| 1 | 1 | 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 | - | 
| ... | ... | @@ -16,11 +16,11 @@ | 
| 16 | 16 | #include <pcap.h> | 
| 17 | 17 |  | 
| 18 | 18 | #include "src/lib.h" | 
| 19 | +#include "src/ethernet.h" | |
| 19 | 20 |  | 
| 20 | 21 | void packet_handler(u_char *param, | 
| 21 | 22 |    const struct pcap_pkthdr *header, const u_char *pkt_data) { | 
| 22 | -  printf("caplen : %d\n", header->caplen); | |
| 23 | -  printf("len : %d\n", header->len); | |
| 23 | + dump_ethernet_header(pkt_data); | |
| 24 | 24 | } | 
| 25 | 25 |  | 
| 26 | 26 |  int main(int argc, char **argv) { | 
| 1 | 1 | new file mode 100644 | 
| ... | ... | @@ -0,0 +1,68 @@ | 
| 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 | +void packet_handler(u_char *param, | |
| 19 | +  const struct pcap_pkthdr *header, const u_char *pkt_data) { | |
| 20 | +  printf("caplen : %d\n", header->caplen); | |
| 21 | +  printf("len : %d\n", header->len); | |
| 22 | +} | |
| 23 | + | |
| 24 | +int main(int argc, char **argv) { | |
| 25 | + pcap_t *adhandle; | |
| 26 | + char errbuf[PCAP_ERRBUF_SIZE]; | |
| 27 | + pcap_if_t *alldevs; | |
| 28 | + pcap_if_t *d; | |
| 29 | + struct pcap_addr *a; | |
| 30 | + int i = 0; | |
| 31 | + int no; | |
| 32 | + | |
| 33 | +    if (pcap_findalldevs(&alldevs, errbuf) < 0) { | |
| 34 | +        printf("pcap_findalldevs error\n"); | |
| 35 | + return 1; | |
| 36 | + } | |
| 37 | + | |
| 38 | +    for (d=alldevs; d; d=d->next) { | |
| 39 | +        printf("%d :  %s\n", ++i, (d->description)?(d->description):(d->name)); | |
| 40 | + } | |
| 41 | + | |
| 42 | +    printf("number : "); | |
| 43 | +    scanf("%d", &no); | |
| 44 | + | |
| 45 | +    if (!(no > 0 && no <= i)) { | |
| 46 | +        printf("number error\n"); | |
| 47 | + return 1; | |
| 48 | + } | |
| 49 | + | |
| 50 | +    for (d=alldevs, i=0; d; d=d->next) { | |
| 51 | + if (no == ++i) break; | |
| 52 | + } | |
| 53 | + | |
| 54 | +    if (!(adhandle= pcap_open_live(d->name, 65536, 1, 1000, errbuf))) { | |
| 55 | +        printf("pcap_open_live error %s\n", d->name); | |
| 56 | + pcap_freealldevs(alldevs); | |
| 57 | + return -1; | |
| 58 | + } | |
| 59 | + | |
| 60 | + pcap_freealldevs(alldevs); | |
| 61 | + | |
| 62 | + pcap_loop(adhandle, 0, packet_handler, NULL); | |
| 63 | + | |
| 64 | + pcap_close(adhandle); | |
| 65 | + | |
| 66 | + return 0; | |
| 67 | +} | |
| 68 | + |