0

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?

Edited by timetraveller1992

2
Contributors
2
Replies
5
Views
5 Years
Discussion Span
Last Post by timetraveller1992
0

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.

0

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

Edited by timetraveller1992

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.