I can post more code if need be... I have a procedure that prints the fields of ethernet frames and ip headers. I have an issue with the src mac addr being printed incorrectly and incompletely. What am I doing wrong? The part in red is the trouble code.
Code:
1#include "sniffer.h"
2
3void print_headers(struct ethhdr * ethhdr, struct ip * iphdr){
4
5 char ipstr_src[INET_ADDRSTRLEN];
6 char ipstr_dst[INET_ADDRSTRLEN];
7 char macstr_dst[ETH_ALEN], macstr_src[ETH_ALEN];
8
9
10 struct ether_addr * ether_addr;
11
12 printf("\n"
13 "[Ethernet Header]\n"
14 "Destination MAC: %s \n"
15 "Source MAC: %s \n"
16 "Protocol: %u \n\t",
17 ether_ntoa_r((struct ether_addr *)&(ethhdr->h_dest), macstr_dst),
18 ether_ntoa_r((struct ether_addr *)&(ethhdr->h_source), macstr_src),
19 ethhdr->h_proto
20 );
21
22 printf(
23 "[IP Header]\n\t"
24 "Header Length: %u\n\t"
25 "Version: %u\n\t"
26 "TOS: %u \n\t"
27 "Len: %u \n\t"
28 "ID: %u \n\t"
29 "Fragment Offset: %u\n\t"
30 "TTL: %u \n\t"
31 "Protocol: %u \n\t"
32 "Checksum: %u \n\t"
33 "Source: %s \n\t"
34 "Destination: %s\n\t",
35 iphdr->ip_hl, iphdr->ip_v,
36 iphdr->ip_tos, iphdr->ip_len, iphdr->ip_id, iphdr->ip_off,
37 iphdr->ip_ttl, iphdr->ip_p, iphdr->ip_sum,
38 inet_ntop(AF_INET, &iphdr->ip_src, ipstr_src, INET_ADDRSTRLEN),
39 inet_ntop(AF_INET, &iphdr->ip_dst, ipstr_dst, INET_ADDRSTRLEN)
40 );
41
42
43}