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
2010-03-10 21:22:54
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
2010-03-10 22:04:29
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
2010-03-10 22:12:12
Also I don't know why I overlooked the fact that it is a union. I guess no further explanations are needed.
SS
2010-03-10 22:16:33
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
2010-03-10 22:23:33