려리군 2009. 5. 25. 00:06

참고주소 : http://www.cs.cmu.edu/afs/cs/academic/class/15441-f01/www/assignments/P2/htmlsim_split/node18.html


8.1 The IP address INADDR_ANY

8.1 IP 주소 INADDR_ANY


When you wrote your simple FTP server in project 1, you probably bound your listening socket to the special IP address INADDR_ANY. 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 INADDR_ANY are more complex and involved.

당신이 프로젝트 1에서 간단한 FTP서버를 작성했을 때 특별한 IP주소 INADDR_ANY로 리슨 소켓을 바인드 했을 것이다. 이는 다양한 네트워크 인퍼테이스를 사용하는 기계를 대비해서 혹은 어떤 종류의 인터페이스로 정해진 패킷을 받도록 하기 위해 당신의 프로그램이 실행하고 있는 기계의 주소를 알 필요 없이 일할 수 있도록 한다. 실제로 INADDR_ANY의 의미는 더 복잡하다.


In the simulator, INADDR_ANY has the following semantics: When receiving, a socket bound to this 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 ``owns'' that port/interface.

시뮬레이터에서 INADDR_ANY는 다음과 같은 의미를 갖는다. 수신시 이 주소로 바인드된 소켓은 모든 인터페이스로부터 패킷을 받는다. 예를 들어 호스트 컴퓨터가 0,1,2로 된 인터페이스를 갖는다고 하자. 이 호스트의 UDP 소켓은 udp 8000번 포트이며 INADDR_ANY를 사용하여 바인드 되었다면 그 소켓은 인터페이스 0, 1, 2에 도착한 8000번 포트에 대한 모든 패킷을 받을 것이다. 만약 두번재 소켓이 인터페이스 1의 8000번 포트에 바인드하려고 시도한다면 그 바인드는 첫 번째 소켓이 포트/인퍼페이스를 이미 '소유'했기 때문에 실패할 것이다.


When sending, a socket bound with INADDR_ANY binds to the default IP address, which is that of the lowest-numbered interface.

송신시, INADDR_ANY와 바인드한 소켓은 가장 낮은 숫자의 인터페이스를 가진 디폴트 IP주소로 바인드한다.