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

前端 未结 9 548
伪装坚强ぢ
伪装坚强ぢ 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条回答
  •  旧时难觅i
    2021-01-12 05:19

    Obviously not something I've looked into very deeply, let alone tried, this might be one for the "so crazy it just might work" basket...

    If it's really only ever going to be for Linux, you could write a custom netfilter module which tracks the incoming connections and notes which interface they come in on, and writes that information somewhere for your server application to read.

提交回复
热议问题