Have problem printing source mac address in linux [closed]
etherheader
points to the header of ether packet as its name implies开发者_运维知识库:
printf("Source MAC address: "
"%02x:%02x:%02x:%02x:%02x:%02x\n",
etherheader[0],etherheader[1],etherheader[2],
etherheader[3],etherheader[4],etherheader[5]);
struct ether_header {
u_int8_t ether_dhost[6];
u_int8_t ether_shost[6];
u_int16_t ether_type;
}
It turns out the above code always prints:
Source MAC address: 40:40:8d:40:b8:f4
What's wrong?
UPDATE
Destination MAC address: 40:40:8d:40:b8:f4
Source MAC address: 88:43:e1:7c:46:7f
Source host 123.126.50.73
Dest host *.*.27.*
----------
Destination MAC address: 40:40:8d:40:b8:f4
Source MAC address: 88:43:e1:7c:46:7f
Source host 114.62.80.83
Dest host *.*.27.*
Ethernet is a protocol (suite) for Local Area Networks. If your machine is statically connected, point-to-point, to a single router/switch which provides it with internet access, then this is where all your incoming packets originate from (the last hop, for your ingress traffic). This means that regardless what IP on the internet you're trying to establish IP communication with, all packets will traverse the link between your machine and your router/switch (through Ethernet).
If you are connected to a single network element, and neither your nor its network configuration changes, MAC addresses for those two machines (network cards, to be more precise) will remain the same. This behaviour seems to be what you're observing.
If packets originate from outside the broadcast domain (AKA subnet) of the destination then the source MAC address will always be that of the router that provides the gateway into that broadcast domain. Although 40:40:8d doesn't appear to be a valid OUI (see http://standards.ieee.org/develop/regauth/oui/oui.txt) so maybe there is just a programming error.
88:43:e1 is an OUI from Cisco, which lends some weight to the above paragraph being an explanation of why the source MAC address does not change.
精彩评论