This is about the Basics of INADDR_ANY. When we bind to the server by placing the value of sin_addr.s_addr as INADDR_ANY, Does it binds to all the IP addresses( If that system is multi homed one)
with the specified port?.
i.e if the system is having IP1 , IP2 and IP3 addresses and when we bind as specified above, does the further Listen call listnes to all the IP Adressees IP1 , IP2 and IP3 with the specified port.
Im not sure clearly what your question is, but i will give a try.
INADDR_ANY has the following semantics, When receiving, a socket bound to the address receives packets from all interfaces. For example, suppose that a host has interfaces 0, 1 and 2. If a UDP socket on this host is bound using INADDR_ANY and udp port 8000, then the socket will receive all packets for port 8000 that arrive on interfaces 0, 1, or 2. If a second socket attempts to Bind to port 8000 on interface 1, the Bind will fail since the first socket already "owned'' that port/interface. When sending, a socket bound with INADDR_ANY binds to the default IP address, which is that of the lowest-numbered interface.
Very well killerserv, the only thing I want to add is that when you send packets from a socket that is bound to a socket address structure with sin_addr (sin6_addr) to INADDR_ANY (in6addr_any) then the kernel sets the source address field of the outgoing IP packets according to the outgoing interface. That means that it checks the routing table, finds the apropriate interface and then sets the source ip address field.
Continuation for same....
Suppoose we have configured logical Interface 220.127.116.11 on a server with Primary IP 18.104.22.168.
Now when I am sending a packet from this server, is it possible to make receiver assume that this packet has come from IP 22.214.171.124 and not 126.96.36.199
I think it is possibl using RAW sockets??? but then do we need to modify kernel also...??
Last edited by Ankit_Jain; 08-08-2008 at 10:28 AM..
I seem to have the same problem as in https://www.unix.com/ip-networking/91203-inaddr_any-opposite.html#post302262417
But I can't find a solution.
I have a UDP server socket bound to 0.0.0.0. The server hosts the addresses IP1, IP2 and IP3. I get an incoming request to IP1. I use... (1 Reply)
Hello, is there some way to obtain system's IP adresses to bind socket to every of them separately instead od INADDR_ANY?
If there is some way to get server's IP to which client has connected, for example:
server_app - bind to listen on INADDR_ANY, gets connected client to 188.8.131.52,... (2 Replies)