Windows equivalent of inet_aton

Asked
Active3 hr before
Viewed126 times

8 Answers

equivalentwindows
90%

(If you can change the Linux source, inet_pton will also work there).,Windows supports inet_pton, which has a similar interface to inet_aton (but that works with IPV6 addresses too). Just supply AF_INET as the first parameter, and it will otherwise work like inet_aton.,It's the Windows equivalent rather than the C++ equivalent, but probably you want inet_addr, which I believe predates inet_aton and which Windows supports., Was War of the Worlds the first science fiction to discuss bacteria/viruses?

To run in windows XP, you can try this checking:

#pragma comment(lib, "Ws2_32.lib")

sockaddr_in inaddr;

#ifdef _WIN32_WINNT 0x0501
inaddr.sin_addr.s_addr = inet_addr("10.10.10.10"); //for XP
#else
inet_pton(AF_INET, "10.10.10.10", & inaddr.sin_addr.s_addr); //for Vista or higher
#endif
88%

Windows supports inet_pton, which has a similar interface to inet_aton (but that works with IPV6 addresses too). Just supply AF_INET as the first parameter, and it will otherwise work like inet_aton.,It's the Windows equivalent rather than the C++ equivalent, but probably you want inet_addr, which I believe predates inet_aton and which Windows supports.,That article also lists, in the "see also" section, the full set of verbosely-named functions to handle IPv6 addresses and so on.,(If you can change the Linux source, inet_pton will also work there).

To run in windows XP, you can try this checking:

#pragma comment(lib, "Ws2_32.lib")

sockaddr_in inaddr;

#ifdef _WIN32_WINNT 0x0501
inaddr.sin_addr.s_addr = inet_addr("10.10.10.10"); //for XP
#else
inet_pton(AF_INET, "10.10.10.10", & inaddr.sin_addr.s_addr); //for Vista or higher
#endif
72%

Windows supports inet_pton, which has a similar interface to inet_aton (but that works with IPV6 addresses too). Just supply AF_INET as the first parameter, and it will otherwise work like inet_aton.,It's the Windows equivalent rather than the C++ equivalent, but probably you want inet_addr, which I believe predates inet_aton and which Windows supports.,That article also lists, in the "see also" section, the full set of verbosely-named functions to handle IPv6 addresses and so on.,(If you can change the Linux source, inet_pton will also work there).

To run in windows XP, you can try this checking:

#pragma comment(lib, "Ws2_32.lib")

sockaddr_in inaddr;

#ifdef _WIN32_WINNT 0x0501
inaddr.sin_addr.s_addr = inet_addr("10.10.10.10"); //for XP
#else
inet_pton(AF_INET, "10.10.10.10", & inaddr.sin_addr.s_addr); //for Vista or higher
#endif
65%

The inet_ntoa function converts an (Ipv4) Internet network address into an ASCII string in Internet standard dotted-decimal format.,An in_addr structure that represents an Internet host address.,Windows Phone 8: This function is supported for Windows Phone Store apps on Windows Phone 8 and later.,The WSAAddressToString function can be used to convert a sockaddr structure containing an IPv4 address to a string representation of an IPv4 address in Internet standard dotted-decimal notation. The advantage of the WSAAddressToString function is that it supports both IPv4 and IPv6 addresses. Another advantage of the WSAAddressToString function is that there are both ASCII and Unicode versions of this function.

Syntax

void inet_ntoa(
   [ in ] a
);
75%

It's the Windows equivalent rather than the C++ equivalent, but probably you want inet_addr, which I believe predates inet_aton and which Windows supports.,Windows supports inet_pton, which has a similar interface to inet_aton (but that works with IPV6 addresses too). Just supply AF_INET as the first parameter, and it will otherwise work like inet_aton.,That article also lists, in the "see also" section, the full set of verbosely-named functions to handle IPv6 addresses and so on.,(If you can change the Linux source, inet_pton will also work there).

It's the Windows equivalent rather than the C++ equivalent, but probably you want inet_addr, which I believe predates inet_aton and which Windows supports.

inet_addr

It's the Windows equivalent rather than the C++ equivalent, but probably you want inet_addr, which I believe predates inet_aton and which Windows supports.

inet_aton
load more v
40%

Introduction to .NET Directory Services Programming,These miscellaneous conversion functions provide the ability to convert IP address from string form (dotted-notation) to binary network format (and vice versa). All of these functions are prefixed with inet, which refers to the fact that they operate on Internet addresses (IPv4).

These miscellaneous conversion functions provide the ability to convert IP address from string form (dotted-notation) to binary network format (and vice versa). All of these functions are prefixed with inet, which refers to the fact that they operate on Internet addresses (IPv4).

#include <netinet /in.h> #include <arpa /inet.h> unsigned long inet_addr( const char *addr ); char *inet_ntoa( struct in_addr in ); int inet_aton( const char *addr, struct in_addr *inp );
load more v
22%

Convert IP addresses from a dots-and-number string to a struct in_addr and back,The function inet_aton() is the opposite, converting from a dots-and-numbers string into a in_addr_t (which is the type of the field s_addr in your struct in_addr.),inet_ntoa() returns the dots-and-numbers string in a static buffer that is overwritten with each call to the function.,The function inet_ntoa() converts a network address in a struct in_addr to a dots-and-numbers format string. The "n" in "ntoa" stands for network, and the "a" stands for ASCII for historical reasons (so it's "Network To ASCII"--the "toa" suffix has an analogous friend in the C library called atoi() which converts an ASCII string to an integer.)

struct sockaddr_in antelope;
char * some_addr;

inet_aton("10.0.0.1", & antelope.sin_addr); // store IP in antelope

some_addr = inet_ntoa(antelope.sin_addr); // return the IP
printf("%s\n", some_addr); // prints "10.0.0.1"

// and this call is the same as the inet_aton() call, above:
antelope.sin_addr.s_addr = inet_addr("10.0.0.1");
60%

if != inet_aton() then ?,5 ways you can learn to program faster ,Creating a game, from start to finish ,How to create a shared library on Linux with GCC - December 30, 2011

int inet_aton(char * addr, struct in_addr * dest) {
   int a[4];
   if (sscanf(addr, "%d.%d.%d.%d", & a[0], & a[1], & a[2], & a[3]) != 4)
      return 0;
   dest - > s_addr = a[3] | a[2] << 8 | a[1] << 16 | a[0] << 24;
   return 1;
}

Other "equivalent-windows" queries related to "Windows equivalent of inet_aton"