34 #include "contiki-net.h"
86 #define ICMP_ECHO_REPLY 0
130 #define ETHBUF ((struct eth_hdr *)&packet[0])
131 #define IPBUF ((struct ip_hdr *)&packet[0])
132 #define UDPBUF ((struct udpip_hdr *)&packet[0])
133 #define ICMPBUF ((struct icmpip_hdr *)&packet[0])
134 #define TCPBUF ((struct tcpip_hdr *)&packet[0])
139 tcpflags(
unsigned char flags,
char *flagsstr)
141 if(flags & TCP_FIN) {
144 if(flags & TCP_SYN) {
147 if(flags & TCP_RST) {
150 if(flags & TCP_ACK) {
153 if(flags & TCP_URG) {
161 n(u16_t num,
char *ptr)
171 for(d = 10000; d >= 1; d /= 10) {
173 if(f == 1 || a > 0) {
191 s(
char *str,
char *ptr)
194 return ptr + strlen(str);
198 tcpdump_format(u8_t *packet, u16_t packetlen,
199 char *buf, u16_t buflen)
202 if(IPBUF->proto == UIP_PROTO_ICMP) {
203 if(ICMPBUF->type == ICMP_ECHO) {
205 n(IPBUF->destipaddr[3], d(
206 n(IPBUF->destipaddr[2], d(
207 n(IPBUF->destipaddr[1], d(
208 n(IPBUF->destipaddr[0],
210 n(IPBUF->srcipaddr[3], d(
211 n(IPBUF->srcipaddr[2], d(
212 n(IPBUF->srcipaddr[1], d(
213 n(IPBUF->srcipaddr[0],
214 buf)))))))))))))))) - buf;
221 }
else if(ICMPBUF->type == ICMP_ECHO_REPLY) {
223 n(IPBUF->destipaddr[3], d(
224 n(IPBUF->destipaddr[2], d(
225 n(IPBUF->destipaddr[1], d(
226 n(IPBUF->destipaddr[0],
228 n(IPBUF->srcipaddr[3], d(
229 n(IPBUF->srcipaddr[2], d(
230 n(IPBUF->srcipaddr[1], d(
231 n(IPBUF->srcipaddr[0],
232 buf)))))))))))))))) - buf;
239 }
else if(IPBUF->proto == UIP_PROTO_UDP) {
242 n(IPBUF->destipaddr[3], d(
243 n(IPBUF->destipaddr[2], d(
244 n(IPBUF->destipaddr[1], d(
245 n(IPBUF->destipaddr[0],
248 n(IPBUF->srcipaddr[3], d(
249 n(IPBUF->srcipaddr[2], d(
250 n(IPBUF->srcipaddr[1], d(
251 n(IPBUF->srcipaddr[0],
252 buf)))))))))))))))))))) - buf;
260 }
else if(IPBUF->proto == UIP_PROTO_TCP) {
261 tcpflags(TCPBUF->flags, flags);
265 n(IPBUF->destipaddr[3], d(
266 n(IPBUF->destipaddr[2], d(
267 n(IPBUF->destipaddr[1], d(
268 n(IPBUF->destipaddr[0],
271 n(IPBUF->srcipaddr[3], d(
272 n(IPBUF->srcipaddr[2], d(
273 n(IPBUF->srcipaddr[1], d(
274 n(IPBUF->srcipaddr[0],
275 buf))))))))))))))))))))) - buf;
285 strcpy(buf,
"Unrecognized protocol");