-/* $OpenBSD: interface.h,v 1.86 2020/08/17 06:29:29 dlg Exp $ */
+/* $OpenBSD: interface.h,v 1.87 2023/02/28 10:04:50 claudio Exp $ */
/*
* Copyright (c) 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997
* WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*
- * @(#) $Id: interface.h,v 1.86 2020/08/17 06:29:29 dlg Exp $ (LBL)
+ * @(#) $Id: interface.h,v 1.87 2023/02/28 10:04:50 claudio Exp $ (LBL)
*/
#ifndef tcpdump_interface_h
extern void bgp_print(const u_char *, int);
extern void decnet_print(const u_char *, u_int, u_int);
extern void default_print(const u_char *, u_int);
-extern void default_print_unaligned(const u_char *, u_int);
extern void dvmrp_print(const u_char *, u_int);
extern void egp_print(const u_char *, u_int, const u_char *);
extern void enc_if_print(u_char *, const struct pcap_pkthdr *, const u_char *);
-/* $OpenBSD: print-isoclns.c,v 1.15 2021/12/01 18:28:46 deraadt Exp $ */
+/* $OpenBSD: print-isoclns.c,v 1.16 2023/02/28 10:04:50 claudio Exp $ */
/*
* Copyright (c) 1992, 1993, 1994, 1995, 1996
/* isis_print(&p, &length); */
printf(" len=%d ", length);
if (caplen > 1)
- default_print_unaligned(p, caplen);
+ default_print(p, caplen);
break;
case NULLNS:
etheraddr_string(edst));
printf(" len=%d ", length);
if (caplen > 1)
- default_print_unaligned(p, caplen);
+ default_print(p, caplen);
break;
}
}
-/* $OpenBSD: print-llc.c,v 1.22 2020/01/24 22:46:37 procter Exp $ */
+/* $OpenBSD: print-llc.c,v 1.23 2023/02/28 10:04:50 claudio Exp $ */
/*
* Copyright (c) 1992, 1993, 1994, 1995, 1996, 1997
printf("%s/%c", m, f);
if (caplen < 6) {
- default_print_unaligned(p, caplen);
+ default_print(p, caplen);
return (0);
}
p += 3;
} else {
char f;
if (caplen < 4) {
- default_print_unaligned(p, caplen);
+ default_print(p, caplen);
return (0);
}
llc.llcis = ntohs(llc.llcis);
-/* $OpenBSD: print-nsh.c,v 1.1 2019/12/03 01:43:33 dlg Exp $ */
+/* $OpenBSD: print-nsh.c,v 1.2 2023/02/28 10:04:50 claudio Exp $ */
/*
* Copyright (c) 2019 David Gwynne <dlg@openbsd.org>
}
if (vflag)
- default_print_unaligned(p, length);
+ default_print(p, l);
return;
trunc:
-/* $OpenBSD: tcpdump.c,v 1.97 2022/07/09 23:24:44 halex Exp $ */
+/* $OpenBSD: tcpdump.c,v 1.98 2023/02/28 10:04:50 claudio Exp $ */
/*
* Copyright (c) 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997
}
}
-/* Like default_print() but data need not be aligned */
-void
-default_print_unaligned(const u_char *cp, u_int length)
-{
- u_int i, s;
- int nshorts;
-
- if (Xflag) {
- /* dump the buffer in `emacs-hexl' style */
- default_print_hexl(cp, length);
- } else if (Aflag) {
- /* dump the text in the buffer */
- default_print_ascii(cp, length);
- } else {
- /* dump the buffer in old tcpdump style */
- nshorts = (u_int) length / sizeof(u_short);
- i = 0;
- while (--nshorts >= 0) {
- if ((i++ % 8) == 0)
- printf("\n\t\t\t");
- s = *cp++;
- printf(" %02x%02x", s, *cp++);
- }
- if (length & 1) {
- if ((i % 8) == 0)
- printf("\n\t\t\t");
- printf(" %02x", *cp);
- }
- }
-}
-
void
default_print(const u_char *bp, u_int length)
{
- const u_short *sp;
u_int i;
int nshorts;
+ if (snapend - bp < length)
+ length = snapend - bp;
+
if (Xflag) {
/* dump the buffer in `emacs-hexl' style */
default_print_hexl(bp, length);
/* dump the text in the buffer */
default_print_ascii(bp, length);
} else {
+ u_short sp;
+
/* dump the buffer in old tcpdump style */
- if ((long)bp & 1) {
- default_print_unaligned(bp, length);
- return;
- }
- sp = (u_short *)bp;
nshorts = (u_int) length / sizeof(u_short);
i = 0;
while (--nshorts >= 0) {
if ((i++ % 8) == 0)
printf("\n\t\t\t");
- printf(" %04x", ntohs(*sp++));
+
+ sp = (u_short)*bp++ << 8;
+ sp |= *bp++;
+ printf(" %04x", sp);
}
if (length & 1) {
if ((i % 8) == 0)
printf("\n\t\t\t");
- printf(" %02x", *(u_char *)sp);
+ printf(" %02x", *bp);
}
}
}