A machine has 2 NICs. Which one will be utilized when connecting to a socket?

后端 未结 3 2001
攒了一身酷
攒了一身酷 2021-01-02 19:13

Suppose I create a very simple socket connection, how can one programatically:

  1. Find out what interface (ip address / NIC) is being used.
  2. Force the ot
3条回答
  •  死守一世寂寞
    2021-01-02 19:43

    a. After a connection is established, most socket APIs have a call for something like "getLocalAddress" that will tell you the interface that the OS selected for you.

    b. Similarly, after a socket is created but before a connection is established, most socket APIs have a call to bind the socket to a local address and/or port.

提交回复
热议问题