From: Guy Harris Date: Mon, 29 Jan 2018 23:48:55 +0000 (-0800) Subject: Add nd_{v}snprintf() routines/wrappers. X-Git-Tag: tcpdump-4.99-bp~1315 X-Git-Url: https://git.tcpdump.org/tcpdump/commitdiff_plain/c499612a7f1024a183d0200ef5f1ea7fba63a3e4 Add nd_{v}snprintf() routines/wrappers. Some versions of the MSVC runtime library have a non-C99-compliant vsnprintf(), which we want to avoid. On Windows, use snprintf() and vsnprintf() for VS 2015 and later, where they both exist in C99-compliant forms, and wrap _{v}snprintf_s() otherwise (they're guaranteed to do the null termination that we want). --- diff --git a/CMakeLists.txt b/CMakeLists.txt index 7e2b9db5..3482ea81 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -204,14 +204,33 @@ cmake_pop_check_state() check_function_exists(getopt_long HAVE_GETOPT_LONG) # -# With MSVC 2015, stdio.h defines snprintf() and vsnprintf() as inline -# functions, so you need to include stdio.h when testing for them - -# check_function_exists() won't do it, you need check_symbol_exists(). -# -check_symbol_exists(vsnprintf stdio.h HAVE_VSNPRINTF) -check_symbol_exists(snprintf stdio.h HAVE_SNPRINTF) -check_function_exists(fork HAVE_FORK) -check_function_exists(vfork HAVE_VFORK) +# For Windows, either +# +# 1) we're using VS 2015, in which case we have both snprintf() +# and vsnprintf(), and they behave in a C99-compliant fashion, +# so we use them +# +# or +# +# 2) we're not, and we don't have snprintf(), and we either don't +# have vsnprintf() or we have one that *doesn't* behave in a +# C99-compliant fashion, but we *do* have _snprintf_s() and +# _vsnprintf_s(), so we wrap them with #defines +# +# and we test for both of them at compile time, so we don't need to +# check for snprintf() or vsnprintf() here. +# +# XXX - do we need to care about UN*Xes that don't have snprintf() +# or vsnprintf() any more? +# +# We also don't need to waste time checking for fork() or vfork(). +# +if(NOT WIN32) + check_function_exists(vsnprintf HAVE_VSNPRINTF) + check_function_exists(snprintf HAVE_SNPRINTF) + check_function_exists(fork HAVE_FORK) + check_function_exists(vfork HAVE_VFORK) +endif(NOT WIN32) check_function_exists(strftime HAVE_STRFTIME) check_function_exists(setlinebuf HAVE_SETLINEBUF) @@ -920,13 +939,11 @@ foreach(FUNC strlcat strlcpy strdup strsep getservent getopt_long) set(NETDISSECT_SOURCE_LIST_C ${NETDISSECT_SOURCE_LIST_C} missing/${FUNC}.c) endif() endforeach() -if(NOT HAVE_VSNPRINTF OR NOT HAVE_SNPRINTF) - if(WIN32) - set(NETDISSECT_SOURCE_LIST_C ${NETDISSECT_SOURCE_LIST_C} missing/win_snprintf.c) - else(WIN32) +if(NOT WIN32) + if(NOT HAVE_VSNPRINTF OR NOT HAVE_SNPRINTF) set(NETDISSECT_SOURCE_LIST_C ${NETDISSECT_SOURCE_LIST_C} missing/snprintf.c) - endif(WIN32) -endif(NOT HAVE_VSNPRINTF OR NOT HAVE_SNPRINTF) + endif(NOT HAVE_VSNPRINTF OR NOT HAVE_SNPRINTF) +endif(NOT WIN32) add_library(netdissect STATIC ${NETDISSECT_SOURCE_LIST_C} diff --git a/Makefile.in b/Makefile.in index 185e44b5..6169bd11 100644 --- a/Makefile.in +++ b/Makefile.in @@ -358,7 +358,6 @@ EXTRA_DIST = \ missing/strsep.c \ missing/win_ether_ntohost.c \ missing/win_ether_ntohost.h \ - missing/win_snprintf.c \ mkdep \ packetdat.awk \ pcap_dump_ftell.c \ diff --git a/addrtoname.c b/addrtoname.c index ac79c0f2..effc0914 100644 --- a/addrtoname.c +++ b/addrtoname.c @@ -594,7 +594,7 @@ etheraddr_string(netdissect_options *ndo, const u_char *ep) } if (!ndo->ndo_nflag) { - snprintf(cp, BUFSIZE - (2 + 5*3), " (oui %s)", + nd_snprintf(cp, BUFSIZE - (2 + 5*3), " (oui %s)", tok2str(oui_values, "Unknown", oui)); } else *cp = '\0'; @@ -743,7 +743,7 @@ tcpport_string(netdissect_options *ndo, u_short port) tp->addr = i; tp->nxt = newhnamemem(ndo); - (void)snprintf(buf, sizeof(buf), "%u", i); + (void)nd_snprintf(buf, sizeof(buf), "%u", i); tp->name = strdup(buf); if (tp->name == NULL) (*ndo->ndo_error)(ndo, "tcpport_string: strdup(buf)"); @@ -764,7 +764,7 @@ udpport_string(netdissect_options *ndo, u_short port) tp->addr = i; tp->nxt = newhnamemem(ndo); - (void)snprintf(buf, sizeof(buf), "%u", i); + (void)nd_snprintf(buf, sizeof(buf), "%u", i); tp->name = strdup(buf); if (tp->name == NULL) (*ndo->ndo_error)(ndo, "udpport_string: strdup(buf)"); @@ -820,7 +820,7 @@ init_servarray(netdissect_options *ndo) while (table->name) table = table->nxt; if (ndo->ndo_nflag) { - (void)snprintf(buf, sizeof(buf), "%d", port); + (void)nd_snprintf(buf, sizeof(buf), "%d", port); table->name = strdup(buf); } else table->name = strdup(sv->s_name); @@ -1318,7 +1318,7 @@ const char * ieee8021q_tci_string(const uint16_t tci) { static char buf[128]; - snprintf(buf, sizeof(buf), "vlan %u, p %u%s", + nd_snprintf(buf, sizeof(buf), "vlan %u, p %u%s", tci & 0xfff, tci >> 13, (tci & 0x1000) ? ", DEI" : ""); diff --git a/addrtostr.c b/addrtostr.c index 62cc298a..3b573529 100644 --- a/addrtostr.c +++ b/addrtostr.c @@ -191,7 +191,7 @@ addrtostr6 (const void *src, char *dst, size_t size) space_left -= added_space; break; } - snprintfed = snprintf (dp, space_left, "%x", words[i]); + snprintfed = nd_snprintf (dp, space_left, "%x", words[i]); if (snprintfed < 0) return (NULL); if ((size_t) snprintfed >= space_left) diff --git a/interface.h b/interface.h index 8927a19b..d54172ee 100644 --- a/interface.h +++ b/interface.h @@ -28,8 +28,6 @@ #include "funcattrs.h" -/* snprintf et al */ - #include #if HAVE_STDINT_H diff --git a/machdep.c b/machdep.c index 0c9304a2..f55c2688 100644 --- a/machdep.c +++ b/machdep.c @@ -35,11 +35,6 @@ #include #include -#if !defined(HAVE_SNPRINTF) -int snprintf(char *, size_t, const char *, ...) PRINTFLIKE(3, 4); -#endif /* !defined(HAVE_SNPRINTF) */ -#endif /* __osf__ */ - #include "machdep.h" /* diff --git a/missing/getservent.c b/missing/getservent.c index 39cee068..198644f2 100644 --- a/missing/getservent.c +++ b/missing/getservent.c @@ -65,9 +65,9 @@ const char *etc_path(const char *file) return (file); else #ifdef _WIN32 - snprintf(path, sizeof(path), "%s%s%s", env, __PATH_ETC_INET, file); + nd_snprintf(path, sizeof(path), "%s%s%s", env, __PATH_ETC_INET, file); #else - snprintf(path, sizeof(path), "%s%s", env, file); + nd_snprintf(path, sizeof(path), "%s%s", env, file); #endif return (path); } diff --git a/missing/snprintf.c b/missing/snprintf.c index 921b74c1..3b21f31f 100644 --- a/missing/snprintf.c +++ b/missing/snprintf.c @@ -456,13 +456,13 @@ xyzprintf (struct state *state, const char *char_format, va_list ap) #ifndef HAVE_SNPRINTF int -snprintf (char *str, size_t sz, const char *format, ...) +nd_snprintf (char *str, size_t sz, const char *format, ...) { va_list args; int ret; va_start(args, format); - ret = vsnprintf (str, sz, format, args); + ret = nd_vsnprintf (str, sz, format, args); #ifdef PARANOIA { @@ -518,13 +518,13 @@ asprintf (char **ret, const char *format, ...) #ifndef HAVE_ASNPRINTF int -asnprintf (char **ret, size_t max_sz, const char *format, ...) +nd_asnprintf (char **ret, size_t max_sz, const char *format, ...) { va_list args; int val; va_start(args, format); - val = vasnprintf (ret, max_sz, format, args); + val = nd_vasnprintf (ret, max_sz, format, args); #ifdef PARANOIA { @@ -550,14 +550,14 @@ asnprintf (char **ret, size_t max_sz, const char *format, ...) int vasprintf (char **ret, const char *format, va_list args) { - return vasnprintf (ret, 0, format, args); + return nd_vasnprintf (ret, 0, format, args); } #endif #ifndef HAVE_VASNPRINTF int -vasnprintf (char **ret, size_t max_sz, const char *format, va_list args) +nd_vasnprintf (char **ret, size_t max_sz, const char *format, va_list args) { int st; size_t len; @@ -600,7 +600,7 @@ vasnprintf (char **ret, size_t max_sz, const char *format, va_list args) #ifndef HAVE_VSNPRINTF int -vsnprintf (char *str, size_t sz, const char *format, va_list args) +nd_vsnprintf (char *str, size_t sz, const char *format, va_list args) { struct state state; int ret; diff --git a/missing/win_ether_ntohost.c b/missing/win_ether_ntohost.c index 05930923..6ac26b7c 100644 --- a/missing/win_ether_ntohost.c +++ b/missing/win_ether_ntohost.c @@ -85,9 +85,9 @@ const char *etc_path (const char *file) return (file); if (win9x) - snprintf (path, sizeof(path), "%s\\etc\\%s", env, file); + nd_snprintf (path, sizeof(path), "%s\\etc\\%s", env, file); else - snprintf (path, sizeof(path), "%s\\system32\\drivers\\etc\\%s", env, file); + nd_snprintf (path, sizeof(path), "%s\\system32\\drivers\\etc\\%s", env, file); return (path); } diff --git a/missing/win_snprintf.c b/missing/win_snprintf.c deleted file mode 100644 index 17dc633c..00000000 --- a/missing/win_snprintf.c +++ /dev/null @@ -1,31 +0,0 @@ -#include -#include - -int -vsnprintf(char *str, size_t str_size, const char *format, va_list args) -{ - int ret; - - ret = _vsnprintf_s(str, str_size, _TRUNCATE, format, args); - - /* - * XXX - _vsnprintf() and _snprintf() do *not* guarantee - * that str is null-terminated, but C99's vsnprintf() - * and snprintf() do, and we want to offer C99 behavior, - * so forcibly null-terminate the string. - */ - str[str_size - 1] = '\0'; - return (ret); -} - -int -snprintf(char *str, size_t str_size, const char *format, ...) -{ - va_list args; - int ret; - - va_start(args, format); - ret = vsnprintf(str, str_size, format, args); - va_end(args); - return (ret); -} diff --git a/netdissect-stdinc.h b/netdissect-stdinc.h index 5437f32e..2a4e1bc7 100644 --- a/netdissect-stdinc.h +++ b/netdissect-stdinc.h @@ -307,22 +307,51 @@ typedef char* caddr_t; * and define vsnprintf to be _vsnprintf, as we're relying on null- * termination of strings in all cases. * - * We also want to allow this to be built with versions of Visual Studio - * prior to VS 2015, so we can't rely on snprintf() being present. + * Furthermore, some versions of Visual Studio prior to Visual + * Studio 2015 had vsnprintf() (but not snprintf()!), but those + * versions don't guarantee null termination, either. * - * And, if there are any UN*Xes out there on which we can run that - * don't have snprintf() or don't have vsnprintf(), we define our - * own as well. + * We assume all UN*Xes that have snprintf() and vsnprintf() provide + * C99 behavior. */ -#if !defined(HAVE_SNPRINTF) -int snprintf (char *str, size_t sz, FORMAT_STRING(const char *format), ...) - PRINTFLIKE(3, 4); -#endif /* !defined(HAVE_SNPRINTF) */ - -#if !defined(HAVE_VSNPRINTF) -int vsnprintf (char *str, size_t sz, FORMAT_STRING(const char *format), - va_list ap) PRINTFLIKE(3, 0); -#endif /* !defined(HAVE_VSNPRINTF) */ +#if defined(_MSC_VER) || defined(__MINGW32__) + #if defined(_MSC_VER) && _MSC_VER >= 1900 + /* + * VS 2015 or newer; just use the C runtime's snprintf() and + * vsnprintf(). + */ + #define nd_snprintf snprintf + #define nd_vsnprintf vsnprintf + #else /* defined(_MSC_VER) && _MSC_VER >= 1900 */ + /* + * VS prior to 2015, or MingGW; assume we have _snprintf_s() and + * _vsnprintf_s(), which guarantee null termination. + */ + #define nd_snprintf(buf, buflen, fmt, ...) \ + _snprintf_s(buf, buflen, _TRUNCATE, fmt, __VA_ARGS__) + #define nd_vsnprintf(buf, buflen, fmt, ap) \ + _vsnprintf_s(buf, buflen, _TRUNCATE, fmt, ap) + #endif /* defined(_MSC_VER) && _MSC_VER >= 1900 */ +#else /* defined(_MSC_VER) || defined(__MINGW32__) */ + /* + * Some other compiler, which we assume to be a UN*X compiler. + * Use the system's snprintf() if we have it, otherwise use + * our own implementation + */ + #ifdef HAVE_SNPRINTF + #define nd_snprintf snprintf + #else /* HAVE_SNPRINTF */ + int nd_snprintf (char *str, size_t sz, FORMAT_STRING(const char *format), ...) + PRINTFLIKE(3, 4); + #endif /* HAVE_SNPRINTF */ + + #ifdef HAVE_VSNPRINTF + #define nd_vsnprintf vsnprintf + #else /* HAVE_VSNPRINTF */ + int nd_vsnprintf (char *str, size_t sz, FORMAT_STRING(const char *format), + va_list ap) PRINTFLIKE(3, 0); + #endif /* HAVE_VSNPRINTF */ +#endif /* defined(_MSC_VER) || defined(__MINGW32__) */ /* * fopen() read and write modes for text files and binary files. diff --git a/netdissect.c b/netdissect.c index 450bb1a2..d32de4e9 100644 --- a/netdissect.c +++ b/netdissect.c @@ -122,14 +122,14 @@ nd_load_smi_module(const char *module, char *errbuf, size_t errbuf_size) { #ifdef USE_LIBSMI if (smiLoadModule(module) == 0) { - snprintf(errbuf, errbuf_size, "could not load MIB module %s", + nd_snprintf(errbuf, errbuf_size, "could not load MIB module %s", module); return (-1); } nd_smi_module_loaded = 1; return (0); #else - snprintf(errbuf, errbuf_size, "MIB module %s not loaded: no libsmi support", + nd_snprintf(errbuf, errbuf_size, "MIB module %s not loaded: no libsmi support", module); return (-1); #endif diff --git a/netdissect.h b/netdissect.h index 3e76468b..4c09bfe2 100644 --- a/netdissect.h +++ b/netdissect.h @@ -152,7 +152,7 @@ typedef unsigned char nd_mac_addr[MAC_ADDR_LEN]; */ typedef unsigned char nd_byte; -/* snprintf et al */ +/* nd_snprintf et al */ #include #include diff --git a/parsenfsfh.c b/parsenfsfh.c index 0a54a3ff..324ba664 100644 --- a/parsenfsfh.c +++ b/parsenfsfh.c @@ -450,7 +450,7 @@ Parse_fh(const unsigned char *fh, u_int len, my_fsid *fsidp, #endif /* Save the actual handle, so it can be display with -u */ for (i = 0; i < len*4 && i*2 < sizeof(fsidp->Opaque_Handle) - 1; i++) - (void)snprintf(&(fsidp->Opaque_Handle[i*2]), 3, "%.2X", + (void)nd_snprintf(&(fsidp->Opaque_Handle[i*2]), 3, "%.2X", EXTRACT_U_1(fhp + i)); fsidp->Opaque_Handle[i*2] = '\0'; diff --git a/print-ascii.c b/print-ascii.c index bd87f6ac..0c347bf0 100644 --- a/print-ascii.c +++ b/print-ascii.c @@ -114,7 +114,7 @@ hex_and_ascii_print_with_offset(netdissect_options *ndo, const char *ident, cp++; s2 = EXTRACT_U_1(cp); cp++; - (void)snprintf(hsp, sizeof(hexstuff) - (hsp - hexstuff), + (void)nd_snprintf(hsp, sizeof(hexstuff) - (hsp - hexstuff), " %02x%02x", s1, s2); hsp += HEXDUMP_HEXSTUFF_PER_SHORT; *(asp++) = (ND_ISGRAPH(s1) ? s1 : '.'); @@ -132,7 +132,7 @@ hex_and_ascii_print_with_offset(netdissect_options *ndo, const char *ident, if (length & 1) { s1 = EXTRACT_U_1(cp); cp++; - (void)snprintf(hsp, sizeof(hexstuff) - (hsp - hexstuff), + (void)nd_snprintf(hsp, sizeof(hexstuff) - (hsp - hexstuff), " %02x", s1); hsp += 3; *(asp++) = (ND_ISGRAPH(s1) ? s1 : '.'); diff --git a/print-atalk.c b/print-atalk.c index 0d6b87d8..25a1801a 100644 --- a/print-atalk.c +++ b/print-atalk.c @@ -624,7 +624,7 @@ ataddr_string(netdissect_options *ndo, if (tp2->addr == i) { tp->addr = (atnet << 8) | athost; tp->nxt = newhnamemem(ndo); - (void)snprintf(nambuf, sizeof(nambuf), "%s.%u", + (void)nd_snprintf(nambuf, sizeof(nambuf), "%s.%u", tp2->name, athost); tp->name = strdup(nambuf); if (tp->name == NULL) @@ -636,9 +636,9 @@ ataddr_string(netdissect_options *ndo, tp->addr = (atnet << 8) | athost; tp->nxt = newhnamemem(ndo); if (athost != 255) - (void)snprintf(nambuf, sizeof(nambuf), "%u.%u", atnet, athost); + (void)nd_snprintf(nambuf, sizeof(nambuf), "%u.%u", atnet, athost); else - (void)snprintf(nambuf, sizeof(nambuf), "%u", atnet); + (void)nd_snprintf(nambuf, sizeof(nambuf), "%u", atnet); tp->name = strdup(nambuf); if (tp->name == NULL) (*ndo->ndo_error)(ndo, "ataddr_string: strdup(nambuf)"); @@ -661,7 +661,7 @@ ddpskt_string(netdissect_options *ndo, static char buf[8]; if (ndo->ndo_nflag) { - (void)snprintf(buf, sizeof(buf), "%u", skt); + (void)nd_snprintf(buf, sizeof(buf), "%u", skt); return (buf); } return (tok2str(skt2str, "%u", skt)); diff --git a/print-babel.c b/print-babel.c index 0fba820b..c7d789b8 100644 --- a/print-babel.c +++ b/print-babel.c @@ -111,7 +111,7 @@ static const char * format_id(const u_char *id) { static char buf[25]; - snprintf(buf, 25, "%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x", + nd_snprintf(buf, 25, "%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x", EXTRACT_U_1(id), EXTRACT_U_1(id + 1), EXTRACT_U_1(id + 2), EXTRACT_U_1(id + 3), EXTRACT_U_1(id + 4), EXTRACT_U_1(id + 5), EXTRACT_U_1(id + 6), EXTRACT_U_1(id + 7)); @@ -127,9 +127,9 @@ format_prefix(netdissect_options *ndo, const u_char *prefix, unsigned char plen) { static char buf[50]; if(plen >= 96 && memcmp(prefix, v4prefix, 12) == 0) - snprintf(buf, 50, "%s/%u", ipaddr_string(ndo, prefix + 12), plen - 96); + nd_snprintf(buf, 50, "%s/%u", ipaddr_string(ndo, prefix + 12), plen - 96); else - snprintf(buf, 50, "%s/%u", ip6addr_string(ndo, prefix), plen); + nd_snprintf(buf, 50, "%s/%u", ip6addr_string(ndo, prefix), plen); buf[49] = '\0'; return buf; } @@ -150,7 +150,7 @@ format_interval(const uint16_t i) if (i == 0) return "0.0s (bogus)"; - snprintf(buf, sizeof(buf), "%u.%02us", i / 100, i % 100); + nd_snprintf(buf, sizeof(buf), "%u.%02us", i / 100, i % 100); return buf; } @@ -164,7 +164,7 @@ static const char * format_timestamp(const uint32_t i) { static char buf[sizeof("0000.000000s")]; - snprintf(buf, sizeof(buf), "%u.%06us", i / 1000000, i % 1000000); + nd_snprintf(buf, sizeof(buf), "%u.%06us", i / 1000000, i % 1000000); return buf; } diff --git a/print-bgp.c b/print-bgp.c index 5a8f279e..dd1f6d38 100644 --- a/print-bgp.c +++ b/print-bgp.c @@ -524,9 +524,9 @@ as_printf(netdissect_options *ndo, char *str, size_t size, u_int asnum) { if (!ndo->ndo_bflag || asnum <= 0xFFFF) { - snprintf(str, size, "%u", asnum); + nd_snprintf(str, size, "%u", asnum); } else { - snprintf(str, size, "%u.%u", asnum >> 16, asnum & 0xFFFF); + nd_snprintf(str, size, "%u.%u", asnum >> 16, asnum & 0xFFFF); } return str; } @@ -555,7 +555,7 @@ decode_prefix4(netdissect_options *ndo, if (plen % 8) { ((u_char *)&addr)[plenbytes - 1] &= ((0xff00 >> (plen % 8)) & 0xff); } - snprintf(buf, buflen, "%s/%u", ipaddr_string(ndo, &addr), plen); + nd_snprintf(buf, buflen, "%s/%u", ipaddr_string(ndo, &addr), plen); return 1 + plenbytes; trunc: @@ -603,7 +603,7 @@ decode_labeled_prefix4(netdissect_options *ndo, ((u_char *)&addr)[plenbytes - 1] &= ((0xff00 >> (plen % 8)) & 0xff); } /* the label may get offsetted by 4 bits so lets shift it right */ - snprintf(buf, buflen, "%s/%u, label:%u %s", + nd_snprintf(buf, buflen, "%s/%u, label:%u %s", ipaddr_string(ndo, &addr), plen, EXTRACT_BE_U_3(pptr + 1)>>4, @@ -635,14 +635,14 @@ bgp_vpn_ip_print(netdissect_options *ndo, switch(addr_length) { case (sizeof(struct in_addr) << 3): /* 32 */ ND_TCHECK_LEN(pptr, sizeof(struct in_addr)); - snprintf(pos, sizeof(addr), "%s", ipaddr_string(ndo, pptr)); + nd_snprintf(pos, sizeof(addr), "%s", ipaddr_string(ndo, pptr)); break; case (sizeof(struct in6_addr) << 3): /* 128 */ ND_TCHECK_LEN(pptr, sizeof(struct in6_addr)); - snprintf(pos, sizeof(addr), "%s", ip6addr_string(ndo, pptr)); + nd_snprintf(pos, sizeof(addr), "%s", ip6addr_string(ndo, pptr)); break; default: - snprintf(pos, sizeof(addr), "bogus address length %u", addr_length); + nd_snprintf(pos, sizeof(addr), "bogus address length %u", addr_length); break; } pos += strlen(pos); @@ -689,7 +689,7 @@ bgp_vpn_sg_print(netdissect_options *ndo, total_length += (addr_length >> 3) + 1; offset = strlen(buf); if (addr_length) { - snprintf(buf + offset, buflen - offset, ", Source %s", + nd_snprintf(buf + offset, buflen - offset, ", Source %s", bgp_vpn_ip_print(ndo, pptr, addr_length)); pptr += (addr_length >> 3); } @@ -704,7 +704,7 @@ bgp_vpn_sg_print(netdissect_options *ndo, total_length += (addr_length >> 3) + 1; offset = strlen(buf); if (addr_length) { - snprintf(buf + offset, buflen - offset, ", Group %s", + nd_snprintf(buf + offset, buflen - offset, ", Group %s", bgp_vpn_ip_print(ndo, pptr, addr_length)); pptr += (addr_length >> 3); } @@ -729,7 +729,7 @@ bgp_vpn_rd_print(netdissect_options *ndo, /* 2-byte-AS:number fmt*/ case 0: - snprintf(pos, sizeof(rd) - (pos - rd), "%u:%u (= %u.%u.%u.%u)", + nd_snprintf(pos, sizeof(rd) - (pos - rd), "%u:%u (= %u.%u.%u.%u)", EXTRACT_BE_U_2(pptr + 2), EXTRACT_BE_U_4(pptr + 4), EXTRACT_U_1(pptr + 4), EXTRACT_U_1(pptr + 5), @@ -738,7 +738,7 @@ bgp_vpn_rd_print(netdissect_options *ndo, /* IP-address:AS fmt*/ case 1: - snprintf(pos, sizeof(rd) - (pos - rd), "%u.%u.%u.%u:%u", + nd_snprintf(pos, sizeof(rd) - (pos - rd), "%u.%u.%u.%u:%u", EXTRACT_U_1(pptr + 2), EXTRACT_U_1(pptr + 3), EXTRACT_U_1(pptr + 4), EXTRACT_U_1(pptr + 5), EXTRACT_BE_U_2(pptr + 6)); @@ -746,14 +746,14 @@ bgp_vpn_rd_print(netdissect_options *ndo, /* 4-byte-AS:number fmt*/ case 2: - snprintf(pos, sizeof(rd) - (pos - rd), "%s:%u (%u.%u.%u.%u:%u)", + nd_snprintf(pos, sizeof(rd) - (pos - rd), "%s:%u (%u.%u.%u.%u:%u)", as_printf(ndo, astostr, sizeof(astostr), EXTRACT_BE_U_4(pptr + 2)), EXTRACT_BE_U_2(pptr + 6), EXTRACT_U_1(pptr + 2), EXTRACT_U_1(pptr + 3), EXTRACT_U_1(pptr + 4), EXTRACT_U_1(pptr + 5), EXTRACT_BE_U_2(pptr + 6)); break; default: - snprintf(pos, sizeof(rd) - (pos - rd), "unknown RD format"); + nd_snprintf(pos, sizeof(rd) - (pos - rd), "unknown RD format"); break; } pos += strlen(pos); @@ -779,7 +779,7 @@ decode_rt_routing_info(netdissect_options *ndo, */ if (0 == plen) { /* Without "origin AS", without "route target". */ - snprintf(buf, buflen, "default route target"); + nd_snprintf(buf, buflen, "default route target"); return 1; } @@ -807,7 +807,7 @@ decode_rt_routing_info(netdissect_options *ndo, ((u_char *)&route_target)[(plen + 7) / 8 - 1] &= ((0xff00 >> (plen % 8)) & 0xff); } - snprintf(buf, buflen, "origin AS: %s, route target %s", + nd_snprintf(buf, buflen, "origin AS: %s, route target %s", asbuf, bgp_vpn_rd_print(ndo, (u_char *)&route_target)); @@ -843,7 +843,7 @@ decode_labeled_vpn_prefix4(netdissect_options *ndo, ((0xff00 >> (plen % 8)) & 0xff); } /* the label may get offsetted by 4 bits so lets shift it right */ - snprintf(buf, buflen, "RD: %s, %s/%u, label:%u %s", + nd_snprintf(buf, buflen, "RD: %s, %s/%u, label:%u %s", bgp_vpn_rd_print(ndo, pptr+4), ipaddr_string(ndo, &addr), plen, @@ -895,7 +895,7 @@ decode_mdt_vpn_nlri(netdissect_options *ndo, /* MDT Group Address */ ND_TCHECK_LEN(pptr, sizeof(struct in_addr)); - snprintf(buf, buflen, "RD: %s, VPN IP Address: %s, MC Group Address: %s", + nd_snprintf(buf, buflen, "RD: %s, VPN IP Address: %s, MC Group Address: %s", bgp_vpn_rd_print(ndo, rd), ipaddr_string(ndo, vpn_ip), ipaddr_string(ndo, pptr)); return MDT_VPN_NLRI_LEN + 1; @@ -937,7 +937,7 @@ decode_multicast_vpn(netdissect_options *ndo, route_length = EXTRACT_U_1(pptr); pptr++; - snprintf(buf, buflen, "Route-Type: %s (%u), length: %u", + nd_snprintf(buf, buflen, "Route-Type: %s (%u), length: %u", tok2str(bgp_multicast_vpn_route_type_values, "Unknown", route_type), route_type, route_length); @@ -946,7 +946,7 @@ decode_multicast_vpn(netdissect_options *ndo, case BGP_MULTICAST_VPN_ROUTE_TYPE_INTRA_AS_I_PMSI: ND_TCHECK_LEN(pptr, BGP_VPN_RD_LEN); offset = strlen(buf); - snprintf(buf + offset, buflen - offset, ", RD: %s, Originator %s", + nd_snprintf(buf + offset, buflen - offset, ", RD: %s, Originator %s", bgp_vpn_rd_print(ndo, pptr), bgp_vpn_ip_print(ndo, pptr + BGP_VPN_RD_LEN, (route_length - BGP_VPN_RD_LEN) << 3)); @@ -954,7 +954,7 @@ decode_multicast_vpn(netdissect_options *ndo, case BGP_MULTICAST_VPN_ROUTE_TYPE_INTER_AS_I_PMSI: ND_TCHECK_LEN(pptr, BGP_VPN_RD_LEN + 4); offset = strlen(buf); - snprintf(buf + offset, buflen - offset, ", RD: %s, Source-AS %s", + nd_snprintf(buf + offset, buflen - offset, ", RD: %s, Source-AS %s", bgp_vpn_rd_print(ndo, pptr), as_printf(ndo, astostr, sizeof(astostr), EXTRACT_BE_U_4(pptr + BGP_VPN_RD_LEN))); @@ -963,7 +963,7 @@ decode_multicast_vpn(netdissect_options *ndo, case BGP_MULTICAST_VPN_ROUTE_TYPE_S_PMSI: ND_TCHECK_LEN(pptr, BGP_VPN_RD_LEN); offset = strlen(buf); - snprintf(buf + offset, buflen - offset, ", RD: %s", + nd_snprintf(buf + offset, buflen - offset, ", RD: %s", bgp_vpn_rd_print(ndo, pptr)); pptr += BGP_VPN_RD_LEN; @@ -972,14 +972,14 @@ decode_multicast_vpn(netdissect_options *ndo, ND_TCHECK_LEN(pptr, addr_length); offset = strlen(buf); - snprintf(buf + offset, buflen - offset, ", Originator %s", + nd_snprintf(buf + offset, buflen - offset, ", Originator %s", bgp_vpn_ip_print(ndo, pptr, addr_length << 3)); break; case BGP_MULTICAST_VPN_ROUTE_TYPE_SOURCE_ACTIVE: ND_TCHECK_LEN(pptr, BGP_VPN_RD_LEN); offset = strlen(buf); - snprintf(buf + offset, buflen - offset, ", RD: %s", + nd_snprintf(buf + offset, buflen - offset, ", RD: %s", bgp_vpn_rd_print(ndo, pptr)); pptr += BGP_VPN_RD_LEN; @@ -990,7 +990,7 @@ decode_multicast_vpn(netdissect_options *ndo, case BGP_MULTICAST_VPN_ROUTE_TYPE_SOURCE_TREE_JOIN: ND_TCHECK_LEN(pptr, BGP_VPN_RD_LEN + 4); offset = strlen(buf); - snprintf(buf + offset, buflen - offset, ", RD: %s, Source-AS %s", + nd_snprintf(buf + offset, buflen - offset, ", RD: %s, Source-AS %s", bgp_vpn_rd_print(ndo, pptr), as_printf(ndo, astostr, sizeof(astostr), EXTRACT_BE_U_4(pptr + BGP_VPN_RD_LEN))); @@ -1052,7 +1052,7 @@ decode_labeled_vpn_l2(netdissect_options *ndo, /* assume AD-only with RD, BGPNH */ ND_TCHECK_LEN(pptr, 12); buf[0] = '\0'; - stringlen = snprintf(buf, buflen, "RD: %s, BGPNH: %s", + stringlen = nd_snprintf(buf, buflen, "RD: %s, BGPNH: %s", bgp_vpn_rd_print(ndo, pptr), ipaddr_string(ndo, pptr+8)); UPDATE_BUF_BUFLEN(buf, buflen, stringlen); @@ -1065,7 +1065,7 @@ decode_labeled_vpn_l2(netdissect_options *ndo, ND_TCHECK_LEN(pptr, 15); buf[0] = '\0'; - stringlen = snprintf(buf, buflen, "RD: %s, CE-ID: %u, Label-Block Offset: %u, Label Base %u", + stringlen = nd_snprintf(buf, buflen, "RD: %s, CE-ID: %u, Label-Block Offset: %u, Label Base %u", bgp_vpn_rd_print(ndo, pptr), EXTRACT_BE_U_2(pptr + 8), EXTRACT_BE_U_2(pptr + 10), @@ -1078,7 +1078,7 @@ decode_labeled_vpn_l2(netdissect_options *ndo, while (tlen != 0) { if (tlen < 3) { if (buflen != 0) { - stringlen=snprintf(buf,buflen, "\n\t\tran past the end"); + stringlen=nd_snprintf(buf,buflen, "\n\t\tran past the end"); UPDATE_BUF_BUFLEN(buf, buflen, stringlen); } return plen + 2; @@ -1093,7 +1093,7 @@ decode_labeled_vpn_l2(netdissect_options *ndo, switch(tlv_type) { case 1: if (buflen != 0) { - stringlen=snprintf(buf,buflen, "\n\t\tcircuit status vector (%u) length: %u: 0x", + stringlen=nd_snprintf(buf,buflen, "\n\t\tcircuit status vector (%u) length: %u: 0x", tlv_type, tlv_len); UPDATE_BUF_BUFLEN(buf, buflen, stringlen); @@ -1101,14 +1101,14 @@ decode_labeled_vpn_l2(netdissect_options *ndo, while (ttlv_len != 0) { if (tlen < 1) { if (buflen != 0) { - stringlen=snprintf(buf,buflen, " (ran past the end)"); + stringlen=nd_snprintf(buf,buflen, " (ran past the end)"); UPDATE_BUF_BUFLEN(buf, buflen, stringlen); } return plen + 2; } ND_TCHECK_1(pptr); if (buflen != 0) { - stringlen=snprintf(buf,buflen, "%02x", + stringlen=nd_snprintf(buf,buflen, "%02x", EXTRACT_U_1(pptr)); pptr++; UPDATE_BUF_BUFLEN(buf, buflen, stringlen); @@ -1119,14 +1119,14 @@ decode_labeled_vpn_l2(netdissect_options *ndo, break; default: if (buflen != 0) { - stringlen=snprintf(buf,buflen, "\n\t\tunknown TLV #%u, length: %u", + stringlen=nd_snprintf(buf,buflen, "\n\t\tunknown TLV #%u, length: %u", tlv_type, tlv_len); UPDATE_BUF_BUFLEN(buf, buflen, stringlen); } if (tlen < ttlv_len) { if (buflen != 0) { - stringlen=snprintf(buf,buflen, " (ran past the end)"); + stringlen=nd_snprintf(buf,buflen, " (ran past the end)"); UPDATE_BUF_BUFLEN(buf, buflen, stringlen); } return plen + 2; @@ -1169,7 +1169,7 @@ decode_prefix6(netdissect_options *ndo, addr.s6_addr[plenbytes - 1] &= ((0xff00 >> (plen % 8)) & 0xff); } - snprintf(buf, buflen, "%s/%u", ip6addr_string(ndo, &addr), plen); + nd_snprintf(buf, buflen, "%s/%u", ip6addr_string(ndo, &addr), plen); return 1 + plenbytes; trunc: @@ -1209,7 +1209,7 @@ decode_labeled_prefix6(netdissect_options *ndo, ((0xff00 >> (plen % 8)) & 0xff); } /* the label may get offsetted by 4 bits so lets shift it right */ - snprintf(buf, buflen, "%s/%u, label:%u %s", + nd_snprintf(buf, buflen, "%s/%u, label:%u %s", ip6addr_string(ndo, &addr), plen, EXTRACT_BE_U_3(pptr + 1)>>4, @@ -1250,7 +1250,7 @@ decode_labeled_vpn_prefix6(netdissect_options *ndo, ((0xff00 >> (plen % 8)) & 0xff); } /* the label may get offsetted by 4 bits so lets shift it right */ - snprintf(buf, buflen, "RD: %s, %s/%u, label:%u %s", + nd_snprintf(buf, buflen, "RD: %s, %s/%u, label:%u %s", bgp_vpn_rd_print(ndo, pptr+4), ip6addr_string(ndo, &addr), plen, @@ -1283,7 +1283,7 @@ decode_clnp_prefix(netdissect_options *ndo, addr[(plen + 7) / 8 - 1] &= ((0xff00 >> (plen % 8)) & 0xff); } - snprintf(buf, buflen, "%s/%u", + nd_snprintf(buf, buflen, "%s/%u", isonsap_string(ndo, addr,(plen + 7) / 8), plen); @@ -1318,7 +1318,7 @@ decode_labeled_vpn_clnp_prefix(netdissect_options *ndo, addr[(plen + 7) / 8 - 1] &= ((0xff00 >> (plen % 8)) & 0xff); } /* the label may get offsetted by 4 bits so lets shift it right */ - snprintf(buf, buflen, "RD: %s, %s/%u, label:%u %s", + nd_snprintf(buf, buflen, "RD: %s, %s/%u, label:%u %s", bgp_vpn_rd_print(ndo, pptr+4), isonsap_string(ndo, addr,(plen + 7) / 8), plen, diff --git a/print-cnfp.c b/print-cnfp.c index 17fdc859..badbea96 100644 --- a/print-cnfp.c +++ b/print-cnfp.c @@ -296,14 +296,14 @@ cnfp_v5_print(netdissect_options *ndo, const u_char *cp) EXTRACT_BE_U_4(nr->last_time)%1000); asbuf[0] = buf[0] = '\0'; - snprintf(buf, sizeof(buf), "/%u", EXTRACT_U_1(nr->src_mask)); - snprintf(asbuf, sizeof(asbuf), ":%u", + nd_snprintf(buf, sizeof(buf), "/%u", EXTRACT_U_1(nr->src_mask)); + nd_snprintf(asbuf, sizeof(asbuf), ":%u", EXTRACT_BE_U_2(nr->src_as)); ND_PRINT("\n %s%s%s:%u ", intoa(nr->src_ina.s_addr), buf, asbuf, EXTRACT_BE_U_2(nr->srcport)); - snprintf(buf, sizeof(buf), "/%u", EXTRACT_U_1(nr->dst_mask)); - snprintf(asbuf, sizeof(asbuf), ":%u", + nd_snprintf(buf, sizeof(buf), "/%u", EXTRACT_U_1(nr->dst_mask)); + nd_snprintf(asbuf, sizeof(asbuf), ":%u", EXTRACT_BE_U_2(nr->dst_as)); ND_PRINT("> %s%s%s:%u ", intoa(nr->dst_ina.s_addr), buf, asbuf, EXTRACT_BE_U_2(nr->dstport)); @@ -394,14 +394,14 @@ cnfp_v6_print(netdissect_options *ndo, const u_char *cp) EXTRACT_BE_U_4(nr->last_time)%1000); asbuf[0] = buf[0] = '\0'; - snprintf(buf, sizeof(buf), "/%u", EXTRACT_U_1(nr->src_mask)); - snprintf(asbuf, sizeof(asbuf), ":%u", + nd_snprintf(buf, sizeof(buf), "/%u", EXTRACT_U_1(nr->src_mask)); + nd_snprintf(asbuf, sizeof(asbuf), ":%u", EXTRACT_BE_U_2(nr->src_as)); ND_PRINT("\n %s%s%s:%u ", intoa(nr->src_ina.s_addr), buf, asbuf, EXTRACT_BE_U_2(nr->srcport)); - snprintf(buf, sizeof(buf), "/%u", EXTRACT_U_1(nr->dst_mask)); - snprintf(asbuf, sizeof(asbuf), ":%u", + nd_snprintf(buf, sizeof(buf), "/%u", EXTRACT_U_1(nr->dst_mask)); + nd_snprintf(asbuf, sizeof(asbuf), ":%u", EXTRACT_BE_U_2(nr->dst_as)); ND_PRINT("> %s%s%s:%u ", intoa(nr->dst_ina.s_addr), buf, asbuf, EXTRACT_BE_U_2(nr->dstport)); @@ -429,7 +429,7 @@ cnfp_v6_print(netdissect_options *ndo, const u_char *cp) } buf[0]='\0'; - snprintf(buf, sizeof(buf), "(%u<>%u encaps)", + nd_snprintf(buf, sizeof(buf), "(%u<>%u encaps)", (EXTRACT_BE_U_2(nr->flags) >> 8) & 0xff, (EXTRACT_BE_U_2(nr->flags)) & 0xff); ND_PRINT("tos %u, %u (%u octets) %s", diff --git a/print-decnet.c b/print-decnet.c index 7606d5c2..92361cf3 100644 --- a/print-decnet.c +++ b/print-decnet.c @@ -1246,7 +1246,7 @@ dnnum_string(netdissect_options *ndo, u_short dnaddr) str = (char *)malloc(siz = sizeof("00.0000")); if (str == NULL) (*ndo->ndo_error)(ndo, "dnnum_string: malloc"); - snprintf(str, siz, "%u.%u", area, node); + nd_snprintf(str, siz, "%u.%u", area, node); return(str); } diff --git a/print-fr.c b/print-fr.c index d9ac455b..a95b56f2 100644 --- a/print-fr.c +++ b/print-fr.c @@ -152,7 +152,7 @@ q922_string(netdissect_options *ndo, const u_char *p, u_int length) memset(buffer, 0, sizeof(buffer)); if (parse_q922_header(ndo, p, &dlci, &addr_len, &flags, length) == 1){ - snprintf(buffer, sizeof(buffer), "DLCI %u", dlci); + nd_snprintf(buffer, sizeof(buffer), "DLCI %u", dlci); } return buffer; diff --git a/print-hncp.c b/print-hncp.c index 0dee297f..1121d2a1 100644 --- a/print-hncp.c +++ b/print-hncp.c @@ -161,7 +161,7 @@ format_nid(const u_char *data) static char buf[4][sizeof("01:01:01:01")]; static int i = 0; i = (i + 1) % 4; - snprintf(buf[i], sizeof(buf[i]), "%02x:%02x:%02x:%02x", + nd_snprintf(buf[i], sizeof(buf[i]), "%02x:%02x:%02x:%02x", EXTRACT_U_1(data), EXTRACT_U_1(data + 1), EXTRACT_U_1(data + 2), EXTRACT_U_1(data + 3)); return buf[i]; @@ -173,7 +173,7 @@ format_256(const u_char *data) static char buf[4][sizeof("0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef")]; static int i = 0; i = (i + 1) % 4; - snprintf(buf[i], sizeof(buf[i]), "%016" PRIx64 "%016" PRIx64 "%016" PRIx64 "%016" PRIx64, + nd_snprintf(buf[i], sizeof(buf[i]), "%016" PRIx64 "%016" PRIx64 "%016" PRIx64 "%016" PRIx64, EXTRACT_BE_U_8(data), EXTRACT_BE_U_8(data + 8), EXTRACT_BE_U_8(data + 16), @@ -188,7 +188,7 @@ format_interval(const uint32_t n) static char buf[4][sizeof("0000000.000s")]; static int i = 0; i = (i + 1) % 4; - snprintf(buf[i], sizeof(buf[i]), "%u.%03us", n / 1000, n % 1000); + nd_snprintf(buf[i], sizeof(buf[i]), "%u.%03us", n / 1000, n % 1000); return buf[i]; } @@ -226,7 +226,7 @@ print_prefix(netdissect_options *ndo, const u_char *prefix, u_int max_length) ((u_char *)&addr)[plenbytes - 1] &= ((0xff00 >> (plen % 8)) & 0xff); } - snprintf(buf, sizeof(buf), "%s/%u", ipaddr_string(ndo, &addr), plen); + nd_snprintf(buf, sizeof(buf), "%s/%u", ipaddr_string(ndo, &addr), plen); plenbytes += 1 + IPV4_MAPPED_HEADING_LEN; } else { plenbytes = decode_prefix6(ndo, prefix, max_length, buf, sizeof(buf)); diff --git a/print-icmp.c b/print-icmp.c index 7e7db14a..269b14fb 100644 --- a/print-icmp.c +++ b/print-icmp.c @@ -322,7 +322,7 @@ icmp_tstamp_print(u_int tstamp) sec = tstamp / 1000; min = sec / 60; sec -= min * 60; hrs = min / 60; min -= hrs * 60; - snprintf(buf, sizeof(buf), "%02u:%02u:%02u.%03u",hrs,min,sec,msec); + nd_snprintf(buf, sizeof(buf), "%02u:%02u:%02u.%03u",hrs,min,sec,msec); return buf; } @@ -360,7 +360,7 @@ icmp_print(netdissect_options *ndo, const u_char *bp, u_int plen, const u_char * case ICMP_ECHO: case ICMP_ECHOREPLY: ND_TCHECK_2(dp->icmp_seq); - (void)snprintf(buf, sizeof(buf), "echo %s, id %u, seq %u", + (void)nd_snprintf(buf, sizeof(buf), "echo %s, id %u, seq %u", icmp_type == ICMP_ECHO ? "request" : "reply", EXTRACT_BE_U_2(dp->icmp_id), @@ -373,7 +373,7 @@ icmp_print(netdissect_options *ndo, const u_char *bp, u_int plen, const u_char * case ICMP_UNREACH_PROTOCOL: ND_TCHECK_1(dp->icmp_ip.ip_p); - (void)snprintf(buf, sizeof(buf), + (void)nd_snprintf(buf, sizeof(buf), "%s protocol %u unreachable", ipaddr_string(ndo, &dp->icmp_ip.ip_dst), EXTRACT_U_1(dp->icmp_ip.ip_p)); @@ -390,21 +390,21 @@ icmp_print(netdissect_options *ndo, const u_char *bp, u_int plen, const u_char * switch (ip_proto) { case IPPROTO_TCP: - (void)snprintf(buf, sizeof(buf), + (void)nd_snprintf(buf, sizeof(buf), "%s tcp port %s unreachable", ipaddr_string(ndo, &oip->ip_dst), tcpport_string(ndo, dport)); break; case IPPROTO_UDP: - (void)snprintf(buf, sizeof(buf), + (void)nd_snprintf(buf, sizeof(buf), "%s udp port %s unreachable", ipaddr_string(ndo, &oip->ip_dst), udpport_string(ndo, dport)); break; default: - (void)snprintf(buf, sizeof(buf), + (void)nd_snprintf(buf, sizeof(buf), "%s protocol %u port %u unreachable", ipaddr_string(ndo, &oip->ip_dst), ip_proto, dport); @@ -418,11 +418,11 @@ icmp_print(netdissect_options *ndo, const u_char *bp, u_int plen, const u_char * mp = (const struct mtu_discovery *)(const u_char *)&dp->icmp_void; mtu = EXTRACT_BE_U_2(mp->nexthopmtu); if (mtu) { - (void)snprintf(buf, sizeof(buf), + (void)nd_snprintf(buf, sizeof(buf), "%s unreachable - need to frag (mtu %u)", ipaddr_string(ndo, &dp->icmp_ip.ip_dst), mtu); } else { - (void)snprintf(buf, sizeof(buf), + (void)nd_snprintf(buf, sizeof(buf), "%s unreachable - need to frag", ipaddr_string(ndo, &dp->icmp_ip.ip_dst)); } @@ -432,7 +432,7 @@ icmp_print(netdissect_options *ndo, const u_char *bp, u_int plen, const u_char * default: fmt = tok2str(unreach2str, "#%u %%s unreachable", icmp_code); - (void)snprintf(buf, sizeof(buf), fmt, + (void)nd_snprintf(buf, sizeof(buf), fmt, ipaddr_string(ndo, &dp->icmp_ip.ip_dst)); break; } @@ -442,7 +442,7 @@ icmp_print(netdissect_options *ndo, const u_char *bp, u_int plen, const u_char * ND_TCHECK_4(dp->icmp_ip.ip_dst); fmt = tok2str(type2str, "redirect-#%u %%s to net %%s", icmp_code); - (void)snprintf(buf, sizeof(buf), fmt, + (void)nd_snprintf(buf, sizeof(buf), fmt, ipaddr_string(ndo, &dp->icmp_ip.ip_dst), ipaddr_string(ndo, &dp->icmp_gwaddr)); break; @@ -453,7 +453,7 @@ icmp_print(netdissect_options *ndo, const u_char *bp, u_int plen, const u_char * const struct id_rdiscovery *idp; u_int lifetime, num, size; - (void)snprintf(buf, sizeof(buf), "router advertisement"); + (void)nd_snprintf(buf, sizeof(buf), "router advertisement"); cp = buf + strlen(buf); ihp = (const struct ih_rdiscovery *)&dp->icmp_void; @@ -462,13 +462,13 @@ icmp_print(netdissect_options *ndo, const u_char *bp, u_int plen, const u_char * cp = buf + strlen(buf); lifetime = EXTRACT_BE_U_2(ihp->ird_lifetime); if (lifetime < 60) { - (void)snprintf(cp, sizeof(buf) - (cp - buf), "%u", + (void)nd_snprintf(cp, sizeof(buf) - (cp - buf), "%u", lifetime); } else if (lifetime < 60 * 60) { - (void)snprintf(cp, sizeof(buf) - (cp - buf), "%u:%02u", + (void)nd_snprintf(cp, sizeof(buf) - (cp - buf), "%u:%02u", lifetime / 60, lifetime % 60); } else { - (void)snprintf(cp, sizeof(buf) - (cp - buf), + (void)nd_snprintf(cp, sizeof(buf) - (cp - buf), "%u:%02u:%02u", lifetime / 3600, (lifetime % 3600) / 60, @@ -477,19 +477,19 @@ icmp_print(netdissect_options *ndo, const u_char *bp, u_int plen, const u_char * cp = buf + strlen(buf); num = EXTRACT_U_1(ihp->ird_addrnum); - (void)snprintf(cp, sizeof(buf) - (cp - buf), " %u:", num); + (void)nd_snprintf(cp, sizeof(buf) - (cp - buf), " %u:", num); cp = buf + strlen(buf); size = EXTRACT_U_1(ihp->ird_addrsiz); if (size != 2) { - (void)snprintf(cp, sizeof(buf) - (cp - buf), + (void)nd_snprintf(cp, sizeof(buf) - (cp - buf), " [size %u]", size); break; } idp = (const struct id_rdiscovery *)&dp->icmp_data; while (num-- > 0) { ND_TCHECK_SIZE(idp); - (void)snprintf(cp, sizeof(buf) - (cp - buf), " {%s %u}", + (void)nd_snprintf(cp, sizeof(buf) - (cp - buf), " {%s %u}", ipaddr_string(ndo, &idp->ird_addr), EXTRACT_BE_U_4(idp->ird_pref)); cp = buf + strlen(buf); @@ -511,7 +511,7 @@ icmp_print(netdissect_options *ndo, const u_char *bp, u_int plen, const u_char * break; default: - (void)snprintf(buf, sizeof(buf), "time exceeded-#%u", + (void)nd_snprintf(buf, sizeof(buf), "time exceeded-#%u", icmp_code); break; } @@ -519,24 +519,24 @@ icmp_print(netdissect_options *ndo, const u_char *bp, u_int plen, const u_char * case ICMP_PARAMPROB: if (icmp_code) - (void)snprintf(buf, sizeof(buf), + (void)nd_snprintf(buf, sizeof(buf), "parameter problem - code %u", icmp_code); else { ND_TCHECK_1(dp->icmp_pptr); - (void)snprintf(buf, sizeof(buf), + (void)nd_snprintf(buf, sizeof(buf), "parameter problem - octet %u", EXTRACT_U_1(dp->icmp_pptr)); } break; case ICMP_MASKREPLY: ND_TCHECK_4(dp->icmp_mask); - (void)snprintf(buf, sizeof(buf), "address mask is 0x%08x", + (void)nd_snprintf(buf, sizeof(buf), "address mask is 0x%08x", EXTRACT_BE_U_4(dp->icmp_mask)); break; case ICMP_TSTAMP: ND_TCHECK_2(dp->icmp_seq); - (void)snprintf(buf, sizeof(buf), + (void)nd_snprintf(buf, sizeof(buf), "time stamp query id %u seq %u", EXTRACT_BE_U_2(dp->icmp_id), EXTRACT_BE_U_2(dp->icmp_seq)); @@ -544,15 +544,15 @@ icmp_print(netdissect_options *ndo, const u_char *bp, u_int plen, const u_char * case ICMP_TSTAMPREPLY: ND_TCHECK_4(dp->icmp_ttime); - (void)snprintf(buf, sizeof(buf), + (void)nd_snprintf(buf, sizeof(buf), "time stamp reply id %u seq %u: org %s", EXTRACT_BE_U_2(dp->icmp_id), EXTRACT_BE_U_2(dp->icmp_seq), icmp_tstamp_print(EXTRACT_BE_U_4(dp->icmp_otime))); - (void)snprintf(buf+strlen(buf),sizeof(buf)-strlen(buf),", recv %s", + (void)nd_snprintf(buf+strlen(buf),sizeof(buf)-strlen(buf),", recv %s", icmp_tstamp_print(EXTRACT_BE_U_4(dp->icmp_rtime))); - (void)snprintf(buf+strlen(buf),sizeof(buf)-strlen(buf),", xmit %s", + (void)nd_snprintf(buf+strlen(buf),sizeof(buf)-strlen(buf),", xmit %s", icmp_tstamp_print(EXTRACT_BE_U_4(dp->icmp_ttime))); break; diff --git a/print-icmp6.c b/print-icmp6.c index 9d073edc..9453ce9b 100644 --- a/print-icmp6.c +++ b/print-icmp6.c @@ -755,7 +755,7 @@ get_lifetime(uint32_t v) if (v == (uint32_t)~0UL) return "infinity"; else { - snprintf(buf, sizeof(buf), "%us", v); + nd_snprintf(buf, sizeof(buf), "%us", v); return buf; } } diff --git a/print-ipx.c b/print-ipx.c index 4af8b0eb..4faebf73 100644 --- a/print-ipx.c +++ b/print-ipx.c @@ -100,7 +100,7 @@ ipxaddr_string(uint32_t net, const u_char *node) { static char line[256]; - snprintf(line, sizeof(line), "%08x.%02x:%02x:%02x:%02x:%02x:%02x", + nd_snprintf(line, sizeof(line), "%08x.%02x:%02x:%02x:%02x:%02x:%02x", net, EXTRACT_U_1(node), EXTRACT_U_1(node + 1), EXTRACT_U_1(node + 2), EXTRACT_U_1(node + 3), EXTRACT_U_1(node + 4), EXTRACT_U_1(node + 5)); diff --git a/print-isakmp.c b/print-isakmp.c index df9eaf92..84229ec5 100644 --- a/print-isakmp.c +++ b/print-isakmp.c @@ -2794,7 +2794,7 @@ static char * numstr(u_int x) { static char buf[20]; - snprintf(buf, sizeof(buf), "#%u", x); + nd_snprintf(buf, sizeof(buf), "#%u", x); return buf; } diff --git a/print-isoclns.c b/print-isoclns.c index 6433e012..b8252301 100644 --- a/print-isoclns.c +++ b/print-isoclns.c @@ -1676,19 +1676,19 @@ isis_print_id(const uint8_t *cp, u_int id_len) if (sysid_len > id_len) sysid_len = id_len; for (i = 1; i <= sysid_len; i++) { - snprintf(pos, sizeof(id) - (pos - id), "%02x", EXTRACT_U_1(cp)); + nd_snprintf(pos, sizeof(id) - (pos - id), "%02x", EXTRACT_U_1(cp)); cp++; pos += strlen(pos); if (i == 2 || i == 4) *pos++ = '.'; } if (id_len >= NODE_ID_LEN) { - snprintf(pos, sizeof(id) - (pos - id), ".%02x", EXTRACT_U_1(cp)); + nd_snprintf(pos, sizeof(id) - (pos - id), ".%02x", EXTRACT_U_1(cp)); cp++; pos += strlen(pos); } if (id_len == LSP_ID_LEN) - snprintf(pos, sizeof(id) - (pos - id), "-%02x", EXTRACT_U_1(cp)); + nd_snprintf(pos, sizeof(id) - (pos - id), "-%02x", EXTRACT_U_1(cp)); return (id); } @@ -1878,7 +1878,7 @@ isis_print_ext_is_reach(netdissect_options *ndo, if (subtlv_sum_len) { ND_PRINT(" (%u)", subtlv_sum_len); /* prepend the indent string */ - snprintf(ident_buffer, sizeof(ident_buffer), "%s ",ident); + nd_snprintf(ident_buffer, sizeof(ident_buffer), "%s ",ident); ident = ident_buffer; while (subtlv_sum_len != 0) { if (!ND_TTEST_2(tptr)) @@ -2214,7 +2214,7 @@ isis_print_extd_ip_reach(netdissect_options *ndo, subtlvlen=EXTRACT_U_1(tptr + 1); tptr+=2; /* prepend the indent string */ - snprintf(ident_buffer, sizeof(ident_buffer), "%s ",ident); + nd_snprintf(ident_buffer, sizeof(ident_buffer), "%s ",ident); if (!isis_print_ip_reach_subtlv(ndo, tptr, subtlvtype, subtlvlen, ident_buffer)) return(0); tptr+=subtlvlen; diff --git a/print-lldp.c b/print-lldp.c index 1fdb8f25..e76260ec 100644 --- a/print-lldp.c +++ b/print-lldp.c @@ -1355,10 +1355,10 @@ lldp_network_addr_print(netdissect_options *ndo, const u_char *tptr, u_int len) } if (!pfunc) { - snprintf(buf, sizeof(buf), "AFI %s (%u), no AF printer !", + nd_snprintf(buf, sizeof(buf), "AFI %s (%u), no AF printer !", tok2str(af_values, "Unknown", af), af); } else { - snprintf(buf, sizeof(buf), "AFI %s (%u): %s", + nd_snprintf(buf, sizeof(buf), "AFI %s (%u): %s", tok2str(af_values, "Unknown", af), af, (*pfunc)(ndo, tptr+1)); } diff --git a/print-nfs.c b/print-nfs.c index 3407961f..85540693 100644 --- a/print-nfs.c +++ b/print-nfs.c @@ -332,11 +332,11 @@ nfsreply_print(netdissect_options *ndo, ND_TCHECK_4(rp->rm_xid); if (!ndo->ndo_nflag) { strlcpy(srcid, "nfs", sizeof(srcid)); - snprintf(dstid, sizeof(dstid), "%u", + nd_snprintf(dstid, sizeof(dstid), "%u", EXTRACT_BE_U_4(rp->rm_xid)); } else { - snprintf(srcid, sizeof(srcid), "%u", NFS_PORT); - snprintf(dstid, sizeof(dstid), "%u", + nd_snprintf(srcid, sizeof(srcid), "%u", NFS_PORT); + nd_snprintf(dstid, sizeof(dstid), "%u", EXTRACT_BE_U_4(rp->rm_xid)); } print_nfsaddr(ndo, bp2, srcid, dstid); diff --git a/print-openflow-1.0.c b/print-openflow-1.0.c index ac58d7b3..9004f927 100644 --- a/print-openflow-1.0.c +++ b/print-openflow-1.0.c @@ -703,7 +703,7 @@ vlan_str(const uint16_t vid) if (vid == OFP_VLAN_NONE) return "NONE"; fmt = (vid > 0 && vid < 0x0fff) ? "%u" : "%u (bogus)"; - snprintf(buf, sizeof(buf), fmt, vid); + nd_snprintf(buf, sizeof(buf), fmt, vid); return buf; } @@ -711,7 +711,7 @@ static const char * pcp_str(const uint8_t pcp) { static char buf[sizeof("255 (bogus)")]; - snprintf(buf, sizeof(buf), pcp <= 7 ? "%u" : "%u (bogus)", pcp); + nd_snprintf(buf, sizeof(buf), pcp <= 7 ? "%u" : "%u (bogus)", pcp); return buf; } diff --git a/print-rx.c b/print-rx.c index 150ee971..ca6b4672 100644 --- a/print-rx.c +++ b/print-rx.c @@ -1184,7 +1184,7 @@ acl_print(netdissect_options *ndo, acl & PRSFS_ADMINISTER ? "a" : ""); for (i = 0; i < pos; i++) { - snprintf(fmt, sizeof(fmt), "%%%ds %%d\n%%n", maxsize - 1); + nd_snprintf(fmt, sizeof(fmt), "%%%ds %%d\n%%n", maxsize - 1); if (sscanf((char *) s, fmt, user, &acl, &n) != 2) goto finish; s += n; @@ -1198,7 +1198,7 @@ acl_print(netdissect_options *ndo, } for (i = 0; i < neg; i++) { - snprintf(fmt, sizeof(fmt), "%%%ds %%d\n%%n", maxsize - 1); + nd_snprintf(fmt, sizeof(fmt), "%%%ds %%d\n%%n", maxsize - 1); if (sscanf((char *) s, fmt, user, &acl, &n) != 2) goto finish; s += n; diff --git a/print-snmp.c b/print-snmp.c index b9c71fb0..91136796 100644 --- a/print-snmp.c +++ b/print-snmp.c @@ -198,7 +198,7 @@ static const char *ErrorStatus[] = { #define DECODE_ErrorStatus(e) \ ( e >= 0 && (size_t)e < sizeof(ErrorStatus)/sizeof(ErrorStatus[0]) \ ? ErrorStatus[e] \ - : (snprintf(errbuf, sizeof(errbuf), "err=%u", e), errbuf)) + : (nd_snprintf(errbuf, sizeof(errbuf), "err=%u", e), errbuf)) /* * generic-trap values in the SNMP Trap-PDU @@ -216,7 +216,7 @@ static const char *GenericTrap[] = { #define DECODE_GenericTrap(t) \ ( t >= 0 && (size_t)t < sizeof(GenericTrap)/sizeof(GenericTrap[0]) \ ? GenericTrap[t] \ - : (snprintf(buf, sizeof(buf), "gt=%d", t), buf)) + : (nd_snprintf(buf, sizeof(buf), "gt=%d", t), buf)) /* * ASN.1 type class table diff --git a/print-stp.c b/print-stp.c index 0ccfc411..f0fecaf7 100644 --- a/print-stp.c +++ b/print-stp.c @@ -91,7 +91,7 @@ stp_print_bridge_id(const u_char *p) { static char bridge_id_str[sizeof("pppp.aa:bb:cc:dd:ee:ff")]; - snprintf(bridge_id_str, sizeof(bridge_id_str), + nd_snprintf(bridge_id_str, sizeof(bridge_id_str), "%.2x%.2x.%.2x:%.2x:%.2x:%.2x:%.2x:%.2x", EXTRACT_U_1(p), EXTRACT_U_1(p + 1), EXTRACT_U_1(p + 2), EXTRACT_U_1(p + 3), EXTRACT_U_1(p + 4), EXTRACT_U_1(p + 5), diff --git a/print-sunrpc.c b/print-sunrpc.c index 749abd1f..74e9db38 100644 --- a/print-sunrpc.c +++ b/print-sunrpc.c @@ -170,13 +170,13 @@ sunrpc_print(netdissect_options *ndo, const u_char *bp, rp = (const struct sunrpc_msg *)bp; if (!ndo->ndo_nflag) { - snprintf(srcid, sizeof(srcid), "0x%x", + nd_snprintf(srcid, sizeof(srcid), "0x%x", EXTRACT_BE_U_4(rp->rm_xid)); strlcpy(dstid, "sunrpc", sizeof(dstid)); } else { - snprintf(srcid, sizeof(srcid), "0x%x", + nd_snprintf(srcid, sizeof(srcid), "0x%x", EXTRACT_BE_U_4(rp->rm_xid)); - snprintf(dstid, sizeof(dstid), "0x%x", SUNRPC_PMAPPORT); + nd_snprintf(dstid, sizeof(dstid), "0x%x", SUNRPC_PMAPPORT); } switch (IP_V((const struct ip *)bp2)) { @@ -234,7 +234,7 @@ progstr(uint32_t prog) rp = getrpcbynumber(prog); if (rp == NULL) #endif - (void) snprintf(buf, sizeof(buf), "#%u", prog); + (void) nd_snprintf(buf, sizeof(buf), "#%u", prog); #if defined(HAVE_GETRPCBYNUMBER) && defined(HAVE_RPC_RPC_H) else strlcpy(buf, rp->r_name, sizeof(buf)); diff --git a/print-telnet.c b/print-telnet.c index f23d8a56..6c3e7d53 100644 --- a/print-telnet.c +++ b/print-telnet.c @@ -382,7 +382,7 @@ numstr(int x) { static char buf[20]; - snprintf(buf, sizeof(buf), "%#x", x); + nd_snprintf(buf, sizeof(buf), "%#x", x); return buf; } diff --git a/print-zephyr.c b/print-zephyr.c index 01e34ed8..eddbe859 100644 --- a/print-zephyr.c +++ b/print-zephyr.c @@ -119,7 +119,7 @@ z_triple(const char *class, const char *inst, const char *recipient) { if (!*recipient) recipient = "*"; - snprintf(z_buf, sizeof(z_buf), "<%s,%s,%s>", class, inst, recipient); + nd_snprintf(z_buf, sizeof(z_buf), "<%s,%s,%s>", class, inst, recipient); z_buf[sizeof(z_buf)-1] = '\0'; return z_buf; } diff --git a/smbutil.c b/smbutil.c index 01f21fe6..c2249c45 100644 --- a/smbutil.c +++ b/smbutil.c @@ -1026,17 +1026,17 @@ smb_errstr(int class, int num) const err_code_struct *err = err_classes[i].err_msgs; for (j = 0; err[j].name; j++) if (num == err[j].code) { - snprintf(ret, sizeof(ret), "%s - %s (%s)", + nd_snprintf(ret, sizeof(ret), "%s - %s (%s)", err_classes[i].class, err[j].name, err[j].message); return ret; } } - snprintf(ret, sizeof(ret), "%s - %d", err_classes[i].class, num); + nd_snprintf(ret, sizeof(ret), "%s - %d", err_classes[i].class, num); return ret; } - snprintf(ret, sizeof(ret), "ERROR: Unknown error (%d,%d)", class, num); + nd_snprintf(ret, sizeof(ret), "ERROR: Unknown error (%d,%d)", class, num); return(ret); } @@ -1917,6 +1917,6 @@ nt_errstr(uint32_t err) return nt_errors[i].name; } - snprintf(ret, sizeof(ret), "0x%08x", err); + nd_snprintf(ret, sizeof(ret), "0x%08x", err); return ret; } diff --git a/tcpdump.c b/tcpdump.c index b325b28c..81321f79 100644 --- a/tcpdump.c +++ b/tcpdump.c @@ -779,7 +779,7 @@ MakeFilename(char *buffer, char *orig_name, int cnt, int max_chars) if (cnt == 0 && max_chars == 0) strncpy(buffer, filename, PATH_MAX + 1); else - if (snprintf(buffer, PATH_MAX + 1, "%s%0*d", filename, max_chars, cnt) > PATH_MAX) + if (nd_snprintf(buffer, PATH_MAX + 1, "%s%0*d", filename, max_chars, cnt) > PATH_MAX) /* Report an error if the filename is too large */ error("too many output files or filename is too long (> %d)", PATH_MAX); free(filename); @@ -1198,7 +1198,7 @@ fprintf(stderr, "Opening %s\n", device); /* * Return an error for our caller to handle. */ - snprintf(ebuf, PCAP_ERRBUF_SIZE, "%s: %s\n(%s)", + nd_snprintf(ebuf, PCAP_ERRBUF_SIZE, "%s: %s\n(%s)", device, pcap_statustostr(status), cp); pcap_close(pc); return (NULL); @@ -1212,7 +1212,7 @@ fprintf(stderr, "Opening %s\n", device); char sysctl[32]; size_t s = sizeof(parent); - snprintf(sysctl, sizeof(sysctl), + nd_snprintf(sysctl, sizeof(sysctl), "net.wlan.%d.%%parent", atoi(device + 4)); sysctlbyname(sysctl, parent, &s, NULL, 0); strlcpy(newdev, device, sizeof(newdev)); diff --git a/util-print.c b/util-print.c index 82f450c6..5123ba1a 100644 --- a/util-print.c +++ b/util-print.c @@ -268,7 +268,7 @@ _U_ format = "%02d:%02d:%02d.%06u"; #endif - snprintf(buf, TS_BUF_SIZE, format, + nd_snprintf(buf, TS_BUF_SIZE, format, sec / 3600, (sec % 3600) / 60, sec % 60, usec); return buf; @@ -305,7 +305,7 @@ _U_ format = "%u.%06u"; #endif - snprintf(buf, TS_BUF_SIZE, format, + nd_snprintf(buf, TS_BUF_SIZE, format, (unsigned)sec, (unsigned)usec); return buf; @@ -497,7 +497,7 @@ tok2strbuf(const struct tok *lp, const char *fmt, if (fmt == NULL) fmt = "#%d"; - (void)snprintf(buf, bufsize, fmt, v); + (void)nd_snprintf(buf, bufsize, fmt, v); return (const char *)buf; } @@ -569,7 +569,7 @@ bittok2str_internal(const struct tok *lp, const char *fmt, if (bufp == buf) /* bummer - lets print the "unknown" message as advised in the fmt string if we got one */ - (void)snprintf(buf, sizeof(buf), fmt == NULL ? "#%08x" : fmt, v); + (void)nd_snprintf(buf, sizeof(buf), fmt == NULL ? "#%08x" : fmt, v); return (buf); } @@ -611,7 +611,7 @@ tok2strary_internal(const char **lp, int n, const char *fmt, return lp[v]; if (fmt == NULL) fmt = "#%d"; - (void)snprintf(buf, sizeof(buf), fmt, v); + (void)nd_snprintf(buf, sizeof(buf), fmt, v); return (buf); }