title: How can I get the interface name/index associated with a TCP socket?
body: <p>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 might be interfaces with the same address/subnet values. It's Linux based, and there's no need for the code to be portable.</p>
  
  <p>All I could find were functions to get all interfaces, or a single interface by index. I could not find any way to get the interface associated with an accepted TCP socket.</p>
  
  <p>Any ideas? Something I've missed?</p>
  
  <p>EDIT: To reiterate, IP addresses are not unique in my case. Neither the destination addresses (the server itself) nor the source addresses (the clients).
  Yes, this is a very extreme IP scheme.</p>