in reply to Re^2: Figuring out which network interface a broadcast packet came in on?
in thread Figuring out which network interface a broadcast packet came in on?

I think you need to set rules in your routing table in order to route packets based on incoming/outgoing interfaces (ip is your friend here).

As far as I know, a socket at the application layer can give you only information on ip address/port number and not about interface on which it arrived. You might have to dig into writing your own code at the kernel layer, or use one of the utilities like ip to get the information you want.

Just my 2 cents..

  • Comment on Re^3: Figuring out which network interface a broadcast packet came in on?

Replies are listed 'Best First'.
Re^4: Figuring out which network interface a broadcast packet came in on?
by lyeoh (Acolyte) on Sep 03, 2005 at 04:09 UTC
    Routing tables aren't very useful for DHCP packets, because a significant proportion of DHCP packets don't have unique IP addresses even at a local network level. After all DHCP is typically used by hosts without valid IP addresses to get valid IP addresses.

    getsockopt and setsockopt allow you to get more info about a socket. e.g.

    # Get the original destination of the connection # that was redirected to our socket my $p= getsockopt $client, $SOL_IP, $SO_ORIGINAL_DST; $orig_destaddr=inet_ntoa(substr($p,4,4)); $orig_destport=unpack('n',substr($p,2,2));
    I just don't know how to read or write the ancillary messages once I set the IP_PKTINFO socket option. In C it's stuff like sendmsg, recvmsg or cmsg.

    DHCP doesn't really require high performance - legitimate client machines should not be sending DHCP packets at a high rate, so perl isn't such a bad fit other than this problem I'm having. A perl DHCP server won't be as prone to buffer overflows and will be flexible and more easily extensible.