[950d54a] | 1 | #include <stdio.h> |
---|
| 2 | #include <inttypes.h> |
---|
| 3 | #include <dlfcn.h> |
---|
| 4 | #include "libpacketdump.h" |
---|
[e3b0188] | 5 | #include "libtrace.h" |
---|
[950d54a] | 6 | #include <netinet/udp.h> |
---|
| 7 | #include <netinet/in.h> |
---|
[010fafb] | 8 | #include <netdb.h> |
---|
[950d54a] | 9 | |
---|
| 10 | #define STRUCT udp |
---|
| 11 | |
---|
| 12 | #define SAFE(x) \ |
---|
| 13 | ((unsigned int)len>=((char*)&STRUCT->x-(char*)STRUCT+sizeof(STRUCT->x))) |
---|
| 14 | #define DISPLAY_EXP(x,fmt,exp) \ |
---|
| 15 | if (SAFE(x)) \ |
---|
| 16 | printf(fmt,exp); \ |
---|
| 17 | else \ |
---|
| 18 | return; |
---|
| 19 | |
---|
| 20 | #define DISPLAY(x,fmt) DISPLAY_EXP(x,fmt,STRUCT->x) |
---|
| 21 | |
---|
| 22 | #define DISPLAYS(x,fmt) DISPLAY_EXP(x,fmt,htons(STRUCT->x)) |
---|
| 23 | #define DISPLAYL(x,fmt) DISPLAY_EXP(x,fmt,htonl(STRUCT->x)) |
---|
| 24 | #define DISPLAYIP(x,fmt) DISPLAY_EXP(x,fmt,inet_ntoa(*(struct in_addr*)&STRUCT->x)) |
---|
| 25 | |
---|
| 26 | |
---|
[c7062df] | 27 | DLLEXPORT void decode(int link_type UNUSED,const char *packet,unsigned len) |
---|
[950d54a] | 28 | { |
---|
[e3b0188] | 29 | struct libtrace_udp *udp = (struct libtrace_udp*)packet; |
---|
[950d54a] | 30 | printf(" UDP:"); |
---|
[010fafb] | 31 | if (SAFE(source)) { |
---|
| 32 | struct servent *ent=getservbyport(udp->source,"udp"); |
---|
| 33 | if(ent) { |
---|
| 34 | printf(" Source %i (%s)",htons(udp->source),ent->s_name); |
---|
| 35 | } else { |
---|
| 36 | printf(" Source %i",htons(udp->source)); |
---|
| 37 | } |
---|
| 38 | } |
---|
| 39 | else { |
---|
| 40 | printf("\n"); |
---|
| 41 | return; |
---|
| 42 | } |
---|
| 43 | if (SAFE(dest)) { |
---|
| 44 | struct servent *ent=getservbyport(udp->dest,"udp"); |
---|
| 45 | if(ent) { |
---|
| 46 | printf(" Dest %i (%s)",htons(udp->dest),ent->s_name); |
---|
| 47 | } else { |
---|
| 48 | printf(" Dest %i",htons(udp->dest)); |
---|
| 49 | } |
---|
| 50 | } |
---|
| 51 | else { |
---|
| 52 | printf("\n"); |
---|
| 53 | return; |
---|
| 54 | } |
---|
[950d54a] | 55 | printf("\n UDP:"); |
---|
| 56 | DISPLAYS(len," Len %u"); |
---|
| 57 | DISPLAYS(check," Checksum %u"); |
---|
| 58 | printf("\n"); |
---|
| 59 | if (htons(udp->source) < htons(udp->dest)) |
---|
| 60 | decode_next(packet+sizeof(*udp),len-sizeof(*udp),"udp",htons(udp->source)); |
---|
| 61 | else |
---|
| 62 | decode_next(packet+sizeof(*udp),len-sizeof(*udp),"udp",htons(udp->dest)); |
---|
| 63 | return; |
---|
| 64 | } |
---|