Question
please helpbconvert to pseudocode. Thanks #include #include pcap.h #include stdio.h #include #include #include //File input and output; #pragma comment(lib,ws2_32.lib) #pragma comment(lib,wpcap.lib) using namespace std; struct
please helpbconvert to pseudocode. Thanks #include
void tcp_protocol_packet_callback(u_char *argument,const struct pcap_pkthdr* packet_header,const u_char* packet_content){ struct tcp_header *tcp_protocol;/*tcp protocol variable*/
u_char flags;
int header_length;
u_short source_port;
u_short destination_port;
u_short windows;
u_short urgent_pointer;
u_int sequence;
u_int acknowledgement;
u_int16_t checksum;
tcp_protocol=(struct tcp_header *) (packet_content+14+20);
source_port =ntohs(tcp_protocol->tcp_source_port);
destination_port =ntohs(tcp_protocol->tcp_destination_port);
header_length =tcp_protocol->tcp_offset *4;
sequence =ntohl(tcp_protocol->tcp_acknowledgement);
acknowledgement =ntohl(tcp_protocol->tcp_ack);
windows = ntohs(tcp_protocol->tcp_windows);
urgent_pointer = ntohs(tcp_protocol->tcp_urgent_pointer);
flags = tcp_protocol->tcp_flags;
checksum =ntohs (tcp_protocol->tcp_checksum);
printf(" ========== Transport layer (TCP protocol) ========== ");
printf("source port:\t %d ",source_port);
printf("Destination Port:\t %d ",destination_port);
int min = (destination_port cout<<"The application layer protocol is:/t"; switch (min) { case 80:printf("http Hypertext Transfer Protocol (HTTP) for World Wide Web (WWW) service"); break; case 21: printf("ftp file transfer protocol (FTP)"); break; case 23:printf("telnet Telnet service"); break; case 25:printf("smtp Simple Mail Transfer Protocol (SMTP)"); break; case 110:printf("pop3 Post Office Protocol Version 3"); break; case 443:printf("https Secure Hypertext Transfer Protocol (HTTP)"); break; default :printf("[Other types] "); break; } cout< printf(" "); printf("Window size:\t%d/n",windows); printf("Checksum:\t%d ",checksum); printf("urgent pointer field:\t%d ",urgent_pointer); } void ip_protocol_packet_callback(u_char *argument,const struct pcap_pkthdr* packet_header,const u_char* packet_content); void ethernet_protocol_packet_callback(u_char *argument,const struct pcap_pkthdr *packet_header,const u_char* packet_content){ u_short ethernet_type; struct ethernet_header *ethernet_protocol; u_char *mac_string; static int packet_number=1; printf(" *** ****** ******* ********* ********* ******* **** ** *** "); printf("\t!!!!!# The [%d] IP packet is captured #!!!!! ",packet_number); printf(" ========== Link layer (Ethernet protocol) ========== "); ethernet_protocol =(struct ethernet_header *) packet_content; printf("Ethernet type is:\t"); ethernet_type=ntohs(ethernet_protocol->ether_type); printf("%04x ",ethernet_type); switch(ethernet_type){ case 0x0800: printf("The network layer is:/tIPv4 protocol ");break; case 0x0806: printf("The network layer is:/tARP protocol ");break; case 0x8035: printf("The network layer is:/tRARP protocol ");break; default: break; } printf("Mac source address:\t"); mac_string=ethernet_protocol->ether_shost; printf("%02x:%02x:%02x:%02x:%02x:%02x: ",*mac_string,*(mac_string+1),*(mac_string+2),*(mac_string+3),* (mac_string+4),*(mac_string+5)); printf("Mac destination address:\t"); mac_string=ethernet_protocol->ether_dhost; printf("%02x:%02x:%02x:%02x:%02x:%02x: ",*mac_string,*(mac_string+1),*(mac_string+2),*(mac_string+3),* (mac_string+4),*(mac_string+5)); switch (ethernet_type){ case 0x0800: ip_protocol_packet_callback(argument,packet_header,packet_content); break; default :break; } packet_number++; } int main(int argc, const char * argv[]) { cout<<"========== Parse IP data packet ========== "; pcap_if_t *alldevs; pcap_if_t *d; int inum=0; int i=0; pcap_t *adhandle; char errbuf[PCAP_ERRBUF_SIZE]; if (pcap_findalldevs(&alldevs,errbuf) == -1){ fprintf(stderr,"Error in pcap_findalldevs: %s ", errbuf); exit(1); } for(d=alldevs; d; d=d->next){ printf("%d. %s", ++i, d->name); if (d->description) printf(" (%s) ", d->description); else printf(" (No description available) "); } if(i==0){ printf(" No interface found! Make sure LibPcap is installed. "); return -1; } printf(" [Enter the number of the network card to be opened (1-%d)]:\t",i); scanf("%d", &inum);//Enter the number of the network card you want to open if(inum <1 || inum> i){ printf(" Network card number is out of range. "); pcap_freealldevs(alldevs); return -1; } for(d=alldevs, i=0; i< inum-1 ;d=d->next, i++); if ((adhandle = pcap_open_live(d->name,65536,1,1000)) == NULL){ fprintf(stderr," Unable to open the adapter.\t %s is not supported by LibPcap "); pcap_freealldevs(alldevs); return -1; } printf(" Monitor%s... ", d->description); pcap_freealldevs(alldevs); int cnt = -1; cout<<" [Number of data packets to be captured]:\t\t"; cin>>cnt; pcap_loop(adhandle,cnt, ethernet_protocol_packet_callback, NULL); cout<<" \t!!!!!# End of parsing IP packet #!!!!! "; return 0;
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started