How can I get the interface name/index associated with a TCP socket?

前端 未结 9 493
伪装坚强ぢ
伪装坚强ぢ 2021-01-12 04:17

I\'m writing a TCP server that needs to know which interface each connection arrived from. I cannot use the address/subnet to deduce which interface was used, since there mi

9条回答
  •  星月不相逢
    2021-01-12 05:22

    Look at the destination address.

    Each interface is normally bound to a unique address. If multiple interfaces are bonded together, it probably doesn't matter which one it used.

    The only exception to this, is when using ipv6 anycast, but even then, you wouldn't normally have multiple interfaces on the same host with the same ip.

提交回复
热议问题