DLLEXPORT void decode(int link_type UNUSED,const char *packet,unsigned len) { libtrace_ip_t *ip = (libtrace_ip_t*)packet; if (len>=1) { printf(" IP: Header Len %i",ip->ip_hl*4); printf(" Ver %i",ip->ip_v); } //DISPLAY(ip_tos," TOS %02x") DISPLAY_EXP(ip_tos," DSCP %02x",ip->ip_tos >> 2) DISPLAY_EXP(ip_tos," ECN %x",ip->ip_tos & 0x2) DISPLAYS(ip_len," Total Length %i") printf("\n IP:"); DISPLAYS(ip_id," Id %u"); if ((unsigned int)len >= ((char *)&ip->ip_ttl - (char *)ip - 2)) { printf(" Fragoff %i", ntohs(ip->ip_off) & 0x1FFF); if (ntohs(ip->ip_off) & 0x2000) printf(" MORE_FRAG"); if (ntohs(ip->ip_off) & 0x4000) printf(" DONT_FRAG"); if (ntohs(ip->ip_off) & 0x8000) printf(" RESV_FRAG"); } //printf("\n IP:"); DISPLAY(ip_ttl,"\n IP: TTL %i"); if ((unsigned int)len>=((char*)&ip->ip_p-(char*)ip+sizeof(ip->ip_p))) { struct protoent *ent=getprotobynumber(ip->ip_p); if (ent) { printf(" Proto %i (%s)",ip->ip_p,ent->p_name); } else { printf(" Proto %i",ip->ip_p); } } else { printf("\n"); return; } DISPLAYS(ip_sum," Checksum %i\n"); DISPLAYIP(ip_src," IP: Source %s "); DISPLAYIP(ip_dst,"Destination %s\n"); decode_next(packet+ip->ip_hl*4,len-ip->ip_hl*4,"ip",ip->ip_p); return; }
DLLEXPORT void decode(int link_type UNUSED,const char *packet,unsigned len) { struct libtrace_udp *udp = (struct libtrace_udp*)packet; printf(" UDP:"); if (SAFE(udp, source)) { struct servent *ent=getservbyport(udp->source,"udp"); if(ent) { printf(" Source %i (%s)",htons(udp->source),ent->s_name); } else { printf(" Source %i",htons(udp->source)); } } else { printf("\n"); return; } if (SAFE(udp, dest)) { struct servent *ent=getservbyport(udp->dest,"udp"); if(ent) { printf(" Dest %i (%s)",htons(udp->dest),ent->s_name); } else { printf(" Dest %i",htons(udp->dest)); } } else { printf("\n"); return; } printf("\n UDP:"); DISPLAYS(udp, len," Len %u"); DISPLAYS(udp, check," Checksum %u"); printf("\n"); if (htons(udp->source) < htons(udp->dest)) decode_next(packet+sizeof(*udp),len-sizeof(*udp),"udp",htons(udp->source)); else decode_next(packet+sizeof(*udp),len-sizeof(*udp),"udp",htons(udp->dest)); return; }