Question

I'm trying to write a BOOTP server in c#.

I'm receiving and parsing the BOOTP packet from the client and I need to reply with my server IP address.

The problem is:

  • The computer can have multiple network adapters
  • The client doesn't yet have an IP address

Is there any way to find out what adapter the UDP packet was received on?

Was it helpful?

Solution

There are a few possible ways to do this. Bind a separate socket on each IP on each physical interface, then you'll always know which interface the packet arrived on. You can also try the IP_RECVIF flag together with the recvmsg socket function, although I don't know if that's supported on Windows. Steven's has examples in Section 22.2 and 22.6 of Unix Network Programming. You can use the SIOCGIFCONF flag with ioctl to get a list of interfaces on the machine. There is an example program in UNP section 17.6. If c# doesn't give you access to these functions but their supported on Windows you could write a simple C program to collect and update the interface / IP info and then use mmap to share a memory region between your C# program and the interface enumerator.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top