Re: Q: Extract hardware address from received datagram?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Sun, 14 Aug 2005, [iso-8859-1] Albrecht Dreß wrote:

is there any possibility to read the hardware address (MAC) of the remote machine from received PF_INET/SOCK_DGRAM packets?

Not that I know of. Hardware link addresses is generally unknown to the IP layer of the kernel, in large due to the simple fact that not all IP packets have link addresses and in addition there exists several forms of link addresses (Ethernet is not the only means of communication in this world).

I want to write an application which opens a datagram socket, binds it to a specific port and receives broadcast messages. The sending machine is not necessarily in the same net segment. It is of course easy to get the remote ip address, but I also need the in the information in the packet header, in particular the 6-byte hardware (MAC) address of the sending machine.

You could use a PF_PACKET socket to receive any Ethernet frames received on the selected interface. You will need to decode the frame yourself to see if it is a UDP packet and addressed to your port.

Another alternative is to use the QUEUE target of iptables and write the receiving part of your application as a QUEUE handler getting the packets this way.

But as already noted in this thread, you can only receive packets which are sent on the wire connected to you. Broadcasts from stations in other segments is unlikely to appear there as routers do not by definition forward broadcasts, and also by definition never forwards the link layer addressing.

Regards
Henrik
-
: send the line "unsubscribe linux-net" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Index of Archives]     [Netdev]     [Ethernet Bridging]     [Linux 802.1Q VLAN]     [Linux Wireless]     [Kernel Newbies]     [Security]     [Linux for Hams]     [Netfilter]     [Git]     [Bugtraq]     [Yosemite News and Information]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux PCI]     [Linux Admin]     [Samba]

  Powered by Linux