3

I have a PC (in the successive diagrams pc1) equipped with a network interface that can be directly connected to another PC or to a managed switch.

I want to be able to get the MAC address of the closest device in the network.

Just to be more precise:

Situation #1

+-----+       +----------------+       +---------------+
| pc1 |-------| managed switch |-------| other devices |
+-----+       +----------------+       +---------------+

In this case, I want to get the MAC address of the managed switch.

Situation #2

+-----+       +-----+
| pc1 |-------| pc2 |
+-----+       +-----+

In this case, I want to get the mac address of pc2.

What can I use to retrieve the MAC address of the first network device?

Update

As far as I know, I cannot use ARP, because in PC1's ARP table, I'll see all the MAC addresses related to the IP addresses on the ethernet segment, but I have no way in general to know the IP address of the device at the other end of the cable (this is painful in the case of the switch). This is why I am looking for something like ping at the data link layer with a TTL of 1.

5
  • Questions about end-devices like PCs are explicitly off-topic here. You can try to ask this question on Super User. FYI, a switch is transparent and the PC shouldn't see its MAC address.
    – Ron Maupin
    Commented Mar 24, 2016 at 15:49
  • In fact I am not asking about PCs, I am asking a way in IEEE802.3 to detect the MAC address of the equipment at the other end of the cable. I am looking for an Ethernet frame that I can use to detect/lookup the MAC address. Commented Mar 24, 2016 at 15:56
  • You can get the MAC address from any frame originated at the other device. You can use ARP to discover the MAC address of another device on the same LAN. Somehow, you need to get a frame from the other device.
    – Ron Maupin
    Commented Mar 24, 2016 at 15:59
  • Yes, right, that remebers me that I forgot to write a piece of the question. AFAIK ARP lets me get the MAC address from the IP address of the device, but I have no idea how I can discriminate the IP address of the device at the other end of the cable. (I'm updating the question rignt now to better explain) Commented Mar 24, 2016 at 16:02
  • A LAN is a broadcast domain, and all devices on a LAN are equals. In your switch example, you would never see the MAC address of the switch unless you communicate with the management address of the switch. If the device at the other end of the cable is transparent, like a switch, you normally will not receive any frames from it. You need to see a frame from another device to get its MAC address, but you really have no way to determine it is the device at the other end of the link unless it is a point-to-point link.
    – Ron Maupin
    Commented Mar 24, 2016 at 16:10

2 Answers 2

4

802.3 has no concept of "link partner identity". As such, you cannot reliably determine the MAC of any directly connecting device. However, there are higher level application protocols (CDP, LLDP, etc.) that attempt to address this.

1
  • LLDP seems to be perfect for my goal! Commented Mar 25, 2016 at 16:42
1

Ethernet frames have no concept of hops like you want. You are trying to impose a layer-3 concept on layer-2. Ethernet is not hierarchical the way IP is. Switches transparently switch frames, and the MAC addresses in the frames are the source and destination end-points, not any device in between the two endpoints. Ethernet frames are pretty simple with very few fields (no TTL or equivalent, which is why broadcast storms are so bad on ethernet):

enter image description here

What you are asking for is not really possible. Ethernet at layer-2 is just a group of equal peers (all look like like they are directly connected to all others).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.