X-Git-Url: https://git.tcpdump.org/tcpdump/blobdiff_plain/b8c56aa09228ee6c59af9bd2565bc66b69ac7943..9f957a5883cb4c5c99cefa71b42fc9d2d27d73e1:/print-sl.c diff --git a/print-sl.c b/print-sl.c index 3fd7e898..18059041 100644 --- a/print-sl.c +++ b/print-sl.c @@ -59,9 +59,9 @@ u_int sl_if_print(netdissect_options *ndo, const struct pcap_pkthdr *h, const u_char *p) { - register u_int caplen = h->caplen; - register u_int length = h->len; - register const struct ip *ip; + u_int caplen = h->caplen; + u_int length = h->len; + const struct ip *ip; if (caplen < SLIP_HDRLEN || length < SLIP_HDRLEN) { ND_PRINT((ndo, "%s", tstr)); @@ -99,9 +99,9 @@ u_int sl_bsdos_if_print(netdissect_options *ndo, const struct pcap_pkthdr *h, const u_char *p) { - register u_int caplen = h->caplen; - register u_int length = h->len; - register const struct ip *ip; + u_int caplen = h->caplen; + u_int length = h->len; + const struct ip *ip; if (caplen < SLIP_HDRLEN) { ND_PRINT((ndo, "%s", tstr)); @@ -124,25 +124,38 @@ sl_bsdos_if_print(netdissect_options *ndo, static void sliplink_print(netdissect_options *ndo, - register const u_char *p, register const struct ip *ip, - register u_int length) + const u_char *p, const struct ip *ip, + u_int length) { int dir; u_int hlen; - dir = p[SLX_DIR]; - ND_PRINT((ndo, dir == SLIPDIR_IN ? "I " : "O ")); + dir = EXTRACT_U_1(p + SLX_DIR); + switch (dir) { + case SLIPDIR_IN: + ND_PRINT((ndo, "I ")); + break; + + case SLIPDIR_OUT: + ND_PRINT((ndo, "O ")); + break; + + default: + ND_PRINT((ndo, "Invalid direction %d ", dir)); + dir = -1; + break; + } if (ndo->ndo_nflag) { /* XXX just dump the header */ - register int i; + int i; for (i = SLX_CHDR; i < SLX_CHDR + CHDR_LEN - 1; ++i) - ND_PRINT((ndo, "%02x.", p[i])); - ND_PRINT((ndo, "%02x: ", p[SLX_CHDR + CHDR_LEN - 1])); + ND_PRINT((ndo, "%02x.", EXTRACT_U_1(p + i))); + ND_PRINT((ndo, "%02x: ", EXTRACT_U_1(p + SLX_CHDR + CHDR_LEN - 1))); return; } - switch (p[SLX_CHDR] & 0xf0) { + switch (EXTRACT_U_1(p + SLX_CHDR) & 0xf0) { case TYPE_IP: ND_PRINT((ndo, "ip %d: ", length + SLIP_HDRLEN)); @@ -154,31 +167,40 @@ sliplink_print(netdissect_options *ndo, * Get it from the link layer since sl_uncompress_tcp() * has restored the IP header copy to IPPROTO_TCP. */ - lastconn = ((const struct ip *)&p[SLX_CHDR])->ip_p; + lastconn = EXTRACT_U_1(((const struct ip *)(p + SLX_CHDR))->ip_p); + ND_PRINT((ndo, "utcp %d: ", lastconn)); + if (dir == -1) { + /* Direction is bogus, don't use it */ + return; + } hlen = IP_HL(ip); hlen += TH_OFF((const struct tcphdr *)&((const int *)ip)[hlen]); lastlen[dir][lastconn] = length - (hlen << 2); - ND_PRINT((ndo, "utcp %d: ", lastconn)); break; default: - if (p[SLX_CHDR] & TYPE_COMPRESSED_TCP) { - compressed_sl_print(ndo, &p[SLX_CHDR], ip, - length, dir); + if (dir == -1) { + /* Direction is bogus, don't use it */ + return; + } + if (EXTRACT_U_1(p + SLX_CHDR) & TYPE_COMPRESSED_TCP) { + compressed_sl_print(ndo, p + SLX_CHDR, ip, + length, dir); ND_PRINT((ndo, ": ")); } else - ND_PRINT((ndo, "slip-%d!: ", p[SLX_CHDR])); + ND_PRINT((ndo, "slip-%d!: ", EXTRACT_U_1(p + SLX_CHDR))); } } static const u_char * print_sl_change(netdissect_options *ndo, - const char *str, register const u_char *cp) + const char *str, const u_char *cp) { - register u_int i; + u_int i; - if ((i = *cp++) == 0) { - i = EXTRACT_16BITS(cp); + if ((i = EXTRACT_U_1(cp)) == 0) { + cp++; + i = EXTRACT_BE_U_2(cp); cp += 2; } ND_PRINT((ndo, " %s%d", str, i)); @@ -187,12 +209,13 @@ print_sl_change(netdissect_options *ndo, static const u_char * print_sl_winchange(netdissect_options *ndo, - register const u_char *cp) + const u_char *cp) { - register short i; + short i; - if ((i = *cp++) == 0) { - i = EXTRACT_16BITS(cp); + if ((i = EXTRACT_U_1(cp)) == 0) { + cp++; + i = EXTRACT_BE_U_2(cp); cp += 2; } if (i >= 0) @@ -207,12 +230,14 @@ compressed_sl_print(netdissect_options *ndo, const u_char *chdr, const struct ip *ip, u_int length, int dir) { - register const u_char *cp = chdr; - register u_int flags, hlen; + const u_char *cp = chdr; + u_int flags, hlen; - flags = *cp++; + flags = EXTRACT_U_1(cp); + cp++; if (flags & NEW_C) { - lastconn = *cp++; + lastconn = EXTRACT_U_1(cp); + cp++; ND_PRINT((ndo, "ctcp %d", lastconn)); } else ND_PRINT((ndo, "ctcp *"));