Search code examples
linuxraw-sockets

Can we choose a particular interface when using raw sockets?


I'm building an application in linux that sends data only through a certain interface. Can I do that using raw sockets, maybe using the set socket options function?


Solution

  • When you bind a socket you do it by IP. But hopefully your interfaces have different IP addresses. If so, you can just call getifaddrs first and find the address of the interface you want.