How does socket bind inaddr_any? (For example, dual-connection multi-network card and multiple IP settings)

Source: Internet
Author: User
 

I also replied to one !!
Inaddr_any indicates the address 0.0.0.0. In fact, this address indicates an uncertain address, "all addresses", or "any address ".

Generally, if you want to create a network server, you need to notify the server operating system at a specific address XXX. xxx. xxx. listen on a port of yyyy on XXX, and send the packet to me. This process is completed by calling the BIND () system. -- That is, your program needs to bind a server address, or use a port on a server address as used. The server operating system can give you the specified address or not.

If your server has multiple NICs,
For some reason, your service (whether listening on a UDP port or a TCP port) may increase or decrease the IP address of your server operating system at any time, it may also be to save the trouble of determining the network port (NIC) on the server-you can tell the operating system when calling BIND: "I need to listen on the yyyy port, so the port sent to the server, no matter which NIC/IP address receives the data, is processed by me." At this time, the server listens on the address 0.0.0.0. For example:

PROTO Recv-Q send-Q local address foreign address (state)
......
Udp4 0 0 *. 7913 *.*
Udp4 0 0 *. 7911 *.*
Tcp4 0 0 *. FTP *. * listen
......
......

These are network listening conditions. The local address is "*. FTP" and "*. 7911", which indicates that the service program is bound to all the network adapters of the server.

Well, you understand what inaddr_any means. So, will my server receive repeated packets if there are n IP addresses? After receiving the packet, will the client reply again?
The answer is: no repeated data packets are received or sent repeatedly.

Why? Right upstairs, every server maintains a route table. The route table determines where data packets should be sent.

Why can't I receive repeated data packets?
A: The client only sends data to the unique IP address on your server.

Why not send data packets repeatedly?
A: The route (PATH) for sending data packets is unique. If the server does not know which address to send data when sending data, the data will be sent to the "Default Gateway.

How do I select the data transmission path?
A: send the message as required by the route table.

If there are duplicate/conflict records in the route table, how can we select the path at this time?
A: route table records are prioritized. Generally, if the route table record of a Windows operating system is repeated, the record to be added later prevails. In some operating systems, such as Linux/FreeBSD, duplicate route table records cannot be added.

 

 

If there are duplicate/conflict records in the route table, how can we select the path at this time?
A: route table records are prioritized. Generally, if the route table record of a Windows operating system is repeated, the record to be added later will prevail. In some operating systems, such as Linux/FreeBSD, repeated route table record cannot be added;

For a dedicated router, there is a routing algorithm. Generally, there are many routes that reach a certain point on the network. The routing algorithm can determine the "best path". The path either has the lowest latency, the lowest communication cost, or the highest bandwidth, it is either the smallest hop point-how to choose it depends on how the router administrator configures it.

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.