Win. Pcap] 패킷에서 IP, Ethernet 정보 출력#include. IPTOSBUFFERS 1.
LINE_LEN 1. 6#define INPUT#define OUTPUTtypedef struct _Packet{const u_char* NProtocol; // Next Protocol void (*Layer. INPUT void*); void (*Layer. INPUT void*); void (*Layer. INPUT void*); }Packet; void Layer. IP(INPUT void*); void Layer. ARP(INPUT void*); void Layer. RARP(INPUT void*); void Layer.
PUP(INPUT void*); void Layer. Ether(INPUT void*); void Print. Hexa. NAscii(const unsigned char *buffer, int size); char *iptos(u_long in); void ifprint(pcap_if_t *d); int main(int argc, char **argv){ const u_char* uc. Data; pcap_if_t *alldevs, *d; pcap_t *fp; u_int inum, i=0; char errbuf[PCAP_ERRBUF_SIZE]; int res; struct pcap_pkthdr *st.
PInfo; Packet st. Data; int i. Data. Link; memset(& st. Data, 0, sizeof(st. Data)); if(argc < 3){printf("\n.
Winpcap developer's packs 인 WpdPack를 다운 받으면 그 안에 샘플들이 많이 있어서. (No description available. (i==0) { printf('\nNo interfaces found! Make sure WinPcap is installed.\n '). . (No description available) \n '); }. printf(' \n No interfaces found! Make sure WinPcap is installed. \n '); return - 1; }. // winpcap라이브러리가 무한루프. . the application can't run due to no interface detected. Make sure winpcap is installed. Modem isnt listed on interface. No Interfaces found on Mac OS X. . (No description available). // printf('\nNo interfaces found! Make sure WinPcap is installed.\n'); // return; // } // // pcap_freealldevs(alldevs); // // //}. ('\nNo interfaces found! Make sure WinPcap is installed.
No adapter selected: printing the device list: \n"); /* The user didn't provide a packet source: Retrieve the local device list */if(pcap_findalldevs(& alldevs, errbuf) == - 1){fprintf(stderr,"Error in pcap_findalldevs_ex: %s\n", errbuf); exit(1); }/* Print the list */for(d=alldevs; d; d=d- > next){printf("%d. No description available)\n"); }if (i==0){printf("No interfaces found! Make sure Win. Pcap is installed.\n"); return - 1; }printf("Enter the interface number (1- %d): ",i); scanf("%d", & inum); if (inum < 1 || inum > i){printf("\n.
Interface number out of range.\n"); /* Free the device list */pcap_freealldevs(alldevs); return - 1; }/* Jump to the selected adapter */ for (d=alldevs, i=0; i< inum- 1 ; d=d- > next, i++); /* Open the adapter */if ((fp = pcap_open_live(d- > name, // name of the device. MACs. 1, // promiscuous mode (nonzero means promiscuous) 1. NULL){fprintf(stderr,"\n. Error opening adapter\n"); return - 1; }}else {/* Do not check for the switch type ('- s') */if ((fp = pcap_open_live(argv[2], // name of the device.
. No Interfaces Found! Please (1)make sure WinPcap is installed. make sure WinPcap is installed. How do I 'make sure login vista OS in administrator'?
MACs. 1, // promiscuous mode (nonzero means promiscuous) 1. NULL){fprintf(stderr,"\n. Error opening adapter\n"); return - 1; }} i. Data. Link = pcap_datalink(fp); if(DLT_EN1. MB == i. Data. Link){printf("[Ethernet 1. Mb]\n"); st. Data. Layer. 2 = Layer.
No Interfaces Found Make Sure Winpcap Is Installed In
Ether; // Regist Layer 2 Processor }else{printf("Not Ethernet Type..\n"); return 0; }do {res = pcap_next_ex(fp, & st. PInfo, & uc. Data); if(st. PInfo- > caplen > 1. Cap Length : [%d]\n", st. PInfo- > caplen); printf("Length : [%d]\n", st. PInfo- > len); printf("\n"); }if(3. PInfo- > caplen) continue; Print.
Hexa. NAscii(uc. Data,st. PInfo- > caplen); st. Data. NProtocol = uc. Data; st. Data. Layer. Data); } while(st. PInfo- > caplen < 3. Data. Layer. 3){st.
Data. Layer. 3(& st. Data); }if(res == - 1){printf("Error reading the packets: %s\n", pcap_geterr(fp)); return - 1; }pcap_close(fp); return 0; }void Layer. IP(INPUT void *v. P) // v. P = Packet struct Start Address{struct ip_header* ih. P = (struct ip_header*)(((Packet *)v. P)- > NProtocol); ////Win. Pcappcap_if_t *alldevs; pcap_if_t *d; char errbuf[PCAP_ERRBUF_SIZE+1]; printf("\n""============================================\n"); printf("============ IP Information ============\n"); printf("============================================\n"); printf("== IP version : IPv%d ==\n", ih.
P- > ip_v); // IP 버젼printf("== Header Length : %dbyte ==\n" , ih. P- > ip_hl*4); // 헤더 길이printf("== Type of service: %3d ==\n" , ih. P- > ip_tos); printf("== Total Length : %5d ==\n" , ih. P- > ip_len); printf("== Identification : %5d ==\n" , ntohs(ih. P- > ip_id)); //식별자printf("== Time ot live : %3d ==\n", ih. P- > ip_ttl); //수명printf("== Protocol : %3d ==\n", ih.
P- > ip_p); //프로토콜printf("== Chceksum : %5d ==\n", ih. P- > ip_sum); //헤더 체크섬printf("== Souce - > Destination ==\n"); printf("== %1.
P- > ip_src)); printf("- > %1. P- > ip_dst)); switch(ntohs(ih. P- > ip_off)){case IP_RF: // 0x. Fragment offset field ==\n"); //플래그break; case IP_DF: // 0x. Reserved fragment flag ==\n"); //플래그break; case IP_MF: // 0x. More fragments flag ==\n"); //플래그break; case IP_OFFMASK: // 0x.
Mask for fragmenting bitsi ==\n"); //플래그break; }printf("============================================\n"); /////Win. Pcap/* Retrieve the interfaces list */ if (pcap_findalldevs(& alldevs, errbuf) == - 1){fprintf(stderr,"Error in pcap_findalldevs: %s\n",errbuf); exit(1); }/* Scan the list printing every entry */for(d=alldevs; d; d=d- > next){ifprint(d); }}void Layer. ARP(INPUT void *v.
P) // v. P = Packet struct Start Address{ }void Layer. RARP(INPUT void *v. P) // v. P = Packet struct Start Address{ }void Layer. PUP(INPUT void *v.
P) // v. P = Packet struct Start Address{ }void Layer. Ether(INPUT void *v. P) //Ethernet 프레임 출력//v. P : Packet Struct Start Address//Return Value : Next Protocol Address{struct ether_header* eh.
P= (struct ether_header*)(((Packet *)v. P)- > NProtocol); ((Packet*)v. P)- > NProtocol= (const u_char*)(eh. P + 1); // Next Protocol Addressprintf("\n""============================================\n"); printf("============Ethernet Information============\n"); printf("============================================\n"); printf("== Souce - > Destination ==\n"); printf("== %0. X: %0. 2X: %0. 2X: %0. X: %0. 2X: %0. 2X ""- > %0. X: %0. 2X: %0. 2X: %0.
X: %0. 2X: %0. 2X ==\n",eh. P- > ether_shost[0], // Souce addresseh. P- > ether_shost[1],eh. P- > ether_shost[2],eh.
P- > ether_shost[3],eh. P- > ether_shost[4],eh. P- > ether_shost[5],eh. P- > ether_dhost[0], //Destination address eh.
P- > ether_dhost[1],eh. P- > ether_dhost[2],eh. P- > ether_dhost[3],eh.
P- > ether_dhost[4],eh. P- > ether_dhost[5]); printf("== Next Protocol : "); switch(ntohs(eh. P- > ether_type)){case ETHERTYPE_IP: printf(" [IP Protocol] ==\n"); ((Packet *)v.
P)- > Layer. 3 = Layer. IP; break; case ETHERTYPE_ARP: printf(" [ARP Protocol] ==\n"); ((Packet *)v. P)- > Layer. 3 = Layer. ARP; break; case ETHERTYPE_REVARP: printf(" [RARP Protocol] ==\n"); ((Packet *)v. P)- > Layer. 3 = Layer. RARP; break; case ETHERTYPE_PUP: printf(" [PUP Protocol] ==\n"); ((Packet *)v. P)- > Layer. 3 = Layer.
PUP; break; default: printf("[Not Support Protocol] ==\n"); break; }printf("============================================\n"); }void Print. Hexa. NAscii(const unsigned char *buffer, int size) //Hexa. Viewer{int loop_temp = 0; int counter = 0; printf("Address 0. A 0. B 0. C 0. D "); printf("0. E 0. F 0. 12. 34. ABCDEF\n"); counter = 0; while(counter < size){printf("0x%0. X ", counter); loop_temp = 0; while(loop_temp < 1.
X ", *buffer); ++buffer; ++loop_temp; }buffer = buffer - 1. IP - > String{static char output[IPTOSBUFFERS][3*4+3+1]; static short which; u_char *p; p = (u_char *)& in; which = (which + 1 == IPTOSBUFFERS ?
Name */printf("%s\n",d- > name); /* Description */if (d- > description)printf("\t. Description: %s\n",d- > description); /* Loopback Address*/ printf("\t.
Loopback: %s\n",(d- > flags & PCAP_IF_LOOPBACK)?"yes": "no"); /* IP addresses */for(a=d- > addresses; a; a=a- > next) {printf("\t. Address Family: #%d\n",a- > addr- > sa_family); switch(a- > addr- > sa_family){case AF_INET: printf("\t. Address Family Name: AF_INET\n"); if (a- > addr)printf("\t.
Address: %s\n",iptos(((struct sockaddr_in *)a- > addr)- > sin_addr. Netmask: %s\n",iptos(((struct sockaddr_in *)a- > netmask)- > sin_addr. Broadcast Address: %s\n",iptos(((struct sockaddr_in *)a- > broadaddr)- > sin_addr. Destination Address: %s\n",iptos(((struct sockaddr_in *)a- > dstaddr)- > sin_addr. Address Family Name: Unknown\n"); break; }}printf("\n"); }#include. ETH_ALEN 6. #define ETHERTYPE_PUP 0x.
Xerox PUP */. #define ETHERTYPE_IP 0x. IP */. #define ETHERTYPE_ARP 0x. Address resolution */. ETHERTYPE_REVARP 0x. Reverse ARP */. #define IPTOS_TOS_MASK 0x. E. #define IPTOS_TOS(tos) ((tos)& IPTOS_TOS_MASK). IPTOS_LOWDELAY 0x.
IPTOS_THROUGHPUT 0x. IPTOS_RELIABILITY 0x.
IPTOS_LOWCOST 0x. ETH_ALEN]; unsigned char ether_shost[ETH_ALEN]; unsigned short ether_type; }; #pragma pack(1)struct ip_header{ unsigned char ip_hl: 4; // 헤더 길이unsigned char ip_v: 4; // 버전u_char ip_tos; // 서비스 타입u_short ip_len; // 전체길이 u_short ip_id; // 식별자#define IP_RF 0x. IP_DF 0x. 40. 00 /* dont fragment flag */#define IP_MF 0x.
IP_OFFMASK 0x. 1fff u_short ip_off; // 플래그, 오프셋 필드u_int. TTL(Time To Live)u_int. IP주소 struct in_addr ip_dst; // 도착지 IP주소}; #pragma pack() //////by Busan.