tags:

views:

438

answers:

2

I'm converting some code written for a linux system to a windows system. I'm using C++ for my windows system and wanted to know the equivalent of the function inet_aton.

+3  A: 

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.

http://msdn.microsoft.com/en-us/library/ms738563.aspx

That article also lists, in the "see also" section, the full set of verbosely-named functions to handle IPv6 addresses and so on.

Steve Jessop
Once I use inet_addr and set the S_addr member of the in_addr struct with the return value, what are the other two union members of the struct in_addr? I'm not quite sure what these (S_un_b and S_un_w) need to be set to.
SS
I assuming I can just use the sockaddr struct type as opposed to the sockaddr_in type and therefore will not need to worry about S_un_b and S_un_w....although I would still like to know what they are used for. Thanks.
SS
Also I don't know why I overlooked the fact that it is a union. I guess no further explanations are needed.
SS
The other members of the union are for if you want to manipulate the address somehow, so that you can look at it byte by byte. On Windows this makes sense because Windows is always little-endian. You rarely need to do that, though: the most common manipulation I guess would be to apply a netmask, and you don't need byte access for that.
Steve Jessop
+1  A: 

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.

(If you can change the Linux source, inet_pton will also work there).

caf
But it is only from Vista and above. on Windows XP it will fail to load.
Vi