... | ... |
@@ -7,4 +7,35 @@ |
7 | 7 |
* Copyright: Copyright (c) 2018, HiSEON |
8 | 8 |
*/ |
9 | 9 |
|
10 |
+#include <stdio.h> |
|
11 |
+#include <arpa/inet.h> |
|
12 |
+#include <net/ethernet.h> |
|
13 |
+ |
|
10 | 14 |
#include "src/ethernet.h" |
15 |
+ |
|
16 |
+void dump_ethernet_header(const u_char *pkt_data) { |
|
17 |
+ struct ether_header *header = (struct ether_header *)pkt_data; |
|
18 |
+ |
|
19 |
+ const char *name = NULL; |
|
20 |
+ |
|
21 |
+ u_int8_t *dmac = header->ether_dhost; |
|
22 |
+ u_int8_t *smac = header->ether_shost; |
|
23 |
+ u_int16_t type = ntohs(header->ether_type); |
|
24 |
+ |
|
25 |
+ switch (type) { |
|
26 |
+ case ETHERTYPE_IP: |
|
27 |
+ name = "IP"; |
|
28 |
+ break; |
|
29 |
+ case ETHERTYPE_ARP: |
|
30 |
+ name = "ARP"; |
|
31 |
+ break; |
|
32 |
+ default: |
|
33 |
+ name = "Unknwon"; |
|
34 |
+ break; |
|
35 |
+ } |
|
36 |
+ |
|
37 |
+ printf("%02x:%02x:%02x:%02x:%02x:%02x => " \ |
|
38 |
+ "%02x:%02x:%02x:%02x:%02x:%02x (%s) \n", |
|
39 |
+ smac[0], smac[1], smac[2], smac[3], smac[4], smac[5], |
|
40 |
+ dmac[0], dmac[1], dmac[2], dmac[3], dmac[4], dmac[5], name); |
|
41 |
+} |