Archived

This topic is now archived and is closed to further replies.

Yanroy

IP address as string

Recommended Posts

I'm having a very odd little problem where when I establish a connection and use inet_ntoa() to get the remote comp's IP address, it returns "0.0.0.0" no matter who connects... I'm assuming my RemoteAddress structure is being set up correctly because I have accept()'ed the connection on using it. Data flows perfectly across the connection, so there's nothing wrong there... I wonder if it has something to do with Unicode? I'd love any insights you could provide me. Thanks.
//sockaddr_in RemoteAddress; is defined earlier and used to accept() the incoming connection.


char IP[20];
WCHAR RemoteIP[20];

strcpy(IP, inet_ntoa(RemoteAddress.sin_addr));
MultiByteToWideChar(CP_ACP, NULL, IP, -1, RemoteIP, 19);
--------------------

You are not a real programmer until you end all your sentences with semicolons; (c) 2000 ROAD Programming
You are unique. Just like everybody else.
"Mechanical engineers design weapons; civil engineers design targets."
"Sensitivity is adjustable, so you can set it to detect elephants and other small creatures." -- Product Description for a vibration sensor

Yanroy@usa.com [edited by - Yanroy on July 2, 2003 11:33:32 AM] [edited by - Yanroy on July 2, 2003 11:34:13 AM]

Share this post


Link to post
Share on other sites
Well, 0.0.0.0 is what would be correctly returned if the sockaddr structure was never initialised by accept(). Jump in the debugger and check if RemoteAddress or the char string IP has valid values.

[edited by - jermz on July 2, 2003 12:01:51 PM]

Share this post


Link to post
Share on other sites
Well, you certainly seem to have figured it out! It doesn''t help me at all, but at least now I know what''s wrong... accept() isn''t filling in any of the data in the structure. Now why would that be?

--------------------


You are not a real programmer until you end all your sentences with semicolons; (c) 2000 ROAD Programming

You are unique. Just like everybody else.

"Mechanical engineers design weapons; civil engineers design targets."
"Sensitivity is adjustable, so you can set it to detect elephants and other small creatures." -- Product Description for a vibration sensor

Yanroy@usa.com

Share this post


Link to post
Share on other sites
I was simply suggesting you try to isolate exactly where the problem occurred using the tools available. Sheesh.

EDIT: Sorry man, didn't know if you were being sincere or the snappy "thanks for nothing jackass" response that often appears in these forums.

As for why accept may not fill in the address; Perhaps a bad length supplied to the accept function or maybe the address type of the socket was incorrectly specified when the socket was created.

[edited by - jermz on July 2, 2003 12:44:51 PM]

Share this post


Link to post
Share on other sites
I figured it out. And I was sincere, jermz. Even though I figured it out before I came back and read that suggestion of yours, you were right... it was because I was passing NULL to the accept function. Stupid me...

But now I''ve got another problem, for which I think I''ll start a new thread. Thanks again.

--------------------


You are not a real programmer until you end all your sentences with semicolons; (c) 2000 ROAD Programming

You are unique. Just like everybody else.

"Mechanical engineers design weapons; civil engineers design targets."
"Sensitivity is adjustable, so you can set it to detect elephants and other small creatures." -- Product Description for a vibration sensor

Yanroy@usa.com

Share this post


Link to post
Share on other sites