main() { int pack_socket,n; int len,datasize; char src_addr[20],dst_addr[20],*data; struct sockaddr_ll sa; socklen_t sl; struct iphdr *ip_hdr; char buf[2000]; struct in_addr addr; pack_socket = socket(PF_PACKET,SOCK_DGRAM,htons(ETH_P_ALL)); while(1){ sl = sizeof(struct sockaddr_ll); n = recvfrom(pack_socket,buf,2000,0,(struct sockaddr *)&sa,&sl); //check whether the packet is ip or not. if(ntohs(sa.sll_protocol) == 0x0800){ printf(" IP packet received \n"); ip_hdr = (struct iphdr *) buf; addr.s_addr = ntohl(ip_hdr->saddr); printf("\n Source Addr = %s", inet_ntoa(addr)); addr.s_addr = ntohl(ip_hdr->daddr); } } }
ERP Project Management,Asp.net,PL SQL Tips for error resolution,Research,Software Errors and solution,SQL 2014,2012,2008,Procedural language,SP,Power BI,excel macro ,Musical notations,Business software,Degree, diploma related informations.