- printf("ip protocol: ");
- ip_hdr=(struct ip *)(package+sizeof(struct ethhdr));
- printf("version = %x ",ntohs(ip_hdr->ip_v));
- printf("header_length = %x \n",ntohs(ip_hdr->ip_hl));
- // i=0;
- //printf("service = %x ",*(ip_hdr->ip_tos));
- //printf("total_length(dec.) = %hu \n",*(ip_hdr->ip_len));
- //printf("ip_addresses: source = ");
- //for(i=0;i<4;i++)
- // printf("%x%s",*(ip_hdr->ip_src+i),
- // (i==3?"\n":"."));
-
-
+ printf("ip protocol: (%d bytes)\n",i_o);
+ ip_hdr=(struct iphdr *)(package+p_o+w_o+e_o);
+ printf("version = %x ",ntohs(ip_hdr->version));
+ printf("header_length = %x \n",ntohs(ip_hdr->ihl));
+ printf("service = %x ",ntohs(ip_hdr->tos));
+ printf("total_length(dec.) = %d \n",ntohs(ip_hdr->tot_len));
+ printf("source_ip: ");
+ for(i=3;i>=0;--i) {
+ printf("%d%s",
+ ip_hdr->saddr&0xff<<i,
+ (i==0?"\n":"."));
+ }
+ printf("destination_ip: ");
+ for(i=3;i>=0;--i) {
+ printf("%d%s",
+ ip_hdr->daddr&0xff<<i,
+ (i==0?"\n":"."));
+ }
+ // printf("ip_addresses: source = ");
+ // printf("%s\tdestination = %s\n",inet_ntoa(ip_hdr->saddr),
+ // inet_ntoa(ip_hdr->daddr));
+ printf("ip_id = %x ",ntohs(ip_hdr->id));
+ printf("ip_offset = %x \n",ntohs(ip_hdr->frag_off));
+ printf("time2live = %x ip_proto = %x\n",ntohs(ip_hdr->ttl),
+ ntohs(ip_hdr->protocol));
+ // printf("chksum: %x\n",ntohs(ip_hdr->ip_sum));