]>
The Tcpdump Group git mirrors - tcpdump/blob - print-cnfp.c
1 /* $OpenBSD: print-cnfp.c,v 1.2 1998/06/25 20:26:59 mickey Exp $ */
4 * Copyright (c) 1998 Michael Shalayeff
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * 3. All advertising materials mentioning features or use of this software
16 * must display the following acknowledgement:
17 * This product includes software developed by Michael Shalayeff.
18 * 4. The name of the author may not be used to endorse or promote products
19 * derived from this software without specific prior written permission.
21 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
22 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
23 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
24 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
25 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
26 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
30 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 /* Cisco NetFlow protocol */
36 static const char rcsid
[] =
37 "@(#) $Header: /tcpdump/master/tcpdump/print-cnfp.c,v 1.9 2002-08-01 08:53:03 risso Exp $";
44 #include <tcpdump-stdinc.h>
49 #include "interface.h"
54 u_int32_t ver_cnt
; /* version [15], and # of records */
55 u_int32_t msys_uptime
;
58 u_int32_t sequence
; /* v5 flow sequence number */
59 u_int32_t reserved
; /* v5 only */
63 struct in_addr src_ina
;
64 struct in_addr dst_ina
;
65 struct in_addr nhop_ina
;
66 u_int32_t ifaces
; /* src,dst ifaces */
69 u_int32_t start_time
; /* sys_uptime value */
70 u_int32_t last_time
; /* sys_uptime value */
71 u_int32_t ports
; /* src,dst ports */
72 u_int32_t proto_tos
; /* proto, tos, pad, flags(v5) */
73 u_int32_t asses
; /* v1: flags; v5: src,dst AS */
74 u_int32_t masks
; /* src,dst addr prefix; v6: encaps */
75 struct in_addr peer_nexthop
; /* v6: IP address of the nexthop within the peer (FIB)*/
79 cnfp_print(const u_char
*cp
, u_int len
, const u_char
*bp
)
81 register const struct nfhdr
*nh
;
82 register const struct nfrec
*nr
;
83 register const struct ip
*ip
;
84 struct protoent
*pent
;
88 ip
= (const struct ip
*)bp
;
89 nh
= (const struct nfhdr
*)cp
;
91 if ((const u_char
*)(nh
+ 1) > snapend
)
94 nrecs
= ntohl(nh
->ver_cnt
) & 0xffff;
95 ver
= (ntohl(nh
->ver_cnt
) & 0xffff0000) >> 16;
96 t
= ntohl(nh
->utc_sec
);
97 /* (p = ctime(&t))[24] = '\0'; */
99 printf("NetFlow v%x, %u.%03u uptime, %u.%09u, ", ver
,
100 (unsigned)ntohl(nh
->msys_uptime
)/1000,
101 (unsigned)ntohl(nh
->msys_uptime
)%1000,
102 (unsigned)ntohl(nh
->utc_sec
), (unsigned)ntohl(nh
->utc_nsec
));
104 if (ver
== 5 || ver
== 6) {
105 printf("#%u, ", (unsigned)htonl(nh
->sequence
));
106 nr
= (const struct nfrec
*)&nh
[1];
109 nr
= (const struct nfrec
*)&nh
->sequence
;
113 printf("%2u recs", nrecs
);
115 for (; nrecs
-- && (const u_char
*)(nr
+ 1) <= snapend
; nr
++) {
119 printf("\n started %u.%03u, last %u.%03u",
120 (unsigned)ntohl(nr
->start_time
)/1000,
121 (unsigned)ntohl(nr
->start_time
)%1000,
122 (unsigned)ntohl(nr
->last_time
)/1000,
123 (unsigned)ntohl(nr
->last_time
)%1000);
125 asbuf
[0] = buf
[0] = '\0';
126 if (ver
== 5 || ver
== 6) {
127 snprintf(buf
, sizeof(buf
), "/%u",
128 (unsigned)(ntohl(nr
->masks
) >> 24) & 0xff);
129 snprintf(asbuf
, sizeof(asbuf
), ":%u",
130 (unsigned)(ntohl(nr
->asses
) >> 16) & 0xffff);
132 printf("\n %s%s%s:%u ", inet_ntoa(nr
->src_ina
), buf
, asbuf
,
133 (unsigned)ntohl(nr
->ports
) >> 16);
135 if (ver
== 5 || ver
==6) {
136 snprintf(buf
, sizeof(buf
), "/%d",
137 (unsigned)(ntohl(nr
->masks
) >> 16) & 0xff);
138 snprintf(asbuf
, sizeof(asbuf
), ":%u",
139 (unsigned)ntohl(nr
->asses
) & 0xffff);
141 printf("> %s%s%s:%u ", inet_ntoa(nr
->dst_ina
), buf
, asbuf
,
142 (unsigned)ntohl(nr
->ports
) & 0xffff);
144 printf(">> %s\n ", inet_ntoa(nr
->nhop_ina
));
146 pent
= getprotobynumber((ntohl(nr
->proto_tos
) >> 8) & 0xff);
149 (unsigned)(ntohl(nr
->proto_tos
) >> 8) & 0xff);
151 printf("%s ", pent
->p_name
);
153 /* tcp flags for tcp only */
154 if (pent
&& pent
->p_proto
== IPPROTO_TCP
) {
157 flags
= (ntohl(nr
->asses
) >> 24) & 0xff;
159 flags
= (ntohl(nr
->proto_tos
) >> 16) & 0xff;
160 if (flags
& TH_FIN
) putchar('F');
161 if (flags
& TH_SYN
) putchar('S');
162 if (flags
& TH_RST
) putchar('R');
163 if (flags
& TH_PUSH
) putchar('P');
164 if (flags
& TH_ACK
) putchar('A');
165 if (flags
& TH_URG
) putchar('U');
172 snprintf(buf
, sizeof(buf
), "(%u<>%u encaps)",
173 (unsigned)(ntohl(nr
->masks
) >> 8) & 0xff,
174 (unsigned)(ntohl(nr
->masks
)) & 0xff);
176 printf("tos %u, %u (%u octets) %s",
177 (unsigned)ntohl(nr
->proto_tos
) & 0xff,
178 (unsigned)ntohl(nr
->packets
),
179 (unsigned)ntohl(nr
->octets
), buf
);