SOL9 Sample: IPv4StringToAddress

SOL9 2.0 Samples

1 Screenshot


2 Source code

/*
 * IPv4StringToAddress.cpp 
 * Copyright (c) 2015 Antillia.com TOSHIYUKI ARAI. ALL RIGHTS RESERVED. 
 */


// SOL9
// 2010/10/30
// 2010/12/16 Updated for UNICODE

#include <sol/net/IPv4String.h>
#include <sol/net/IPv4Address.h>
#include <sol/Locale.h>

// Sample program to convert a IPv4String to an address.

void _tmain(int argc, TCHAR** argv)
{
  try {
    // Specify "127.0.0.1" for IPv6 localhost.
    if (argc != 2) {
      _tprintf(_T("Usage: %s IPv6String\n"), argv[0]);
      _tprintf(_T("Specify 127.0.0.1 for IPv4 localhost.\n"));
      return;
    }

    TCHAR* string = _T("127.0.0.1");
    string = argv[1];

    _tprintf(_T("IPv4 IPv4String %s\n"), string);

    IPv4String  v4String;

    TCHAR* delim = NULL;
    IN_ADDR address;
    v4String.toAddress(string, TRUE, &delim, &address);
    _tprintf(_T("Converted to IN_ADDR\n"));    

    TCHAR convstring[64];
    IPv4Address v4Address;

    v4Address.toString(&address, convstring);
      
    _tprintf(_T("Converted to IPv4String %s\n"), convstring);

  } catch (int err) {
    _tprintf(_T("Exception %d\n"), err);  
  }
}

Last modified: 2 May 2016

Copyright (c) 2016 Antillia.com ALL RIGHTS RESERVED.