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) {
+ for(i=0;i<=3;++i) {
printf("%d%s",
- ip_hdr->saddr&0xff<<i,
- (i==0?"\n":"."));
+ (ip_hdr->saddr&(0xff<<(8*i)))>>(8*i),
+ (i==3?"\n":"."));
}
printf("destination_ip: ");
- for(i=3;i>=0;--i) {
+ for(i=0;i<=3;++i) {
printf("%d%s",
- ip_hdr->daddr&0xff<<i,
- (i==0?"\n":"."));
+ (ip_hdr->daddr&(0xff<<(8*i)))>>(8*i),
+ (i==3?"\n":"."));
}
printf("ip_id = %x ",ntohs(ip_hdr->id));
printf("ip_offset = %x \n",ntohs(ip_hdr->frag_off));