| 8 | 8 |
deleted file mode 100644 |
| ... | ... |
@@ -1,69 +0,0 @@ |
| 1 |
-/*! |
|
| 2 |
- * @file sniffing.c |
|
| 3 |
- * @author HiSEON (ikseon@nepirity.com) |
|
| 4 |
- * |
|
| 5 |
- * @internal |
|
| 6 |
- * Created: 2018년 03월 20일 |
|
| 7 |
- * Copyright: Copyright (c) 2018, Kang IkSeon |
|
| 8 |
- */ |
|
| 9 |
- |
|
| 10 |
-#include <stdio.h> |
|
| 11 |
-#include <string.h> |
|
| 12 |
- |
|
| 13 |
-#include <netinet/in.h> |
|
| 14 |
-#include <arpa/inet.h> |
|
| 15 |
- |
|
| 16 |
-#include <pcap.h> |
|
| 17 |
- |
|
| 18 |
-#include "src/lib.h" |
|
| 19 |
-#include "src/ethernet.h" |
|
| 20 |
- |
|
| 21 |
-void packet_handler(u_char *param, |
|
| 22 |
- const struct pcap_pkthdr *header, const u_char *pkt_data) {
|
|
| 23 |
- dump_ethernet_header(pkt_data); |
|
| 24 |
-} |
|
| 25 |
- |
|
| 26 |
-int main(int argc, char **argv) {
|
|
| 27 |
- pcap_t *adhandle; |
|
| 28 |
- char errbuf[PCAP_ERRBUF_SIZE]; |
|
| 29 |
- pcap_if_t *alldevs; |
|
| 30 |
- pcap_if_t *d; |
|
| 31 |
- int i = 0; |
|
| 32 |
- int no; |
|
| 33 |
- |
|
| 34 |
- if (pcap_findalldevs(&alldevs, errbuf) < 0) {
|
|
| 35 |
- printf("pcap_findalldevs error\n");
|
|
| 36 |
- return 1; |
|
| 37 |
- } |
|
| 38 |
- |
|
| 39 |
- for (d=alldevs; d; d=d->next) {
|
|
| 40 |
- printf("%d : %s\n", ++i, (d->description)?(d->description):(d->name));
|
|
| 41 |
- } |
|
| 42 |
- |
|
| 43 |
- printf("number : ");
|
|
| 44 |
- scanf("%d", &no);
|
|
| 45 |
- |
|
| 46 |
- if (!(no > 0 && no <= i)) {
|
|
| 47 |
- printf("number error\n");
|
|
| 48 |
- return 1; |
|
| 49 |
- } |
|
| 50 |
- |
|
| 51 |
- for (d=alldevs, i=0; d; d=d->next) {
|
|
| 52 |
- if (no == ++i) break; |
|
| 53 |
- } |
|
| 54 |
- |
|
| 55 |
- if (!(adhandle= pcap_open_live(d->name, 65536, 1, 1000, errbuf))) {
|
|
| 56 |
- printf("pcap_open_live error %s\n", d->name);
|
|
| 57 |
- pcap_freealldevs(alldevs); |
|
| 58 |
- return -1; |
|
| 59 |
- } |
|
| 60 |
- |
|
| 61 |
- pcap_freealldevs(alldevs); |
|
| 62 |
- |
|
| 63 |
- pcap_loop(adhandle, 0, packet_handler, NULL); |
|
| 64 |
- |
|
| 65 |
- pcap_close(adhandle); |
|
| 66 |
- |
|
| 67 |
- return 0; |
|
| 68 |
-} |
|
| 69 |
- |
| 70 | 0 |
new file mode 100644 |
| ... | ... |
@@ -0,0 +1,69 @@ |
| 1 |
+/*! |
|
| 2 |
+ * @file sniffing.c |
|
| 3 |
+ * @author HiSEON (ikseon@nepirity.com) |
|
| 4 |
+ * |
|
| 5 |
+ * @internal |
|
| 6 |
+ * Created: 2018년 03월 20일 |
|
| 7 |
+ * Copyright: Copyright (c) 2018, Kang IkSeon |
|
| 8 |
+ */ |
|
| 9 |
+ |
|
| 10 |
+#include <stdio.h> |
|
| 11 |
+#include <string.h> |
|
| 12 |
+ |
|
| 13 |
+#include <netinet/in.h> |
|
| 14 |
+#include <arpa/inet.h> |
|
| 15 |
+ |
|
| 16 |
+#include <pcap.h> |
|
| 17 |
+ |
|
| 18 |
+#include "src/lib.h" |
|
| 19 |
+#include "src/ethernet.h" |
|
| 20 |
+ |
|
| 21 |
+void packet_handler(u_char *param, |
|
| 22 |
+ const struct pcap_pkthdr *header, const u_char *pkt_data) {
|
|
| 23 |
+ dump_ethernet_header(pkt_data); |
|
| 24 |
+} |
|
| 25 |
+ |
|
| 26 |
+int main(int argc, char **argv) {
|
|
| 27 |
+ pcap_t *adhandle; |
|
| 28 |
+ char errbuf[PCAP_ERRBUF_SIZE]; |
|
| 29 |
+ pcap_if_t *alldevs; |
|
| 30 |
+ pcap_if_t *d; |
|
| 31 |
+ int i = 0; |
|
| 32 |
+ int no; |
|
| 33 |
+ |
|
| 34 |
+ if (pcap_findalldevs(&alldevs, errbuf) < 0) {
|
|
| 35 |
+ printf("pcap_findalldevs error\n");
|
|
| 36 |
+ return 1; |
|
| 37 |
+ } |
|
| 38 |
+ |
|
| 39 |
+ for (d=alldevs; d; d=d->next) {
|
|
| 40 |
+ printf("%d : %s\n", ++i, (d->description)?(d->description):(d->name));
|
|
| 41 |
+ } |
|
| 42 |
+ |
|
| 43 |
+ printf("number : ");
|
|
| 44 |
+ scanf("%d", &no);
|
|
| 45 |
+ |
|
| 46 |
+ if (!(no > 0 && no <= i)) {
|
|
| 47 |
+ printf("number error\n");
|
|
| 48 |
+ return 1; |
|
| 49 |
+ } |
|
| 50 |
+ |
|
| 51 |
+ for (d=alldevs, i=0; d; d=d->next) {
|
|
| 52 |
+ if (no == ++i) break; |
|
| 53 |
+ } |
|
| 54 |
+ |
|
| 55 |
+ if (!(adhandle= pcap_open_live(d->name, 65536, 1, 1000, errbuf))) {
|
|
| 56 |
+ printf("pcap_open_live error %s\n", d->name);
|
|
| 57 |
+ pcap_freealldevs(alldevs); |
|
| 58 |
+ return -1; |
|
| 59 |
+ } |
|
| 60 |
+ |
|
| 61 |
+ pcap_freealldevs(alldevs); |
|
| 62 |
+ |
|
| 63 |
+ pcap_loop(adhandle, 0, packet_handler, NULL); |
|
| 64 |
+ |
|
| 65 |
+ pcap_close(adhandle); |
|
| 66 |
+ |
|
| 67 |
+ return 0; |
|
| 68 |
+} |
|
| 69 |
+ |