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"
27 * BEWARE, it is incorrect. The first 4 bits of flow_lbl
28 * are glued to priority now, forming "class".
31 #if defined(__LITTLE_ENDIAN_BITFIELD)
32 __extension__
uint8_t priority
:4,
34 #elif defined(__BIG_ENDIAN_BITFIELD)
35 __extension__
uint8_t version
:4,
38 # error "Please fix <asm/byteorder.h>"
44 struct in6_addr saddr
;
45 struct in6_addr daddr
;
48 static inline void ipv6(struct pkt_buff
*pkt
)
50 uint8_t traffic_class
;
52 char src_ip
[INET6_ADDRSTRLEN
];
53 char dst_ip
[INET6_ADDRSTRLEN
];
54 struct ipv6hdr
*ip
= (struct ipv6hdr
*) pkt_pull(pkt
, sizeof(*ip
));
59 traffic_class
= (ip
->priority
<< 4) |
60 ((ip
->flow_lbl
[0] & 0xF0) >> 4);
61 flow_label
= ((ip
->flow_lbl
[0] & 0x0F) << 8) |
62 (ip
->flow_lbl
[1] << 4) | ip
->flow_lbl
[2];
64 inet_ntop(AF_INET6
, &ip
->saddr
, src_ip
, sizeof(src_ip
));
65 inet_ntop(AF_INET6
, &ip
->daddr
, dst_ip
, sizeof(dst_ip
));
68 tprintf("Addr (%s => %s), ", src_ip
, dst_ip
);
69 tprintf("Version (%u), ", ip
->version
);
70 tprintf("TrafficClass (%u), ", traffic_class
);
71 tprintf("FlowLabel (%u), ", flow_label
);
72 tprintf("Len (%u), ", ntohs(ip
->payload_len
));
73 tprintf("NextHdr (%u), ", ip
->nexthdr
);
74 tprintf("HopLimit (%u)", ip
->hop_limit
);
77 pkt_set_proto(pkt
, ð_lay3
, ip
->nexthdr
);
80 static inline void ipv6_less(struct pkt_buff
*pkt
)
82 char src_ip
[INET6_ADDRSTRLEN
];
83 char dst_ip
[INET6_ADDRSTRLEN
];
84 struct ipv6hdr
*ip
= (struct ipv6hdr
*) pkt_pull(pkt
, sizeof(*ip
));
89 inet_ntop(AF_INET6
, &ip
->saddr
, src_ip
, sizeof(src_ip
));
90 inet_ntop(AF_INET6
, &ip
->daddr
, dst_ip
, sizeof(dst_ip
));
92 tprintf(" %s/%s Len %u", src_ip
, dst_ip
,
93 ntohs(ip
->payload_len
));
95 pkt_set_proto(pkt
, ð_lay3
, ip
->nexthdr
);
98 struct protocol ipv6_ops
= {
101 .print_less
= ipv6_less
,
104 #endif /* PROTO_IPV6_H */