extern void ascii_print(const u_char *, u_int);
extern void aarp_print(const u_char *, u_int);
-extern void aodv_print(const u_char *, u_int, int);
extern void atalk_print(const u_char *, u_int);
extern void bgp_print(const u_char *, int);
extern void decnet_print(const u_char *, u_int, u_int);
extern void cfm_print(const u_char *, u_int);
extern void cdp_print(const u_char *, u_int, u_int);
extern void lwres_print(const u_char *, u_int);
-extern void sctp_print(const u_char *, const u_char *, u_int);
extern void forces_print(const u_char *, u_int);
extern void mpls_lsp_ping_print(const u_char *, u_int);
extern void sip_print(const u_char *, u_int);
* @(#)ip.h 8.2 (Berkeley) 6/1/94
*/
+#ifndef TCPDUMP_IP_H
+#define TCPDUMP_IP_H
+
/*
* Definitions for internet protocol version 4.
* Per RFC 791, September 1981.
#define IPTTLDEC 1 /* subtracted when forwarding */
#define IP_MSS 576 /* default maximum segment size */
-
-/* in print-ip.c */
-extern int nextproto4_cksum(const struct ip *, const u_int8_t *, u_int, u_int, u_int);
+#endif /* TCPDUMP_IP_H */
#include <stdarg.h>
+#include "ip.h" /* struct ip for nextproto4_cksum() */
+
#if !defined(HAVE_SNPRINTF)
int snprintf (char *str, size_t sz, const char *format, ...)
#ifdef __ATTRIBUTE___FORMAT_OK
extern void ns_print(netdissect_options *, const u_char *, u_int, int);
extern void bootp_print(netdissect_options *, const u_char *, u_int);
extern void sflow_print(netdissect_options *, const u_char *, u_int);
+extern void aodv_print(netdissect_options *, const u_char *, u_int, int);
+extern void sctp_print(netdissect_options *, const u_char *, const u_char *, u_int);
/* stuff that has not yet been rototiled */
extern void ppp_bsdos_if_print(u_char *,
const struct pcap_pkthdr *, const u_char *);
-extern void sctp_print(netdissect_options *ndo,
- const u_char *bp, const u_char *bp2,
- u_int sctpPacketLength);
-
extern void snmp_print(netdissect_options *,const u_char *, u_int);
extern void tcp_print(netdissect_options *,const u_char *, u_int,
const u_char *, int);
extern u_int16_t in_cksum(const struct cksum_vec *, int);
extern u_int16_t in_cksum_shouldbe(u_int16_t, u_int16_t);
#endif
+extern int nextproto4_cksum(netdissect_options *ndo, const struct ip *, const u_int8_t *, u_int, u_int, u_int);
extern void esp_print_decodesecret(netdissect_options *ndo);
extern int esp_print_decrypt_buffer_by_ikev2(netdissect_options *ndo,
* POSSIBILITY OF SUCH DAMAGE.
*/
+#define NETDISSECT_REWORKED
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <tcpdump-stdinc.h>
+/* for offsetof */
#include <stddef.h>
-#include <stdio.h>
-#include <ctype.h>
-#include <string.h>
#include "interface.h"
#include "addrtoname.h"
#define AODV_EXT_HELLO 1
static void
-aodv_extension(const struct aodv_ext *ep, u_int length)
+aodv_extension(netdissect_options *ndo,
+ const struct aodv_ext *ep, u_int length)
{
u_int i;
const struct aodv_hello *ah;
switch (ep->type) {
case AODV_EXT_HELLO:
- if (snapend < (u_char *) ep) {
- printf(" [|hello]");
+ if (ndo->ndo_snapend < (u_char *) ep) {
+ ND_PRINT((ndo, " [|hello]"));
return;
}
- i = min(length, (u_int)(snapend - (u_char *)ep));
+ i = min(length, (u_int)(ndo->ndo_snapend - (u_char *)ep));
if (i < sizeof(struct aodv_hello)) {
- printf(" [|hello]");
+ ND_PRINT((ndo, " [|hello]"));
return;
}
i -= sizeof(struct aodv_hello);
ah = (void *)ep;
- printf("\n\text HELLO %ld ms",
- (unsigned long)EXTRACT_32BITS(&ah->interval));
+ ND_PRINT((ndo, "\n\text HELLO %ld ms",
+ (unsigned long)EXTRACT_32BITS(&ah->interval)));
break;
default:
- printf("\n\text %u %u", ep->type, ep->length);
+ ND_PRINT((ndo, "\n\text %u %u", ep->type, ep->length));
break;
}
}
static void
-aodv_rreq(const union aodv *ap, const u_char *dat, u_int length)
+aodv_rreq(netdissect_options *ndo,
+ const union aodv *ap, const u_char *dat, u_int length)
{
u_int i;
- if (snapend < dat) {
- printf(" [|aodv]");
+ if (ndo->ndo_snapend < dat) {
+ ND_PRINT((ndo, " [|aodv]"));
return;
}
- i = min(length, (u_int)(snapend - dat));
+ i = min(length, (u_int)(ndo->ndo_snapend - dat));
if (i < sizeof(ap->rreq)) {
- printf(" [|rreq]");
+ ND_PRINT((ndo, " [|rreq]"));
return;
}
i -= sizeof(ap->rreq);
- printf(" rreq %u %s%s%s%s%shops %u id 0x%08lx\n"
+ ND_PRINT((ndo, " rreq %u %s%s%s%s%shops %u id 0x%08lx\n"
"\tdst %s seq %lu src %s seq %lu", length,
ap->rreq.rreq_type & RREQ_JOIN ? "[J]" : "",
ap->rreq.rreq_type & RREQ_REPAIR ? "[R]" : "",
ipaddr_string(&ap->rreq.rreq_da),
(unsigned long)EXTRACT_32BITS(&ap->rreq.rreq_ds),
ipaddr_string(&ap->rreq.rreq_oa),
- (unsigned long)EXTRACT_32BITS(&ap->rreq.rreq_os));
+ (unsigned long)EXTRACT_32BITS(&ap->rreq.rreq_os)));
if (i >= sizeof(struct aodv_ext))
- aodv_extension((void *)(&ap->rreq + 1), i);
+ aodv_extension(ndo, (void *)(&ap->rreq + 1), i);
}
static void
-aodv_rrep(const union aodv *ap, const u_char *dat, u_int length)
+aodv_rrep(netdissect_options *ndo,
+ const union aodv *ap, const u_char *dat, u_int length)
{
u_int i;
- if (snapend < dat) {
- printf(" [|aodv]");
+ if (ndo->ndo_snapend < dat) {
+ ND_PRINT((ndo, " [|aodv]"));
return;
}
- i = min(length, (u_int)(snapend - dat));
+ i = min(length, (u_int)(ndo->ndo_snapend - dat));
if (i < sizeof(ap->rrep)) {
- printf(" [|rrep]");
+ ND_PRINT((ndo, " [|rrep]"));
return;
}
i -= sizeof(ap->rrep);
- printf(" rrep %u %s%sprefix %u hops %u\n"
+ ND_PRINT((ndo, " rrep %u %s%sprefix %u hops %u\n"
"\tdst %s dseq %lu src %s %lu ms", length,
ap->rrep.rrep_type & RREP_REPAIR ? "[R]" : "",
ap->rrep.rrep_type & RREP_ACK ? "[A] " : " ",
ipaddr_string(&ap->rrep.rrep_da),
(unsigned long)EXTRACT_32BITS(&ap->rrep.rrep_ds),
ipaddr_string(&ap->rrep.rrep_oa),
- (unsigned long)EXTRACT_32BITS(&ap->rrep.rrep_life));
+ (unsigned long)EXTRACT_32BITS(&ap->rrep.rrep_life)));
if (i >= sizeof(struct aodv_ext))
- aodv_extension((void *)(&ap->rrep + 1), i);
+ aodv_extension(ndo, (void *)(&ap->rrep + 1), i);
}
static void
-aodv_rerr(const union aodv *ap, const u_char *dat, u_int length)
+aodv_rerr(netdissect_options *ndo,
+ const union aodv *ap, const u_char *dat, u_int length)
{
u_int i;
const struct rerr_unreach *dp = NULL;
int n, trunc;
- if (snapend < dat) {
- printf(" [|aodv]");
+ if (ndo->ndo_snapend < dat) {
+ ND_PRINT((ndo, " [|aodv]"));
return;
}
- i = min(length, (u_int)(snapend - dat));
+ i = min(length, (u_int)(ndo->ndo_snapend - dat));
if (i < offsetof(struct aodv_rerr, r)) {
- printf(" [|rerr]");
+ ND_PRINT((ndo, " [|rerr]"));
return;
}
i -= offsetof(struct aodv_rerr, r);
dp = &ap->rerr.r.dest[0];
n = ap->rerr.rerr_dc * sizeof(ap->rerr.r.dest[0]);
- printf(" rerr %s [items %u] [%u]:",
+ ND_PRINT((ndo, " rerr %s [items %u] [%u]:",
ap->rerr.rerr_flags & RERR_NODELETE ? "[D]" : "",
- ap->rerr.rerr_dc, length);
+ ap->rerr.rerr_dc, length));
trunc = n - (i/sizeof(ap->rerr.r.dest[0]));
for (; i >= sizeof(ap->rerr.r.dest[0]);
++dp, i -= sizeof(ap->rerr.r.dest[0])) {
- printf(" {%s}(%ld)", ipaddr_string(&dp->u_da),
- (unsigned long)EXTRACT_32BITS(&dp->u_ds));
+ ND_PRINT((ndo, " {%s}(%ld)", ipaddr_string(&dp->u_da),
+ (unsigned long)EXTRACT_32BITS(&dp->u_ds)));
}
if (trunc)
- printf("[|rerr]");
+ ND_PRINT((ndo, "[|rerr]"));
}
static void
#ifdef INET6
-aodv_v6_rreq(const union aodv *ap, const u_char *dat, u_int length)
+aodv_v6_rreq(netdissect_options *ndo,
+ const union aodv *ap, const u_char *dat, u_int length)
#else
-aodv_v6_rreq(const union aodv *ap _U_, const u_char *dat _U_, u_int length)
+aodv_v6_rreq(netdissect_options *ndo,
+ const union aodv *ap _U_, const u_char *dat _U_, u_int length)
#endif
{
#ifdef INET6
u_int i;
- if (snapend < dat) {
- printf(" [|aodv]");
+ if (ndo->ndo_snapend < dat) {
+ ND_PRINT((ndo, " [|aodv]"));
return;
}
- i = min(length, (u_int)(snapend - dat));
+ i = min(length, (u_int)(ndo->ndo_snapend - dat));
if (i < sizeof(ap->rreq6)) {
- printf(" [|rreq6]");
+ ND_PRINT((ndo, " [|rreq6]"));
return;
}
i -= sizeof(ap->rreq6);
- printf(" v6 rreq %u %s%s%s%s%shops %u id 0x%08lx\n"
+ ND_PRINT((ndo, " v6 rreq %u %s%s%s%s%shops %u id 0x%08lx\n"
"\tdst %s seq %lu src %s seq %lu", length,
ap->rreq6.rreq_type & RREQ_JOIN ? "[J]" : "",
ap->rreq6.rreq_type & RREQ_REPAIR ? "[R]" : "",
ip6addr_string(&ap->rreq6.rreq_da),
(unsigned long)EXTRACT_32BITS(&ap->rreq6.rreq_ds),
ip6addr_string(&ap->rreq6.rreq_oa),
- (unsigned long)EXTRACT_32BITS(&ap->rreq6.rreq_os));
+ (unsigned long)EXTRACT_32BITS(&ap->rreq6.rreq_os)));
if (i >= sizeof(struct aodv_ext))
- aodv_extension((void *)(&ap->rreq6 + 1), i);
+ aodv_extension(ndo, (void *)(&ap->rreq6 + 1), i);
#else
- printf(" v6 rreq %u", length);
+ ND_PRINT((ndo, " v6 rreq %u", length));
#endif
}
static void
#ifdef INET6
-aodv_v6_rrep(const union aodv *ap, const u_char *dat, u_int length)
+aodv_v6_rrep(netdissect_options *ndo,
+ const union aodv *ap, const u_char *dat, u_int length)
#else
-aodv_v6_rrep(const union aodv *ap _U_, const u_char *dat _U_, u_int length)
+aodv_v6_rrep(netdissect_options *ndo,
+ const union aodv *ap _U_, const u_char *dat _U_, u_int length)
#endif
{
#ifdef INET6
u_int i;
- if (snapend < dat) {
- printf(" [|aodv]");
+ if (ndo->ndo_snapend < dat) {
+ ND_PRINT((ndo, " [|aodv]"));
return;
}
- i = min(length, (u_int)(snapend - dat));
+ i = min(length, (u_int)(ndo->ndo_snapend - dat));
if (i < sizeof(ap->rrep6)) {
- printf(" [|rrep6]");
+ ND_PRINT((ndo, " [|rrep6]"));
return;
}
i -= sizeof(ap->rrep6);
- printf(" rrep %u %s%sprefix %u hops %u\n"
+ ND_PRINT((ndo, " rrep %u %s%sprefix %u hops %u\n"
"\tdst %s dseq %lu src %s %lu ms", length,
ap->rrep6.rrep_type & RREP_REPAIR ? "[R]" : "",
ap->rrep6.rrep_type & RREP_ACK ? "[A] " : " ",
ip6addr_string(&ap->rrep6.rrep_da),
(unsigned long)EXTRACT_32BITS(&ap->rrep6.rrep_ds),
ip6addr_string(&ap->rrep6.rrep_oa),
- (unsigned long)EXTRACT_32BITS(&ap->rrep6.rrep_life));
+ (unsigned long)EXTRACT_32BITS(&ap->rrep6.rrep_life)));
if (i >= sizeof(struct aodv_ext))
- aodv_extension((void *)(&ap->rrep6 + 1), i);
+ aodv_extension(ndo, (void *)(&ap->rrep6 + 1), i);
#else
- printf(" rrep %u", length);
+ ND_PRINT((ndo, " rrep %u", length));
#endif
}
static void
#ifdef INET6
-aodv_v6_rerr(const union aodv *ap, u_int length)
+aodv_v6_rerr(netdissect_options *ndo,
+ const union aodv *ap, u_int length)
#else
-aodv_v6_rerr(const union aodv *ap _U_, u_int length)
+aodv_v6_rerr(netdissect_options *ndo,
+ const union aodv *ap _U_, u_int length)
#endif
{
#ifdef INET6
j = sizeof(ap->rerr.r.dest6[0]);
dp6 = &ap->rerr.r.dest6[0];
n = ap->rerr.rerr_dc * j;
- printf(" rerr %s [items %u] [%u]:",
+ ND_PRINT((ndo, " rerr %s [items %u] [%u]:",
ap->rerr.rerr_flags & RERR_NODELETE ? "[D]" : "",
- ap->rerr.rerr_dc, length);
+ ap->rerr.rerr_dc, length));
trunc = n - (i/j);
for (; i -= j >= 0; ++dp6) {
- printf(" {%s}(%ld)", ip6addr_string(&dp6->u_da),
- (unsigned long)EXTRACT_32BITS(&dp6->u_ds));
+ ND_PRINT((ndo, " {%s}(%ld)", ip6addr_string(&dp6->u_da),
+ (unsigned long)EXTRACT_32BITS(&dp6->u_ds)));
}
if (trunc)
- printf("[|rerr]");
+ ND_PRINT((ndo, "[|rerr]"));
#else
- printf(" rerr %u", length);
+ ND_PRINT((ndo, " rerr %u", length));
#endif
}
static void
#ifdef INET6
-aodv_v6_draft_01_rreq(const union aodv *ap, const u_char *dat, u_int length)
+aodv_v6_draft_01_rreq(netdissect_options *ndo,
+ const union aodv *ap, const u_char *dat, u_int length)
#else
-aodv_v6_draft_01_rreq(const union aodv *ap _U_, const u_char *dat _U_,
+aodv_v6_draft_01_rreq(netdissect_options *ndo,
+ const union aodv *ap _U_, const u_char *dat _U_,
u_int length)
#endif
{
#ifdef INET6
u_int i;
- if (snapend < dat) {
- printf(" [|aodv]");
+ if (ndo->ndo_snapend < dat) {
+ ND_PRINT((ndo, " [|aodv]"));
return;
}
- i = min(length, (u_int)(snapend - dat));
+ i = min(length, (u_int)(ndo->ndo_snapend - dat));
if (i < sizeof(ap->rreq6_draft_01)) {
- printf(" [|rreq6]");
+ ND_PRINT((ndo, " [|rreq6]"));
return;
}
i -= sizeof(ap->rreq6_draft_01);
- printf(" rreq %u %s%s%s%s%shops %u id 0x%08lx\n"
+ ND_PRINT((ndo, " rreq %u %s%s%s%s%shops %u id 0x%08lx\n"
"\tdst %s seq %lu src %s seq %lu", length,
ap->rreq6_draft_01.rreq_type & RREQ_JOIN ? "[J]" : "",
ap->rreq6_draft_01.rreq_type & RREQ_REPAIR ? "[R]" : "",
ip6addr_string(&ap->rreq6_draft_01.rreq_da),
(unsigned long)EXTRACT_32BITS(&ap->rreq6_draft_01.rreq_ds),
ip6addr_string(&ap->rreq6_draft_01.rreq_oa),
- (unsigned long)EXTRACT_32BITS(&ap->rreq6_draft_01.rreq_os));
+ (unsigned long)EXTRACT_32BITS(&ap->rreq6_draft_01.rreq_os)));
if (i >= sizeof(struct aodv_ext))
- aodv_extension((void *)(&ap->rreq6_draft_01 + 1), i);
+ aodv_extension(ndo, (void *)(&ap->rreq6_draft_01 + 1), i);
#else
- printf(" rreq %u", length);
+ ND_PRINT((ndo, " rreq %u", length));
#endif
}
static void
#ifdef INET6
-aodv_v6_draft_01_rrep(const union aodv *ap, const u_char *dat, u_int length)
+aodv_v6_draft_01_rrep(netdissect_options *ndo,
+ const union aodv *ap, const u_char *dat, u_int length)
#else
-aodv_v6_draft_01_rrep(const union aodv *ap _U_, const u_char *dat _U_,
+aodv_v6_draft_01_rrep(netdissect_options *ndo,
+ const union aodv *ap _U_, const u_char *dat _U_,
u_int length)
#endif
{
#ifdef INET6
u_int i;
- if (snapend < dat) {
- printf(" [|aodv]");
+ if (ndo->ndo_snapend < dat) {
+ ND_PRINT((ndo, " [|aodv]"));
return;
}
- i = min(length, (u_int)(snapend - dat));
+ i = min(length, (u_int)(ndo->ndo_snapend - dat));
if (i < sizeof(ap->rrep6_draft_01)) {
- printf(" [|rrep6]");
+ ND_PRINT((ndo, " [|rrep6]"));
return;
}
i -= sizeof(ap->rrep6_draft_01);
- printf(" rrep %u %s%sprefix %u hops %u\n"
+ ND_PRINT((ndo, " rrep %u %s%sprefix %u hops %u\n"
"\tdst %s dseq %lu src %s %lu ms", length,
ap->rrep6_draft_01.rrep_type & RREP_REPAIR ? "[R]" : "",
ap->rrep6_draft_01.rrep_type & RREP_ACK ? "[A] " : " ",
ip6addr_string(&ap->rrep6_draft_01.rrep_da),
(unsigned long)EXTRACT_32BITS(&ap->rrep6_draft_01.rrep_ds),
ip6addr_string(&ap->rrep6_draft_01.rrep_oa),
- (unsigned long)EXTRACT_32BITS(&ap->rrep6_draft_01.rrep_life));
+ (unsigned long)EXTRACT_32BITS(&ap->rrep6_draft_01.rrep_life)));
if (i >= sizeof(struct aodv_ext))
- aodv_extension((void *)(&ap->rrep6_draft_01 + 1), i);
+ aodv_extension(ndo, (void *)(&ap->rrep6_draft_01 + 1), i);
#else
- printf(" rrep %u", length);
+ ND_PRINT((ndo, " rrep %u", length));
#endif
}
static void
#ifdef INET6
-aodv_v6_draft_01_rerr(const union aodv *ap, u_int length)
+aodv_v6_draft_01_rerr(netdissect_options *ndo,
+ const union aodv *ap, u_int length)
#else
-aodv_v6_draft_01_rerr(const union aodv *ap _U_, u_int length)
+aodv_v6_draft_01_rerr(netdissect_options *ndo,
+ const union aodv *ap _U_, u_int length)
#endif
{
#ifdef INET6
j = sizeof(ap->rerr.r.dest6_draft_01[0]);
dp6 = &ap->rerr.r.dest6_draft_01[0];
n = ap->rerr.rerr_dc * j;
- printf(" rerr %s [items %u] [%u]:",
+ ND_PRINT((ndo, " rerr %s [items %u] [%u]:",
ap->rerr.rerr_flags & RERR_NODELETE ? "[D]" : "",
- ap->rerr.rerr_dc, length);
+ ap->rerr.rerr_dc, length));
trunc = n - (i/j);
for (; i -= j >= 0; ++dp6) {
- printf(" {%s}(%ld)", ip6addr_string(&dp6->u_da),
- (unsigned long)EXTRACT_32BITS(&dp6->u_ds));
+ ND_PRINT((ndo, " {%s}(%ld)", ip6addr_string(&dp6->u_da),
+ (unsigned long)EXTRACT_32BITS(&dp6->u_ds)));
}
if (trunc)
- printf("[|rerr]");
+ ND_PRINT((ndo, "[|rerr]"));
#else
- printf(" rerr %u", length);
+ ND_PRINT((ndo, " rerr %u", length));
#endif
}
void
-aodv_print(const u_char *dat, u_int length, int is_ip6)
+aodv_print(netdissect_options *ndo,
+ const u_char *dat, u_int length, int is_ip6)
{
const union aodv *ap;
ap = (union aodv *)dat;
- if (snapend < dat) {
- printf(" [|aodv]");
+ if (ndo->ndo_snapend < dat) {
+ ND_PRINT((ndo, " [|aodv]"));
return;
}
- if (min(length, (u_int)(snapend - dat)) < sizeof(ap->rrep_ack)) {
- printf(" [|aodv]");
+ if (min(length, (u_int)(ndo->ndo_snapend - dat)) < sizeof(ap->rrep_ack)) {
+ ND_PRINT((ndo, " [|aodv]"));
return;
}
- printf(" aodv");
+ ND_PRINT((ndo, " aodv"));
switch (ap->rerr.rerr_type) {
case AODV_RREQ:
if (is_ip6)
- aodv_v6_rreq(ap, dat, length);
+ aodv_v6_rreq(ndo, ap, dat, length);
else
- aodv_rreq(ap, dat, length);
+ aodv_rreq(ndo, ap, dat, length);
break;
case AODV_RREP:
if (is_ip6)
- aodv_v6_rrep(ap, dat, length);
+ aodv_v6_rrep(ndo, ap, dat, length);
else
- aodv_rrep(ap, dat, length);
+ aodv_rrep(ndo, ap, dat, length);
break;
case AODV_RERR:
if (is_ip6)
- aodv_v6_rerr(ap, length);
+ aodv_v6_rerr(ndo, ap, length);
else
- aodv_rerr(ap, dat, length);
+ aodv_rerr(ndo, ap, dat, length);
break;
case AODV_RREP_ACK:
- printf(" rrep-ack %u", length);
+ ND_PRINT((ndo, " rrep-ack %u", length));
break;
case AODV_V6_DRAFT_01_RREQ:
- aodv_v6_draft_01_rreq(ap, dat, length);
+ aodv_v6_draft_01_rreq(ndo, ap, dat, length);
break;
case AODV_V6_DRAFT_01_RREP:
- aodv_v6_draft_01_rrep(ap, dat, length);
+ aodv_v6_draft_01_rrep(ndo, ap, dat, length);
break;
case AODV_V6_DRAFT_01_RERR:
- aodv_v6_draft_01_rerr(ap, length);
+ aodv_v6_draft_01_rerr(ndo, ap, length);
break;
case AODV_V6_DRAFT_01_RREP_ACK:
- printf(" rrep-ack %u", length);
+ ND_PRINT((ndo, " rrep-ack %u", length));
break;
default:
- printf(" %u %u", ap->rreq.rreq_type, length);
+ ND_PRINT((ndo, " %u %u", ap->rreq.rreq_type, length));
}
}
return (cov > len)? len : cov;
}
-static int dccp_cksum(const struct ip *ip,
+static int dccp_cksum(netdissect_options *ndo, const struct ip *ip,
const struct dccp_hdr *dh, u_int len)
{
- return nextproto4_cksum(ip, (const u_int8_t *)(void *)dh, len,
+ return nextproto4_cksum(ndo, ip, (const u_int8_t *)(void *)dh, len,
dccp_csum_coverage(dh, len), IPPROTO_DCCP);
}
dccp_sum = EXTRACT_16BITS(&dh->dccph_checksum);
ND_PRINT((ndo, "cksum 0x%04x ", dccp_sum));
if (IP_V(ip) == 4)
- sum = dccp_cksum(ip, dh, len);
+ sum = dccp_cksum(ndo, ip, dh, len);
#ifdef INET6
else if (IP_V(ip) == 6)
sum = dccp6_cksum(ip6, dh, len);
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*/
+#define NETDISSECT_REWORKED
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <tcpdump-stdinc.h>
-#include <stdio.h>
-#include <stdlib.h>
#include <string.h>
#include "addrtoname.h"
* print the recorded route in an IP RR, LSRR or SSRR option.
*/
static void
-ip_printroute(register const u_char *cp, u_int length)
+ip_printroute(netdissect_options *ndo,
+ register const u_char *cp, u_int length)
{
register u_int ptr;
register u_int len;
if (length < 3) {
- printf(" [bad length %u]", length);
+ ND_PRINT((ndo, " [bad length %u]", length));
return;
}
if ((length + 1) & 3)
- printf(" [bad length %u]", length);
+ ND_PRINT((ndo, " [bad length %u]", length));
ptr = cp[2] - 1;
if (ptr < 3 || ((ptr + 1) & 3) || ptr > length + 1)
- printf(" [bad ptr %u]", cp[2]);
+ ND_PRINT((ndo, " [bad ptr %u]", cp[2]));
for (len = 3; len < length; len += 4) {
- printf(" %s", ipaddr_string(&cp[len]));
- if (ptr > len)
- printf(",");
+ ND_PRINT((ndo, " %s", ipaddr_string(&cp[len])));
+ if (ptr > len)
+ ND_PRINT((ndo, ","));
}
}
* calculation.
*/
static u_int32_t
-ip_finddst(const struct ip *ip)
+ip_finddst(netdissect_options *ndo,
+ const struct ip *ip)
{
int length;
int len;
for (; length > 0; cp += len, length -= len) {
int tt;
- TCHECK(*cp);
+ ND_TCHECK(*cp);
tt = *cp;
if (tt == IPOPT_EOL)
break;
else if (tt == IPOPT_NOP)
len = 1;
else {
- TCHECK(cp[1]);
+ ND_TCHECK(cp[1]);
len = cp[1];
if (len < 2)
break;
}
- TCHECK2(*cp, len);
+ ND_TCHECK2(*cp, len);
switch (tt) {
case IPOPT_SSRR:
* Compute a V4-style checksum by building a pseudoheader.
*/
int
-nextproto4_cksum(const struct ip *ip, const u_int8_t *data,
- u_int len, u_int covlen, u_int next_proto)
+nextproto4_cksum(netdissect_options *ndo,
+ const struct ip *ip, const u_int8_t *data,
+ u_int len, u_int covlen, u_int next_proto)
{
struct phdr {
u_int32_t src;
if (IP_HL(ip) == 5)
UNALIGNED_MEMCPY(&ph.dst, &ip->ip_dst.s_addr, sizeof(u_int32_t));
else
- ph.dst = ip_finddst(ip);
+ ph.dst = ip_finddst(ndo, ip);
vec[0].ptr = (const u_int8_t *)(void *)&ph;
vec[0].len = sizeof(ph);
}
static void
-ip_printts(register const u_char *cp, u_int length)
+ip_printts(netdissect_options *ndo,
+ register const u_char *cp, u_int length)
{
register u_int ptr;
register u_int len;
const char *type;
if (length < 4) {
- printf("[bad length %u]", length);
+ ND_PRINT((ndo, "[bad length %u]", length));
return;
}
- printf(" TS{");
+ ND_PRINT((ndo, " TS{"));
hoplen = ((cp[3]&0xF) != IPOPT_TS_TSONLY) ? 8 : 4;
if ((length - 4) & (hoplen-1))
- printf("[bad length %u]", length);
+ ND_PRINT((ndo, "[bad length %u]", length));
ptr = cp[2] - 1;
len = 0;
if (ptr < 4 || ((ptr - 4) & (hoplen-1)) || ptr > length + 1)
- printf("[bad ptr %u]", cp[2]);
+ ND_PRINT((ndo, "[bad ptr %u]", cp[2]));
switch (cp[3]&0xF) {
case IPOPT_TS_TSONLY:
- printf("TSONLY");
+ ND_PRINT((ndo, "TSONLY"));
break;
case IPOPT_TS_TSANDADDR:
- printf("TS+ADDR");
+ ND_PRINT((ndo, "TS+ADDR"));
break;
/*
* prespecified should really be 3, but some ones might send 2
*/
case 2:
- printf("PRESPEC2.0");
+ ND_PRINT((ndo, "PRESPEC2.0"));
break;
case 3: /* IPOPT_TS_PRESPEC */
- printf("PRESPEC");
+ ND_PRINT((ndo, "PRESPEC"));
break;
default:
- printf("[bad ts type %d]", cp[3]&0xF);
+ ND_PRINT((ndo, "[bad ts type %d]", cp[3]&0xF));
goto done;
}
for (len = 4; len < length; len += hoplen) {
if (ptr == len)
type = " ^ ";
- printf("%s%d@%s", type, EXTRACT_32BITS(&cp[len+hoplen-4]),
- hoplen!=8 ? "" : ipaddr_string(&cp[len]));
+ ND_PRINT((ndo, "%s%d@%s", type, EXTRACT_32BITS(&cp[len+hoplen-4]),
+ hoplen!=8 ? "" : ipaddr_string(&cp[len])));
type = " ";
}
done:
- printf("%s", ptr == len ? " ^ " : "");
+ ND_PRINT((ndo, "%s", ptr == len ? " ^ " : ""));
if (cp[3]>>4)
- printf(" [%d hops not recorded]} ", cp[3]>>4);
+ ND_PRINT((ndo, " [%d hops not recorded]} ", cp[3]>>4));
else
- printf("}");
+ ND_PRINT((ndo, "}"));
}
/*
* print IP options.
*/
static void
-ip_optprint(register const u_char *cp, u_int length)
+ip_optprint(netdissect_options *ndo,
+ register const u_char *cp, u_int length)
{
register u_int option_len;
const char *sep = "";
for (; length > 0; cp += option_len, length -= option_len) {
u_int option_code;
- printf("%s", sep);
+ ND_PRINT((ndo, "%s", sep));
sep = ",";
- TCHECK(*cp);
+ ND_TCHECK(*cp);
option_code = *cp;
- printf("%s",
- tok2str(ip_option_values,"unknown %u",option_code));
+ ND_PRINT((ndo, "%s",
+ tok2str(ip_option_values,"unknown %u",option_code)));
if (option_code == IPOPT_NOP ||
option_code == IPOPT_EOL)
option_len = 1;
else {
- TCHECK(cp[1]);
+ ND_TCHECK(cp[1]);
option_len = cp[1];
if (option_len < 2) {
- printf(" [bad length %u]", option_len);
+ ND_PRINT((ndo, " [bad length %u]", option_len));
return;
}
}
if (option_len > length) {
- printf(" [bad length %u]", option_len);
+ ND_PRINT((ndo, " [bad length %u]", option_len));
return;
}
- TCHECK2(*cp, option_len);
+ ND_TCHECK2(*cp, option_len);
switch (option_code) {
case IPOPT_EOL:
return;
case IPOPT_TS:
- ip_printts(cp, option_len);
+ ip_printts(ndo, cp, option_len);
break;
case IPOPT_RR: /* fall through */
case IPOPT_SSRR:
case IPOPT_LSRR:
- ip_printroute(cp, option_len);
+ ip_printroute(ndo, cp, option_len);
break;
case IPOPT_RA:
if (option_len < 4) {
- printf(" [bad length %u]", option_len);
+ ND_PRINT((ndo, " [bad length %u]", option_len));
break;
}
- TCHECK(cp[3]);
- if (EXTRACT_16BITS(&cp[2]) != 0)
- printf(" value %u", EXTRACT_16BITS(&cp[2]));
+ ND_TCHECK(cp[3]);
+ if (EXTRACT_16BITS(&cp[2]) != 0)
+ ND_PRINT((ndo, " value %u", EXTRACT_16BITS(&cp[2])));
break;
case IPOPT_NOP: /* nothing to print - fall through */
return;
trunc:
- printf("%s", tstr);
+ ND_PRINT((ndo, "%s", tstr));
}
#define IP_RES 0x8000
case IPPROTO_AH:
ipds->nh = *ipds->cp;
- ipds->advance = ah_print(gndo, ipds->cp);
+ ipds->advance = ah_print(ndo, ipds->cp);
if (ipds->advance <= 0)
break;
ipds->cp += ipds->advance;
}
case IPPROTO_SCTP:
- sctp_print(ipds->cp, (const u_char *)ipds->ip, ipds->len);
+ sctp_print(ndo, ipds->cp, (const u_char *)ipds->ip, ipds->len);
break;
case IPPROTO_DCCP:
case IPPROTO_IPV4:
/* DVMRP multicast tunnel (ip-in-ip encapsulation) */
ip_print(ndo, ipds->cp, ipds->len);
- if (! vflag) {
+ if (! ndo->ndo_vflag) {
ND_PRINT((ndo, " (ipip-proto-4)"));
return;
}
break;
case IPPROTO_VRRP:
- if (packettype == PT_CARP) {
- if (vflag)
- (void)printf("carp %s > %s: ",
+ if (ndo->ndo_packettype == PT_CARP) {
+ if (ndo->ndo_vflag)
+ ND_PRINT((ndo, "carp %s > %s: ",
ipaddr_string(&ipds->ip->ip_src),
- ipaddr_string(&ipds->ip->ip_dst));
+ ipaddr_string(&ipds->ip->ip_dst)));
carp_print(ndo, ipds->cp, ipds->len, ipds->ip->ip_ttl);
} else {
- if (vflag)
- (void)printf("vrrp %s > %s: ",
+ if (ndo->ndo_vflag)
+ ND_PRINT((ndo, "vrrp %s > %s: ",
ipaddr_string(&ipds->ip->ip_src),
- ipaddr_string(&ipds->ip->ip_dst));
+ ipaddr_string(&ipds->ip->ip_dst)));
vrrp_print(ndo, ipds->cp, ipds->len,
(const u_char *)ipds->ip, ipds->ip->ip_ttl);
}
ipds->ip = (const struct ip *)bp;
if (IP_V(ipds->ip) != 4) { /* print version if != 4 */
- printf("IP%u ", IP_V(ipds->ip));
+ ND_PRINT((ndo, "IP%u ", IP_V(ipds->ip)));
if (IP_V(ipds->ip) == 6)
- printf(", wrong link-layer encapsulation");
+ ND_PRINT((ndo, ", wrong link-layer encapsulation"));
}
- else if (!eflag)
- printf("IP ");
+ else if (!ndo->ndo_eflag)
+ ND_PRINT((ndo, "IP "));
if ((u_char *)(ipds->ip + 1) > ndo->ndo_snapend) {
- printf("%s", tstr);
+ ND_PRINT((ndo, "%s", tstr));
return;
}
if (length < sizeof (struct ip)) {
- (void)printf("truncated-ip %u", length);
+ ND_PRINT((ndo, "truncated-ip %u", length));
return;
}
hlen = IP_HL(ipds->ip) * 4;
if (hlen < sizeof (struct ip)) {
- (void)printf("bad-hlen %u", hlen);
+ ND_PRINT((ndo, "bad-hlen %u", hlen));
return;
}
ipds->len = EXTRACT_16BITS(&ipds->ip->ip_len);
if (length < ipds->len)
- (void)printf("truncated-ip - %u bytes missing! ",
- ipds->len - length);
+ ND_PRINT((ndo, "truncated-ip - %u bytes missing! ",
+ ipds->len - length));
if (ipds->len < hlen) {
#ifdef GUESS_TSO
if (ipds->len) {
- (void)printf("bad-len %u", ipds->len);
+ ND_PRINT((ndo, "bad-len %u", ipds->len));
return;
}
else {
ipds->len = length;
}
#else
- (void)printf("bad-len %u", ipds->len);
+ ND_PRINT((ndo, "bad-len %u", ipds->len));
return;
#endif /* GUESS_TSO */
}
ipds->off = EXTRACT_16BITS(&ipds->ip->ip_off);
- if (vflag) {
- (void)printf("(tos 0x%x", (int)ipds->ip->ip_tos);
+ if (ndo->ndo_vflag) {
+ ND_PRINT((ndo, "(tos 0x%x", (int)ipds->ip->ip_tos));
/* ECN bits */
if (ipds->ip->ip_tos & 0x03) {
switch (ipds->ip->ip_tos & 0x03) {
case 1:
- (void)printf(",ECT(1)");
+ ND_PRINT((ndo, ",ECT(1)"));
break;
case 2:
- (void)printf(",ECT(0)");
+ ND_PRINT((ndo, ",ECT(0)"));
break;
case 3:
- (void)printf(",CE");
+ ND_PRINT((ndo, ",CE"));
}
}
if (ipds->ip->ip_ttl >= 1)
- (void)printf(", ttl %u", ipds->ip->ip_ttl);
+ ND_PRINT((ndo, ", ttl %u", ipds->ip->ip_ttl));
/*
* for the firewall guys, print id, offset.
* For unfragmented datagrams, note the don't fragment flag.
*/
- (void)printf(", id %u, offset %u, flags [%s], proto %s (%u)",
+ ND_PRINT((ndo, ", id %u, offset %u, flags [%s], proto %s (%u)",
EXTRACT_16BITS(&ipds->ip->ip_id),
(ipds->off & 0x1fff) * 8,
bittok2str(ip_frag_values, "none", ipds->off&0xe000),
tok2str(ipproto_values,"unknown",ipds->ip->ip_p),
- ipds->ip->ip_p);
+ ipds->ip->ip_p));
- (void)printf(", length %u", EXTRACT_16BITS(&ipds->ip->ip_len));
+ ND_PRINT((ndo, ", length %u", EXTRACT_16BITS(&ipds->ip->ip_len)));
if ((hlen - sizeof(struct ip)) > 0) {
- printf(", options (");
- ip_optprint((u_char *)(ipds->ip + 1), hlen - sizeof(struct ip));
- printf(")");
+ ND_PRINT((ndo, ", options ("));
+ ip_optprint(ndo, (u_char *)(ipds->ip + 1), hlen - sizeof(struct ip));
+ ND_PRINT((ndo, ")"));
}
- if (!Kflag && (u_char *)ipds->ip + hlen <= ndo->ndo_snapend) {
+ if (!ndo->ndo_Kflag && (u_char *)ipds->ip + hlen <= ndo->ndo_snapend) {
vec[0].ptr = (const u_int8_t *)(void *)ipds->ip;
vec[0].len = hlen;
sum = in_cksum(vec, 1);
if (sum != 0) {
ip_sum = EXTRACT_16BITS(&ipds->ip->ip_sum);
- (void)printf(", bad cksum %x (->%x)!", ip_sum,
- in_cksum_shouldbe(ip_sum, sum));
+ ND_PRINT((ndo, ", bad cksum %x (->%x)!", ip_sum,
+ in_cksum_shouldbe(ip_sum, sum)));
}
}
- printf(")\n ");
+ ND_PRINT((ndo, ")\n "));
}
/*
if (ipds->nh != IPPROTO_TCP && ipds->nh != IPPROTO_UDP &&
ipds->nh != IPPROTO_SCTP && ipds->nh != IPPROTO_DCCP) {
- (void)printf("%s > %s: ",
+ ND_PRINT((ndo, "%s > %s: ",
ipaddr_string(&ipds->ip->ip_src),
- ipaddr_string(&ipds->ip->ip_dst));
+ ipaddr_string(&ipds->ip->ip_dst)));
}
ip_print_demux(ndo, ipds);
} else {
/* Ultra quiet now means that all this stuff should be suppressed */
- if (qflag > 1) return;
+ if (ndo->ndo_qflag > 1) return;
/*
* if this isn't the first frag, we're missing the
* next level protocol header. print the ip addr
* and the protocol.
*/
- if (ipds->off & 0x1fff) {
- (void)printf("%s > %s:", ipaddr_string(&ipds->ip->ip_src),
- ipaddr_string(&ipds->ip->ip_dst));
- if (!ndo->ndo_nflag && (proto = getprotobynumber(ipds->ip->ip_p)) != NULL)
- (void)printf(" %s", proto->p_name);
- else
- (void)printf(" ip-proto-%d", ipds->ip->ip_p);
- }
+ if (ipds->off & 0x1fff) {
+ ND_PRINT((ndo, "%s > %s:", ipaddr_string(&ipds->ip->ip_src),
+ ipaddr_string(&ipds->ip->ip_dst)));
+ if (!ndo->ndo_nflag && (proto = getprotobynumber(ipds->ip->ip_p)) != NULL)
+ ND_PRINT((ndo, " %s", proto->p_name));
+ else
+ ND_PRINT((ndo, " ip-proto-%d", ipds->ip->ip_p));
+ }
}
}
struct ip hdr;
if (length < 4) {
- (void)printf("truncated-ip %d", length);
+ ND_PRINT((ndo, "truncated-ip %d", length));
return;
}
memcpy (&hdr, bp, 4);
return;
#endif
default:
- (void)printf("unknown ip %d", IP_V(&hdr));
+ ND_PRINT((ndo, "unknown ip %d", IP_V(&hdr)));
return;
}
}
nh = *cp;
break;
case IPPROTO_SCTP:
- sctp_print(cp, (const u_char *)ip6, len);
+ sctp_print(ndo, cp, (const u_char *)ip6, len);
return;
case IPPROTO_DCCP:
dccp_print(ndo, cp, (const u_char *)ip6, len);
* SUCH DAMAGE.
*/
+#define NETDISSECT_REWORKED
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <tcpdump-stdinc.h>
-#include <assert.h>
-
-#include <stdio.h>
-#include <string.h>
-
#include "interface.h"
#include "addrtoname.h"
#include "extract.h" /* must come after interface.h */
return 0;
}
-void sctp_print(const u_char *bp, /* beginning of sctp packet */
- const u_char *bp2, /* beginning of enclosing */
- u_int sctpPacketLength) /* ip packet */
+void sctp_print(netdissect_options *ndo,
+ const u_char *bp, /* beginning of sctp packet */
+ const u_char *bp2, /* beginning of enclosing */
+ u_int sctpPacketLength) /* ip packet */
{
const struct sctpHeader *sctpPktHdr;
const struct ip *ip;
sctpPktHdr = (const struct sctpHeader*) bp;
endPacketPtr = (const u_char*)sctpPktHdr+sctpPacketLength;
- if( (u_long) endPacketPtr > (u_long) snapend)
- endPacketPtr = (const void *) snapend;
+ if( (u_long) endPacketPtr > (u_long) ndo->ndo_snapend)
+ endPacketPtr = (const void *) ndo->ndo_snapend;
ip = (struct ip *)bp2;
#ifdef INET6
if (IP_V(ip) == 6)
else
ip6 = NULL;
#endif /*INET6*/
- TCHECK(*sctpPktHdr);
+ ND_TCHECK(*sctpPktHdr);
if (sctpPacketLength < sizeof(struct sctpHeader))
{
- (void)printf("truncated-sctp - %ld bytes missing!",
- (long)sctpPacketLength-sizeof(struct sctpHeader));
+ ND_PRINT((ndo, "truncated-sctp - %ld bytes missing!",
+ (long)sctpPacketLength-sizeof(struct sctpHeader)));
return;
}
#ifdef INET6
if (ip6) {
- (void)printf("%s.%d > %s.%d: sctp",
+ ND_PRINT((ndo, "%s.%d > %s.%d: sctp",
ip6addr_string(&ip6->ip6_src),
sourcePort,
ip6addr_string(&ip6->ip6_dst),
- destPort);
+ destPort));
} else
#endif /*INET6*/
{
- (void)printf("%s.%d > %s.%d: sctp",
+ ND_PRINT((ndo, "%s.%d > %s.%d: sctp",
ipaddr_string(&ip->ip_src),
sourcePort,
ipaddr_string(&ip->ip_dst),
- destPort);
+ destPort));
}
fflush(stdout);
if (isForCES_port(sourcePort)) {
- printf("[%s]", tok2str(ForCES_channels, NULL, sourcePort));
+ ND_PRINT((ndo, "[%s]", tok2str(ForCES_channels, NULL, sourcePort)));
isforces = 1;
}
if (isForCES_port(destPort)) {
- printf("[%s]", tok2str(ForCES_channels, NULL, destPort));
+ ND_PRINT((ndo, "[%s]", tok2str(ForCES_channels, NULL, destPort)));
isforces = 1;
}
- if (vflag >= 2)
+ if (ndo->ndo_vflag >= 2)
sep = "\n\t";
else
sep = " (";
const u_char *chunkEnd;
u_int16_t align;
- TCHECK(*chunkDescPtr);
+ ND_TCHECK(*chunkDescPtr);
chunkLength = EXTRACT_16BITS(&chunkDescPtr->chunkLength);
if (chunkLength < sizeof(*chunkDescPtr)) {
- printf("%s%d) [Bad chunk length %u]", sep, chunkCount+1, chunkLength);
- break;
+ ND_PRINT((ndo, "%s%d) [Bad chunk length %u]", sep, chunkCount+1, chunkLength));
+ break;
}
- TCHECK2(*((u_int8_t *)chunkDescPtr), chunkLength);
+ ND_TCHECK2(*((u_int8_t *)chunkDescPtr), chunkLength);
chunkEnd = ((const u_char*)chunkDescPtr + chunkLength);
align=chunkLength % 4;
nextChunk = (const void *) (chunkEnd + align);
- printf("%s%d) ", sep, chunkCount+1);
+ ND_PRINT((ndo, "%s%d) ", sep, chunkCount+1));
switch (chunkDescPtr->chunkID)
{
case SCTP_DATA :
{
const struct sctpDataPart *dataHdrPtr;
- printf("[DATA] ");
+ ND_PRINT((ndo, "[DATA] "));
if ((chunkDescPtr->chunkFlg & SCTP_DATA_UNORDERED)
== SCTP_DATA_UNORDERED)
- printf("(U)");
+ ND_PRINT((ndo, "(U)"));
if ((chunkDescPtr->chunkFlg & SCTP_DATA_FIRST_FRAG)
== SCTP_DATA_FIRST_FRAG)
- printf("(B)");
+ ND_PRINT((ndo, "(B)"));
if ((chunkDescPtr->chunkFlg & SCTP_DATA_LAST_FRAG)
== SCTP_DATA_LAST_FRAG)
- printf("(E)");
+ ND_PRINT((ndo, "(E)"));
if( ((chunkDescPtr->chunkFlg & SCTP_DATA_UNORDERED)
== SCTP_DATA_UNORDERED)
||
((chunkDescPtr->chunkFlg & SCTP_DATA_LAST_FRAG)
== SCTP_DATA_LAST_FRAG) )
- printf(" ");
+ ND_PRINT((ndo, " "));
dataHdrPtr=(const struct sctpDataPart*)(chunkDescPtr+1);
- printf("[TSN: %u] ", EXTRACT_32BITS(&dataHdrPtr->TSN));
- printf("[SID: %u] ", EXTRACT_16BITS(&dataHdrPtr->streamId));
- printf("[SSEQ %u] ", EXTRACT_16BITS(&dataHdrPtr->sequence));
- printf("[PPID 0x%x] ", EXTRACT_32BITS(&dataHdrPtr->payloadtype));
+ ND_PRINT((ndo, "[TSN: %u] ", EXTRACT_32BITS(&dataHdrPtr->TSN)));
+ ND_PRINT((ndo, "[SID: %u] ", EXTRACT_16BITS(&dataHdrPtr->streamId)));
+ ND_PRINT((ndo, "[SSEQ %u] ", EXTRACT_16BITS(&dataHdrPtr->sequence)));
+ ND_PRINT((ndo, "[PPID 0x%x] ", EXTRACT_32BITS(&dataHdrPtr->payloadtype)));
fflush(stdout);
if (isforces) {
const u_char *payloadPtr;
sizeof(struct sctpDataPart)+
sizeof(struct sctpChunkDesc)+1) {
/* Less than 1 byte of chunk payload */
- printf("bogus ForCES chunk length %u]",
- EXTRACT_16BITS(&chunkDescPtr->chunkLength));
+ ND_PRINT((ndo, "bogus ForCES chunk length %u]",
+ EXTRACT_16BITS(&chunkDescPtr->chunkLength)));
return;
}
forces_print(payloadPtr, EXTRACT_16BITS(&chunkDescPtr->chunkLength)- chunksize);
- } else if (vflag >= 2) { /* if verbose output is specified */
+ } else if (ndo->ndo_vflag >= 2) { /* if verbose output is specified */
/* at the command line */
const u_char *payloadPtr;
- printf("[Payload");
+ ND_PRINT((ndo, "[Payload"));
- if (!suppress_default_print) {
+ if (!ndo->ndo_suppress_default_print) {
payloadPtr = (const u_char *) (++dataHdrPtr);
- printf(":");
+ ND_PRINT((ndo, ":"));
if (EXTRACT_16BITS(&chunkDescPtr->chunkLength) <
sizeof(struct sctpDataPart)+
sizeof(struct sctpChunkDesc)+1) {
/* Less than 1 byte of chunk payload */
- printf("bogus chunk length %u]",
- EXTRACT_16BITS(&chunkDescPtr->chunkLength));
+ ND_PRINT((ndo, "bogus chunk length %u]",
+ EXTRACT_16BITS(&chunkDescPtr->chunkLength)));
return;
}
default_print(payloadPtr,
(sizeof(struct sctpDataPart)+
sizeof(struct sctpChunkDesc)));
} else
- printf("]");
+ ND_PRINT((ndo, "]"));
}
break;
}
{
const struct sctpInitiation *init;
- printf("[INIT] ");
+ ND_PRINT((ndo, "[INIT] "));
init=(const struct sctpInitiation*)(chunkDescPtr+1);
- printf("[init tag: %u] ", EXTRACT_32BITS(&init->initTag));
- printf("[rwnd: %u] ", EXTRACT_32BITS(&init->rcvWindowCredit));
- printf("[OS: %u] ", EXTRACT_16BITS(&init->NumPreopenStreams));
- printf("[MIS: %u] ", EXTRACT_16BITS(&init->MaxInboundStreams));
- printf("[init TSN: %u] ", EXTRACT_32BITS(&init->initialTSN));
+ ND_PRINT((ndo, "[init tag: %u] ", EXTRACT_32BITS(&init->initTag)));
+ ND_PRINT((ndo, "[rwnd: %u] ", EXTRACT_32BITS(&init->rcvWindowCredit)));
+ ND_PRINT((ndo, "[OS: %u] ", EXTRACT_16BITS(&init->NumPreopenStreams)));
+ ND_PRINT((ndo, "[MIS: %u] ", EXTRACT_16BITS(&init->MaxInboundStreams)));
+ ND_PRINT((ndo, "[init TSN: %u] ", EXTRACT_32BITS(&init->initialTSN)));
#if(0) /* ALC you can add code for optional params here */
if( (init+1) < chunkEnd )
- printf(" @@@@@ UNFINISHED @@@@@@%s\n",
- "Optional params present, but not printed.");
+ ND_PRINT((ndo, " @@@@@ UNFINISHED @@@@@@%s\n",
+ "Optional params present, but not printed."));
#endif
break;
}
{
const struct sctpInitiation *init;
- printf("[INIT ACK] ");
+ ND_PRINT((ndo, "[INIT ACK] "));
init=(const struct sctpInitiation*)(chunkDescPtr+1);
- printf("[init tag: %u] ", EXTRACT_32BITS(&init->initTag));
- printf("[rwnd: %u] ", EXTRACT_32BITS(&init->rcvWindowCredit));
- printf("[OS: %u] ", EXTRACT_16BITS(&init->NumPreopenStreams));
- printf("[MIS: %u] ", EXTRACT_16BITS(&init->MaxInboundStreams));
- printf("[init TSN: %u] ", EXTRACT_32BITS(&init->initialTSN));
+ ND_PRINT((ndo, "[init tag: %u] ", EXTRACT_32BITS(&init->initTag)));
+ ND_PRINT((ndo, "[rwnd: %u] ", EXTRACT_32BITS(&init->rcvWindowCredit)));
+ ND_PRINT((ndo, "[OS: %u] ", EXTRACT_16BITS(&init->NumPreopenStreams)));
+ ND_PRINT((ndo, "[MIS: %u] ", EXTRACT_16BITS(&init->MaxInboundStreams)));
+ ND_PRINT((ndo, "[init TSN: %u] ", EXTRACT_32BITS(&init->initialTSN)));
#if(0) /* ALC you can add code for optional params here */
if( (init+1) < chunkEnd )
- printf(" @@@@@ UNFINISHED @@@@@@%s\n",
- "Optional params present, but not printed.");
+ ND_PRINT((ndo, " @@@@@ UNFINISHED @@@@@@%s\n",
+ "Optional params present, but not printed."));
#endif
break;
}
int fragNo, tsnNo;
const u_char *dupTSN;
- printf("[SACK] ");
+ ND_PRINT((ndo, "[SACK] "));
sack=(const struct sctpSelectiveAck*)(chunkDescPtr+1);
- printf("[cum ack %u] ", EXTRACT_32BITS(&sack->highestConseqTSN));
- printf("[a_rwnd %u] ", EXTRACT_32BITS(&sack->updatedRwnd));
- printf("[#gap acks %u] ", EXTRACT_16BITS(&sack->numberOfdesc));
- printf("[#dup tsns %u] ", EXTRACT_16BITS(&sack->numDupTsns));
+ ND_PRINT((ndo, "[cum ack %u] ", EXTRACT_32BITS(&sack->highestConseqTSN)));
+ ND_PRINT((ndo, "[a_rwnd %u] ", EXTRACT_32BITS(&sack->updatedRwnd)));
+ ND_PRINT((ndo, "[#gap acks %u] ", EXTRACT_16BITS(&sack->numberOfdesc)));
+ ND_PRINT((ndo, "[#dup tsns %u] ", EXTRACT_16BITS(&sack->numDupTsns)));
/* print gaps */
fragNo=0;
(const void *)frag < nextChunk && fragNo < EXTRACT_16BITS(&sack->numberOfdesc);
frag++, fragNo++)
- printf("\n\t\t[gap ack block #%d: start = %u, end = %u] ",
+ ND_PRINT((ndo, "\n\t\t[gap ack block #%d: start = %u, end = %u] ",
fragNo+1,
EXTRACT_32BITS(&sack->highestConseqTSN) + EXTRACT_16BITS(&frag->fragmentStart),
- EXTRACT_32BITS(&sack->highestConseqTSN) + EXTRACT_16BITS(&frag->fragmentEnd));
+ EXTRACT_32BITS(&sack->highestConseqTSN) + EXTRACT_16BITS(&frag->fragmentEnd)));
/* print duplicate TSNs */
for (dupTSN = (const u_char *)frag, tsnNo=0;
(const void *) dupTSN < nextChunk && tsnNo<EXTRACT_16BITS(&sack->numDupTsns);
dupTSN += 4, tsnNo++)
- printf("\n\t\t[dup TSN #%u: %u] ", tsnNo+1,
- EXTRACT_32BITS(dupTSN));
+ ND_PRINT((ndo, "\n\t\t[dup TSN #%u: %u] ", tsnNo+1,
+ EXTRACT_32BITS(dupTSN)));
break;
}
case SCTP_HEARTBEAT_REQUEST :
- printf("[HB REQ] ");
+ ND_PRINT((ndo, "[HB REQ] "));
break;
case SCTP_HEARTBEAT_ACK :
- printf("[HB ACK] ");
+ ND_PRINT((ndo, "[HB ACK] "));
break;
case SCTP_ABORT_ASSOCIATION :
- printf("[ABORT] ");
+ ND_PRINT((ndo, "[ABORT] "));
break;
case SCTP_SHUTDOWN :
- printf("[SHUTDOWN] ");
+ ND_PRINT((ndo, "[SHUTDOWN] "));
break;
case SCTP_SHUTDOWN_ACK :
- printf("[SHUTDOWN ACK] ");
+ ND_PRINT((ndo, "[SHUTDOWN ACK] "));
break;
case SCTP_OPERATION_ERR :
- printf("[OP ERR] ");
+ ND_PRINT((ndo, "[OP ERR] "));
break;
case SCTP_COOKIE_ECHO :
- printf("[COOKIE ECHO] ");
+ ND_PRINT((ndo, "[COOKIE ECHO] "));
break;
case SCTP_COOKIE_ACK :
- printf("[COOKIE ACK] ");
+ ND_PRINT((ndo, "[COOKIE ACK] "));
break;
case SCTP_ECN_ECHO :
- printf("[ECN ECHO] ");
+ ND_PRINT((ndo, "[ECN ECHO] "));
break;
case SCTP_ECN_CWR :
- printf("[ECN CWR] ");
+ ND_PRINT((ndo, "[ECN CWR] "));
break;
case SCTP_SHUTDOWN_COMPLETE :
- printf("[SHUTDOWN COMPLETE] ");
+ ND_PRINT((ndo, "[SHUTDOWN COMPLETE] "));
break;
case SCTP_FORWARD_CUM_TSN :
- printf("[FOR CUM TSN] ");
+ ND_PRINT((ndo, "[FOR CUM TSN] "));
break;
case SCTP_RELIABLE_CNTL :
- printf("[REL CTRL] ");
+ ND_PRINT((ndo, "[REL CTRL] "));
break;
case SCTP_RELIABLE_CNTL_ACK :
- printf("[REL CTRL ACK] ");
+ ND_PRINT((ndo, "[REL CTRL ACK] "));
break;
default :
- printf("[Unknown chunk type: 0x%x]", chunkDescPtr->chunkID);
+ ND_PRINT((ndo, "[Unknown chunk type: 0x%x]", chunkDescPtr->chunkID));
return;
}
- if (vflag < 2)
+ if (ndo->ndo_vflag < 2)
sep = ", (";
}
return;
trunc:
- printf("[|sctp]");
- return;
+ ND_PRINT((ndo, "[|sctp]"));
}
register const struct tcphdr *tp,
register u_int len)
{
- return nextproto4_cksum(ip, (const u_int8_t *)tp, len, len,
+ return nextproto4_cksum(gndo, ip, (const u_int8_t *)tp, len, len,
IPPROTO_TCP);
}
return (hdr + len);
}
-static int udp_cksum(register const struct ip *ip,
+static int udp_cksum(netdissect_options *ndo, register const struct ip *ip,
register const struct udphdr *up,
register u_int len)
{
- return nextproto4_cksum(ip, (const u_int8_t *)(void *)up, len, len,
+ return nextproto4_cksum(ndo, ip, (const u_int8_t *)(void *)up, len, len,
IPPROTO_UDP);
}
case PT_AODV:
udpipaddr_print(ndo, ip, sport, dport);
- aodv_print((const u_char *)(up + 1), length,
+ aodv_print(ndo, (const u_char *)(up + 1), length,
#ifdef INET6
ip6 != NULL);
#else
if (udp_sum == 0) {
ND_PRINT((ndo, "[no cksum] "));
} else if (ND_TTEST2(cp[0], length)) {
- sum = udp_cksum(ip, up, length + sizeof(struct udphdr));
+ sum = udp_cksum(ndo, ip, up, length + sizeof(struct udphdr));
if (sum != 0) {
ND_PRINT((ndo, "[bad udp cksum 0x%04x -> 0x%04x!] ",
else if (ISPORT(RIP_PORT))
rip_print(ndo, (const u_char *)(up + 1), length);
else if (ISPORT(AODV_PORT))
- aodv_print((const u_char *)(up + 1), length,
+ aodv_print(ndo, (const u_char *)(up + 1), length,
#ifdef INET6
ip6 != NULL);
#else
}
if (version == 3 && ND_TTEST2(bp[0], len)) {
- u_int16_t cksum = nextproto4_cksum((struct ip *)bp2, bp,
+ u_int16_t cksum = nextproto4_cksum(ndo, (struct ip *)bp2, bp,
len, len, IPPROTO_VRRP);
if (cksum)
ND_PRINT((ndo, ", (bad vrrp cksum %x)",