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.
11 #include <netinet/in.h> /* for ntohs() */
12 #include <arpa/inet.h> /* for inet_ntop() */
13 #include <asm/byteorder.h>
18 #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
;
46 extern void ipv6(struct pkt_buff
*pkt
);
47 extern void ipv6_less(struct pkt_buff
*pkt
);
49 void ipv6(struct pkt_buff
*pkt
)
51 uint8_t traffic_class
;
53 char src_ip
[INET6_ADDRSTRLEN
];
54 char dst_ip
[INET6_ADDRSTRLEN
];
55 struct ipv6hdr
*ip
= (struct ipv6hdr
*) pkt_pull(pkt
, sizeof(*ip
));
60 traffic_class
= (ip
->priority
<< 4) |
61 ((ip
->flow_lbl
[0] & 0xF0) >> 4);
62 flow_label
= ((ip
->flow_lbl
[0] & 0x0F) << 8) |
63 (ip
->flow_lbl
[1] << 4) | ip
->flow_lbl
[2];
65 inet_ntop(AF_INET6
, &ip
->saddr
, src_ip
, sizeof(src_ip
));
66 inet_ntop(AF_INET6
, &ip
->daddr
, dst_ip
, sizeof(dst_ip
));
69 tprintf("Addr (%s => %s), ", src_ip
, dst_ip
);
70 tprintf("Version (%u), ", ip
->version
);
71 tprintf("TrafficClass (%u), ", traffic_class
);
72 tprintf("FlowLabel (%u), ", flow_label
);
73 tprintf("Len (%u), ", ntohs(ip
->payload_len
));
74 tprintf("NextHdr (%u), ", ip
->nexthdr
);
75 tprintf("HopLimit (%u)", ip
->hop_limit
);
78 pkt_set_proto(pkt
, ð_lay3
, ip
->nexthdr
);
81 void ipv6_less(struct pkt_buff
*pkt
)
83 char src_ip
[INET6_ADDRSTRLEN
];
84 char dst_ip
[INET6_ADDRSTRLEN
];
85 struct ipv6hdr
*ip
= (struct ipv6hdr
*) pkt_pull(pkt
, sizeof(*ip
));
90 inet_ntop(AF_INET6
, &ip
->saddr
, src_ip
, sizeof(src_ip
));
91 inet_ntop(AF_INET6
, &ip
->daddr
, dst_ip
, sizeof(dst_ip
));
93 tprintf(" %s/%s Len %u", src_ip
, dst_ip
,
94 ntohs(ip
->payload_len
));
96 pkt_set_proto(pkt
, ð_lay3
, ip
->nexthdr
);
99 struct protocol ipv6_ops
= {
102 .print_less
= ipv6_less
,
105 EXPORT_SYMBOL(ipv6_ops
);