How does a socket know which network interface controller to use?

前端 未结 4 831
慢半拍i
慢半拍i 2020-12-04 17:40

If a computer has multiple network cards, all of them connected to different networks and functioning properly, when we open a socket, how does the OS determine which NIC to

4条回答
  •  日久生厌
    2020-12-04 18:28

    I'm not really sure which method is the best, but there is an alternative theory to the bind()-before-connect() approach that Shtééf presented. It's to use setsockopt() with SO_BINDTODEVICE . See: http://codingrelic.geekhold.com/2009/10/code-snippet-sobindtodevice.html

提交回复
热议问题