2 * netsniff-ng - the packet sniffing beast
3 * By Daniel Borkmann <daniel@netsniff-ng.org>
4 * Copyright 2009, 2010 Daniel Borkmann.
5 * Copyright 2010 Emmanuel Roullit.
6 * Subject to the GPL, version 2.
14 #include <netinet/in.h> /* for ntohs() */
15 #include <arpa/inet.h> /* for inet_ntop() */
16 #include <asm/byteorder.h>
19 #include "proto_struct.h"
20 #include "dissector_eth.h"
25 * BEWARE, it is incorrect. The first 4 bits of flow_lbl
26 * are glued to priority now, forming "class".
29 #if defined(__LITTLE_ENDIAN_BITFIELD)
30 __extension__
uint8_t priority
:4,
32 #elif defined(__BIG_ENDIAN_BITFIELD)
33 __extension__
uint8_t version
:4,
36 # error "Please fix <asm/byteorder.h>"
42 struct in6_addr saddr
;
43 struct in6_addr daddr
;
44 } __attribute__((packed
));
46 static inline void ipv6(uint8_t *packet
, size_t len
)
48 uint8_t traffic_class
;
50 char src_ip
[INET6_ADDRSTRLEN
];
51 char dst_ip
[INET6_ADDRSTRLEN
];
52 struct ipv6hdr
*ip
= (struct ipv6hdr
*) packet
;
54 if (len
< sizeof(struct ipv6hdr
))
57 traffic_class
= (ip
->priority
<< 4) |
58 ((ip
->flow_lbl
[0] & 0xF0) >> 4);
59 flow_label
= ((ip
->flow_lbl
[0] & 0x0F) << 8) |
60 (ip
->flow_lbl
[1] << 4) | ip
->flow_lbl
[2];
62 inet_ntop(AF_INET6
, &ip
->saddr
, src_ip
, sizeof(src_ip
));
63 inet_ntop(AF_INET6
, &ip
->daddr
, dst_ip
, sizeof(dst_ip
));
66 tprintf("Addr (%s => %s), ", src_ip
, dst_ip
);
67 tprintf("Version (%u), ", ip
->version
);
68 tprintf("TrafficClass (%u), ", traffic_class
);
69 tprintf("FlowLabel (%u), ", flow_label
);
70 tprintf("Len (%u), ", ntohs(ip
->payload_len
));
71 tprintf("NextHdr (%u), ", ip
->nexthdr
);
72 tprintf("HopLimit (%u)", ip
->hop_limit
);
76 static inline void ipv6_less(uint8_t *packet
, size_t len
)
78 char src_ip
[INET6_ADDRSTRLEN
];
79 char dst_ip
[INET6_ADDRSTRLEN
];
80 struct ipv6hdr
*ip
= (struct ipv6hdr
*) packet
;
82 if (len
< sizeof(struct ipv6hdr
))
85 inet_ntop(AF_INET6
, &ip
->saddr
, src_ip
, sizeof(src_ip
));
86 inet_ntop(AF_INET6
, &ip
->daddr
, dst_ip
, sizeof(dst_ip
));
88 tprintf(" IPv6 %s/%s Len %u", src_ip
, dst_ip
,
89 ntohs(ip
->payload_len
));
92 static inline void ipv6_next(uint8_t *packet
, size_t len
,
93 struct hash_table
**table
,
94 unsigned int *key
, size_t *off
)
96 struct ipv6hdr
*ip
= (struct ipv6hdr
*) packet
;
98 if (len
< sizeof(struct ipv6hdr
))
101 (*off
) = sizeof(struct ipv6hdr
);
102 (*key
) = ip
->nexthdr
;
103 (*table
) = ð_lay3
;
112 struct protocol ipv6_ops
= {
114 .offset
= sizeof(struct ipv6hdr
),
116 .print_less
= ipv6_less
,
117 .print_pay_ascii
= empty
,
118 .print_pay_hex
= empty
,
119 .print_pay_none
= ipv6
,
120 .print_all_cstyle
= __hex2
,
121 .print_all_hex
= __hex
,
122 .proto_next
= ipv6_next
,