Advertisement

Socket Address Seems to be Set to 0.0.0.0

Started by July 01, 2004 05:13 PM
6 comments, last by Permafried- 20 years, 7 months ago
Hey, I was finally testing out my network code today and couldn't figure out why I couldn't exchange data between my client and server. When I stepped throught the code and ultimately printed out the ip address (with correct casting of course) I noticed that apparently INADDR_ANY is assigning my ip address to 0.0.0.0. Im creating my socket as a Winsock 2.2 in case that's important. Was hoping someone might have some idea of what was going on because at this point I have come to a dead stop, maybe it's from coding too much today ^_^. Thanks in advance, Permafried-
Quote:
Original post by Permafried-
I noticed that apparently INADDR_ANY is assigning my ip address to 0.0.0.0.
Correct behavior, you ahven't found your problem yet.
Advertisement
INADDR_ANY should be 0.0.0.0;



Or rather, that is perhaps not so unexpected. I do almost all of my server coding on NetBSD, and it interprets 0.0.0.0 as localhost, and "accept from all" when listening.



Windows does not though iirc. It's been quite some time since I've done any server side stuff for win32, and I don't have access to a compiler to test with.
Hey,

Thanks for the reply, I was starting to wonder if this was essentially setting my localhost. If this is the case, will it ALWAYS set to localhost when I create my server, and if so, how do I tell a client to connect to an ip address of localhost...I need some sort of external address such as the IP I am on right now. My desired behaviour is for the server to pickup the address bound to my network adapter not the localhost loopback all the time.

I must be missing something here because I just don't see how this will work. Btw, I'm using UDP but this shouldn't have any bearing on this as far as I can tell.

Thanks,

Permafried-
INADDR_ANY means it'll accept from any ip address. (or bind to all addresses on the current host)

Unless you're using this as the ip address to connect to (for the client) nothing is wrong here.
C-Junkie,

Essentially all the client is going to do is send a connectionless packet from it's socket (which is also setup as INADDR_ANY) to the server at which point the host will simply parse it out and send a packet back saying "Accepted" or "Not" basically.

My question is, do I just send to the server's known external address and port at which point that will be filtered through to my server and accepted by my recvfrom() method, or will I have to change how I create my socket?

Thanks again,

Permafried-
Advertisement
Quote:
Original post by Permafried-
My question is, do I just send to the server's known external address and port at which point that will be filtered through to my server and accepted by my recvfrom() method, or will I have to change how I create my socket?
Well, since my first thought at thiis point is 'duh' I must be misunderstanding oyur qeustion, and now would be a good time to show some simple code.

Client sends UDP to server IP:port, server recieves it, if its bound to that port, on that IP or on INADDR_ANY.
Hey,

I managed to solve my problem, it had nothing to do with the socket creation but in my sending and receiving.

Thanks again for your help,

Permafried-

[Edited by - Permafried- on July 1, 2004 9:48:35 PM]

This topic is closed to new replies.

Advertisement