Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Re: (OT) Getting the source hardware address of received UDP packets?

by isotope (Deacon)
on Jun 01, 2006 at 16:26 UTC ( [id://553086]=note: print w/replies, xml ) Need Help??


in reply to (OT) Getting the source hardware address of received UDP packets?

IP packets have no concept of MAC address. That's already been removed by the OS by the time you get the packet. There are few ways to get that information at this point:
  • Checking the ARP table would be the easy way, but you don't want to do that.
  • Using libpcap would be the more reliable way, if you don't trust the source IP address, but you don't want to do that.
  • Writing your own ethernet driver in Perl might work, but if you don't want to filter packets with pcap, you're certainly not going to want to write a complete driver.
Now that you've eliminated the reasonable answers, my question is: What are you really trying to accomplish? I suspect there's a much easier way to do what you want.


--isotope

Replies are listed 'Best First'.
Re^2: (OT) Getting the source hardware address of received UDP packets?
by Anonymous Monk on Jun 02, 2006 at 06:12 UTC
    Say a dhcp client without an IP address sends a dhcp request (broadcast).

    While a dhcp request/discover payload usually contains the alleged hardware address of the client, it may still be useful to log the hardware address of the frame if things go wrong.

    But I don't want the program to see all frames. Only just the relevant packets.

    I suppose that's not a good enough reason - so I guess that's why there's no easy way to do that :).

      It is possible to make DHCP requests to a server outside of one's LAN*, but only because DHCP allows you to specify your MAC address inside of your request. The DHCP request looks a bit like "My MAC address is 00:00:00:00:00:00. Please give me an IP address." In other words, the client must explicitly place the MAC address in the DHCP request. There's no IP or UDP (or even TCP) solution to your problem.

      You can do the same as DHCP — have the clients send their MAC address along with their request — with your UDP-based protocol if you're still developing the protocol.

      * — That requires the co-operation of the gateway, but only because the machine doesn't have an IP address yet.

      That really is a good application for Net::Pcap. You dismissed pcap because you didn't want to handle all received frames, but pcap allows you to define a filter so you'd actually be able to select just dhcpc messages if you wanted.


      --isotope

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://553086]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others imbibing at the Monastery: (6)
As of 2024-03-28 08:23 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found