Can bind() socket to remote address?

后端 未结 2 1553
长发绾君心
长发绾君心 2021-01-21 21:44

With the following snapshot of C code, I understand that, the address that bind() call binds to listfd, is the logical address of the local machine wh

2条回答
  •  没有蜡笔的小新
    2021-01-21 21:57

    I agree the Coursera material is probably wrong or at least misleading for introduction level learning about network programming.

    However, I can not suppress a pedantic comment. It is possible (on Linux) to bind to a non-local IP address. Please see option IP_TRANSPARENT at http://man7.org/linux/man-pages/man7/ip.7.html. This probably has very little to do with the issue at hand, though. Also i appreciate the question is tagged bsd.

    More on the point, bind() does not have anything to do with listening. It simply associates the fd with an address. It is the listen() call that enables "listening". It is possible to bind() a socket used for outgoing connections.

提交回复
热议问题