I'm new to network programming. And I skimmed a few pages of beej programming guide and found some useful info but couldn't clear one doubt. We use bind to associate a sockaddr_in structure with the socket descriptor so that the kernel can send data to the network adapter and thereby communicate right. So I noticed the symbolic name INADDR_ANY. I tried a pre-processing only option in my gcc compiler and found the IP to be hexadecimal value of 127.0.0.1 the loop back IP. I'm just wondering what if I assigned a random IP of my choice to the s_addr pointer in the sockaddr_in structure instead of assigning it to INADDR_ANY. Would that mean i'm spoofing my IP?

When a process wants to receive new incoming packets or connections, it should bind a socket to a local interface address using bind. Only one IP socket may be bound to any given local (address, port) pair. When INADDR_ANY is specified in the bind call, the socket will be bound to all local interfaces. When listen or connect are called on an unbound socket, it is automatically bound to a random free port with the local address set to INADDR_ANY.

erm. I already read the same exact text in the man pages. Not helpful! Anyways thanks for the effort

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.