1 /* $NetBSD: print-cnfp.c,v 1.5 2007/07/24 11:53:43 drochner Exp $ */
3 /* $OpenBSD: print-cnfp.c,v 1.2 1998/06/25 20:26:59 mickey Exp $ */
6 * Copyright (c) 1998 Michael Shalayeff
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 * 2. Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in the
16 * documentation and/or other materials provided with the distribution.
18 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
19 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
20 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
21 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
22 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
23 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
27 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 /* Cisco NetFlow protocol */
32 #include <sys/cdefs.h>
35 static const char rcsid
[] _U_
=
36 "@(#) Header: /tcpdump/master/tcpdump/print-cnfp.c,v 1.16.2.1 2005/04/20 20:53:39 guy Exp";
38 __RCSID("$NetBSD: print-cnfp.c,v 1.5 2007/07/24 11:53:43 drochner Exp $");
46 #include <tcpdump-stdinc.h>
51 #include "interface.h"
52 #include "addrtoname.h"
59 u_int32_t ver_cnt
; /* version [15], and # of records */
60 u_int32_t msys_uptime
;
63 u_int32_t sequence
; /* v5 flow sequence number */
64 u_int32_t reserved
; /* v5 only */
68 struct in_addr src_ina
;
69 struct in_addr dst_ina
;
70 struct in_addr nhop_ina
;
71 u_int32_t ifaces
; /* src,dst ifaces */
74 u_int32_t start_time
; /* sys_uptime value */
75 u_int32_t last_time
; /* sys_uptime value */
76 u_int32_t ports
; /* src,dst ports */
77 u_int32_t proto_tos
; /* proto, tos, pad, flags(v5) */
78 u_int32_t asses
; /* v1: flags; v5: src,dst AS */
79 u_int32_t masks
; /* src,dst addr prefix; v6: encaps */
80 struct in_addr peer_nexthop
; /* v6: IP address of the nexthop within the peer (FIB)*/
84 cnfp_print(const u_char
*cp
, const u_char
*bp _U_
)
86 register const struct nfhdr
*nh
;
87 register const struct nfrec
*nr
;
88 struct protoent
*pent
;
94 nh
= (const struct nfhdr
*)cp
;
96 if ((const u_char
*)(nh
+ 1) > snapend
)
99 nrecs
= EXTRACT_32BITS(&nh
->ver_cnt
) & 0xffff;
100 ver
= (EXTRACT_32BITS(&nh
->ver_cnt
) & 0xffff0000) >> 16;
103 * This is seconds since the UN*X epoch, and is followed by
104 * nanoseconds. XXX - format it, rather than just dumping the
105 * raw seconds-since-the-Epoch.
107 t
= EXTRACT_32BITS(&nh
->utc_sec
);
110 printf("NetFlow v%x, %u.%03u uptime, %u.%09u, ", ver
,
111 EXTRACT_32BITS(&nh
->msys_uptime
)/1000,
112 EXTRACT_32BITS(&nh
->msys_uptime
)%1000,
113 EXTRACT_32BITS(&nh
->utc_sec
), EXTRACT_32BITS(&nh
->utc_nsec
));
115 if (ver
== 5 || ver
== 6) {
116 printf("#%u, ", EXTRACT_32BITS(&nh
->sequence
));
117 nr
= (const struct nfrec
*)&nh
[1];
120 nr
= (const struct nfrec
*)&nh
->sequence
;
124 printf("%2u recs", nrecs
);
126 for (; nrecs
-- && (const u_char
*)(nr
+ 1) <= snapend
; nr
++) {
130 printf("\n started %u.%03u, last %u.%03u",
131 EXTRACT_32BITS(&nr
->start_time
)/1000,
132 EXTRACT_32BITS(&nr
->start_time
)%1000,
133 EXTRACT_32BITS(&nr
->last_time
)/1000,
134 EXTRACT_32BITS(&nr
->last_time
)%1000);
136 asbuf
[0] = buf
[0] = '\0';
137 if (ver
== 5 || ver
== 6) {
138 snprintf(buf
, sizeof(buf
), "/%u",
139 (EXTRACT_32BITS(&nr
->masks
) >> 24) & 0xff);
140 snprintf(asbuf
, sizeof(asbuf
), ":%u",
141 (EXTRACT_32BITS(&nr
->asses
) >> 16) & 0xffff);
143 printf("\n %s%s%s:%u ", intoa(nr
->src_ina
.s_addr
), buf
, asbuf
,
144 EXTRACT_32BITS(&nr
->ports
) >> 16);
146 if (ver
== 5 || ver
==6) {
147 snprintf(buf
, sizeof(buf
), "/%d",
148 (EXTRACT_32BITS(&nr
->masks
) >> 16) & 0xff);
149 snprintf(asbuf
, sizeof(asbuf
), ":%u",
150 EXTRACT_32BITS(&nr
->asses
) & 0xffff);
152 printf("> %s%s%s:%u ", intoa(nr
->dst_ina
.s_addr
), buf
, asbuf
,
153 EXTRACT_32BITS(&nr
->ports
) & 0xffff);
155 printf(">> %s\n ", intoa(nr
->nhop_ina
.s_addr
));
157 pent
= getprotobynumber((EXTRACT_32BITS(&nr
->proto_tos
) >> 8) & 0xff);
160 (EXTRACT_32BITS(&nr
->proto_tos
) >> 8) & 0xff);
162 printf("%s ", pent
->p_name
);
164 /* tcp flags for tcp only */
165 if (pent
&& pent
->p_proto
== IPPROTO_TCP
) {
168 flags
= (EXTRACT_32BITS(&nr
->asses
) >> 24) & 0xff;
170 flags
= (EXTRACT_32BITS(&nr
->proto_tos
) >> 16) & 0xff;
171 if (flags
& TH_FIN
) putchar('F');
172 if (flags
& TH_SYN
) putchar('S');
173 if (flags
& TH_RST
) putchar('R');
174 if (flags
& TH_PUSH
) putchar('P');
175 if (flags
& TH_ACK
) putchar('A');
176 if (flags
& TH_URG
) putchar('U');
183 snprintf(buf
, sizeof(buf
), "(%u<>%u encaps)",
184 (EXTRACT_32BITS(&nr
->masks
) >> 8) & 0xff,
185 (EXTRACT_32BITS(&nr
->masks
)) & 0xff);
187 printf("tos %u, %u (%u octets) %s",
188 EXTRACT_32BITS(&nr
->proto_tos
) & 0xff,
189 EXTRACT_32BITS(&nr
->packets
),
190 EXTRACT_32BITS(&nr
->octets
), buf
);