{"id":94,"date":"2017-06-23T11:39:34","date_gmt":"2017-06-23T03:39:34","guid":{"rendered":"http:\/\/49.232.131.197\/?p=94"},"modified":"2017-06-25T00:22:18","modified_gmt":"2017-06-24T16:22:18","slug":"inaddr_any","status":"publish","type":"post","link":"http:\/\/www.sourcecool.com\/index.php\/2017\/06\/23\/inaddr_any\/","title":{"rendered":"INADDR_ANY\u5230\u5e95\u662f\u4ec0\u4e48\u610f\u601d"},"content":{"rendered":"<p>INADDR_ANY\uff0c\u662f\u4e2a\u7279\u6b8aIP\u5730\u5740\u00a0\uff0c\u8868\u793a\u4efb\u52a1\u7684IP\u5730\u5740\uff0c\u4f5c\u4e3a\u670d\u52a1\u5668\u7aef\u7684\u65f6\u5019\u7ecf\u5e38\u8981\u7528\u5230\u3002\u5bf9\u4e8e\u5b83\u7684\u89e3\u91ca\uff0c\u6458\u7528\u4e0b\u9762\u4e00\u6bb5\u82f1\u6587\uff08\u6765\u81ea\u4e8e\uff1a<a title=\"http:\/\/www.cs.cmu.edu\/~srini\/15-441\/F01.full\/www\/assignments\/P2\/htmlsim_split\/node18.html\" href=\"http:\/\/www.cs.cmu.edu\/~srini\/15-441\/F01.full\/www\/assignments\/P2\/htmlsim_split\/node18.html\" target=\"_blank\" rel=\"noopener noreferrer\">http:\/\/www.cs.cmu.edu\/~srini\/15-441\/F01.full\/www\/assignments\/P2\/htmlsim_split\/node18.html<\/a>\uff09\uff1a<\/p>\n<p>When you wrote your simple FTP server in project 1, you probably bound your listening socket to the special IP address\u00a0<tt>INADDR_ANY<\/tt>. This allowed your program to work without knowing the IP address of the machine it was running on, or, in the case of a machine with multiple network interfaces, it allowed your server to receive packets destined to any of the interfaces. In reality, the semantics of\u00a0<tt>INADDR_ANY<\/tt>\u00a0are more complex and involved.<\/p>\n<p>In the simulator,\u00a0<tt>INADDR_ANY<\/tt>\u00a0has the following semantics: When receiving, a socket bound to this address receives packets from\u00a0<i>all<\/i>\u00a0interfaces. For example, suppose that a host has interfaces 0, 1 and 2. If a UDP socket on this host is bound using\u00a0<tt>INADDR_ANY<\/tt>\u00a0and 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 \u201cowns\u201d that port\/interface.<\/p>\n<p>When sending, a socket bound with\u00a0<tt>INADDR_ANY<\/tt>\u00a0binds to the default IP address, which is that of the lowest-numbered interface.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>INADDR_ANY\uff0c\u662f\u4e2a\u7279\u6b8a&hellip;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[7,9],"tags":[],"_links":{"self":[{"href":"http:\/\/www.sourcecool.com\/index.php\/wp-json\/wp\/v2\/posts\/94"}],"collection":[{"href":"http:\/\/www.sourcecool.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.sourcecool.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.sourcecool.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.sourcecool.com\/index.php\/wp-json\/wp\/v2\/comments?post=94"}],"version-history":[{"count":1,"href":"http:\/\/www.sourcecool.com\/index.php\/wp-json\/wp\/v2\/posts\/94\/revisions"}],"predecessor-version":[{"id":95,"href":"http:\/\/www.sourcecool.com\/index.php\/wp-json\/wp\/v2\/posts\/94\/revisions\/95"}],"wp:attachment":[{"href":"http:\/\/www.sourcecool.com\/index.php\/wp-json\/wp\/v2\/media?parent=94"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.sourcecool.com\/index.php\/wp-json\/wp\/v2\/categories?post=94"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.sourcecool.com\/index.php\/wp-json\/wp\/v2\/tags?post=94"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}