Browse code

이더넷 프레임 출력 함수 구현

Kang IkSeon authored on22/03/2018 09:02:09
Showing1 changed files
... ...
@@ -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
+}
Browse code

추가 파일 등록

Kang IkSeon authored on22/03/2018 08:44:41
Showing1 changed files
1 1
new file mode 100644
... ...
@@ -0,0 +1,10 @@
1
+/*!
2
+ *  @file    ethernet.c
3
+ *  @author  HiSEON (ikseon@nepirity.com)
4
+ *
5
+ *  @internal
6
+ *       Created:  2018년 03월 22일
7
+ *     Copyright:  Copyright (c) 2018, HiSEON
8
+ */
9
+
10
+#include "src/ethernet.h"