Confusion in bind call in socket programming
Posted
by Tarun
on Stack Overflow
See other posts from Stack Overflow
or by Tarun
Published on 2010-06-10T14:17:19Z
Indexed on
2010/06/10
14:32 UTC
Read the original article
Hit count: 225
i was learning socket programming in unix using c/c++. I am confused with one function call bind(params..). Actually it takes the adreess structure "sockaddr_in" and we can create the structure in the following way
sockaddr_in.*** = somthing..
sockaddr_in..s_addr htonl(INADDR_ANY)
**Passing INADDR_ANY will alow to bind all local addresses**
My question is , why do we need to use "INADDR_ANY" ? In my knowledge every machine can has only one unique IP Address. In this way there is only one address associated with the machien. Thye bind call should directly bind the socket to the single available address.
Please explain what are the different scenarios and why is it so?
© Stack Overflow or respective owner