2 * netsniff-ng - the packet sniffing beast
3 * By Daniel Borkmann <daniel@netsniff-ng.org>.
4 * Copyright (C) 2009, 2010 Daniel Borkmann
5 * Copyright (C) 2012 Christoph Jaeger <christoph@netsniff-ng.org>
6 * Subject to the GPL, version 2.
18 /* necessary forward declarations */
20 static inline unsigned int pkt_len(struct pkt_buff
*pkt
);
21 static uint8_t *pkt_pull(struct pkt_buff
*pkt
, unsigned int len
);
24 /* Needs to be filled out by user */
26 void (*print_full
)(struct pkt_buff
*pkt
);
27 void (*print_less
)(struct pkt_buff
*pkt
);
28 /* Used by program logic */
29 struct protocol
*next
;
30 void (*process
) (struct pkt_buff
*pkt
);
33 static inline void empty(struct pkt_buff
*pkt
) {}
35 static inline void _hex(uint8_t *ptr
, size_t len
)
41 for (; ptr
&& len
-- > 0; ptr
++)
42 tprintf(" %.2x", *ptr
);
46 static inline void hex(struct pkt_buff
*pkt
)
48 size_t len
= pkt_len(pkt
);
53 _hex(pkt_pull(pkt
, len
), len
);
57 static inline void _ascii(uint8_t *ptr
, size_t len
)
63 for (; ptr
&& len
-- > 0; ptr
++)
64 tprintf(" %c ", isprint(*ptr
) ? *ptr
: '.');
68 static inline void ascii(struct pkt_buff
*pkt
)
70 size_t len
= pkt_len(pkt
);
75 _ascii(pkt_pull(pkt
, len
), len
);
79 static inline void hex_ascii(struct pkt_buff
*pkt
)
81 size_t len
= pkt_len(pkt
);
82 uint8_t *ptr
= pkt_pull(pkt
, len
);