I want to determine if the IP of the PC running my application is the same as the IP address registered at a dns name server.

For example I have a name myname.no-ip.com which should resolve to my current IP address. I've done quite a bit of reading so I would like to confirm if the following is correct (as I understand it)

First I call gethostbyname which returns a hostent structure containing the resolved IP address in network byte order

Now I call getsockname on a connected socket - I do have one  ;)

Am I correct in understanding I call getsock name with a pointer to an empty sockaddr_in structure which will (after the call) contain my current IP address in the sin_addr member?

Also will this returned IP address be in network byte order so I can compare the two directly or must I convert it?

Or did I get it all wrong  :shock:

Thanks for your help
dicky

Posted on 2005-10-09 13:44:37 by dicky96
Am I correct in understanding I call getsock name with a pointer to an empty sockaddr_in structure which will (after the call) contain my current IP address in the sin_addr member?


int getsockname(
  SOCKET s,
  struct sockaddr* name,
  int* namelen
);

s
Descriptor identifying a socket.
name
Pointer to a SOCKADDR structure that receives the address (name) of the socket.
namelen
Size of the name buffer, in bytes.


'name' is an 'out' parameter, so it's used to return the data. simply, it means that you're correct on this one.
Posted on 2005-10-12 15:53:36 by ti_mo_n
Are you behind a firewall running NAT?  If you are, then the IPs will different because of the NAT.

And if you have a multi-port network card or multiple cards running multiple IP's, that's a little extra work too.

Regards,  P1  8)
Posted on 2005-10-12 16:37:03 by Pone
thanks for the answer's guys  8)

btw - things like int*  - is an int like the same thing as a dw?  That's my best guess.  Is there a list somewhere of these things and what size in bytes they really are?  It's little things like that which kinda cause me a lot of time with win32ams - it's like everyone's documentation just assumes u know these things  :roll:

dicky
Posted on 2005-10-13 16:17:27 by dicky96
int is usually 32-bit, but it can (though VERY rarely) be 16-bit.

"int *" is  a pointer to int. you should handle it in the following way:

sockname sockaddr ?
blah dd ?

call getsockname, mySock, offset sockname, offset blah

it's an 'in/out' parameter, so before calling thins function you should set 'blah' to some proper value. when the function returns, 'blah' will contain (probably) some other value, set by the function itself.
Posted on 2005-10-13 17:25:10 by ti_mo_n