diff options
-rw-r--r-- | CMakeLists.txt | 6 | ||||
-rw-r--r-- | Makefile.in | 8 | ||||
-rwxr-xr-x | configure | 48 | ||||
-rw-r--r-- | configure.ac | 16 | ||||
-rw-r--r-- | gencode.c | 2 | ||||
-rw-r--r-- | missing/strlcat.c | 61 | ||||
-rw-r--r-- | missing/strlcpy.c | 56 | ||||
-rw-r--r-- | pcap-bpf.c | 16 | ||||
-rw-r--r-- | pcap-dag.c | 2 | ||||
-rw-r--r-- | pcap-dlpi.c | 14 | ||||
-rw-r--r-- | pcap-dos.c | 4 | ||||
-rw-r--r-- | pcap-libdlpi.c | 2 | ||||
-rw-r--r-- | pcap-linux.c | 74 | ||||
-rw-r--r-- | pcap-new.c | 8 | ||||
-rw-r--r-- | pcap-npf.c | 2 | ||||
-rw-r--r-- | pcap-null.c | 4 | ||||
-rw-r--r-- | pcap-rpcap.c | 6 | ||||
-rw-r--r-- | pcap-septel.c | 2 | ||||
-rw-r--r-- | pcap-sita.c | 2 | ||||
-rw-r--r-- | pcap-snf.c | 2 | ||||
-rw-r--r-- | pcap-usb-linux.c | 2 | ||||
-rw-r--r-- | pcap.c | 56 | ||||
-rw-r--r-- | portability.h | 71 | ||||
-rw-r--r-- | rpcapd/fileconf.c | 10 | ||||
-rw-r--r-- | rpcapd/rpcapd.c | 10 | ||||
-rw-r--r-- | savefile.c | 4 | ||||
-rw-r--r-- | sockutils.c | 6 |
27 files changed, 339 insertions, 155 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index 2dfcc80b..06276f24 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -797,6 +797,12 @@ else() if(NOT HAVE_SNPRINTF) set(PROJECT_SOURCE_LIST_C ${PROJECT_SOURCE_LIST_C} missing/snprintf.c) endif(NOT HAVE_SNPRINTF) + if(NOT HAVE_STRLCAT) + set(PROJECT_SOURCE_LIST_C ${PROJECT_SOURCE_LIST_C} missing/strlcat.c) + endif(NOT HAVE_STRLCAT) + if(NOT HAVE_STRLCPY) + set(PROJECT_SOURCE_LIST_C ${PROJECT_SOURCE_LIST_C} missing/strlcpy.c) + endif(NOT HAVE_STRLCPY) if(NOT HAVE_STRTOK_R) set(PROJECT_SOURCE_LIST_C ${PROJECT_SOURCE_LIST_C} missing/strtok_r.c) endif(NOT HAVE_STRTOK_R) diff --git a/Makefile.in b/Makefile.in index b24f2194..54b03c22 100644 --- a/Makefile.in +++ b/Makefile.in @@ -279,6 +279,8 @@ EXTRA_DIST = \ missing/getopt.c \ missing/getopt.h \ missing/snprintf.c \ + missing/strlcat.c \ + missing/strlcpy.c \ missing/strtok_r.c \ missing/win_snprintf.c \ mkdep \ @@ -492,6 +494,12 @@ gencode.o: $(srcdir)/gencode.c grammar.h scanner.h snprintf.o: $(srcdir)/missing/snprintf.c $(CC) $(FULL_CFLAGS) -o $@ -c $(srcdir)/missing/snprintf.c +strlcat.o: $(srcdir)/missing/strlcat.c + $(CC) $(FULL_CFLAGS) -o $@ -c $(srcdir)/missing/strlcat.c + +strlcpy.o: $(srcdir)/missing/strlcpy.c + $(CC) $(FULL_CFLAGS) -o $@ -c $(srcdir)/missing/strlcpy.c + strtok_r.o: $(srcdir)/missing/strtok_r.c $(CC) $(FULL_CFLAGS) -o $@ -c $(srcdir)/missing/strtok_r.c @@ -5024,7 +5024,7 @@ $as_echo "$ac_cv_lbl_gcc_fixincludes" >&6; } fi fi -for ac_func in strerror strerror_r strerror_s strlcpy strlcat +for ac_func in strerror strerror_r strerror_s do : as_ac_var=`$as_echo "ac_cv_func_$ac_func" | $as_tr_sh` ac_fn_c_check_func "$LINENO" "$ac_func" "$as_ac_var" @@ -5061,6 +5061,52 @@ esac fi +needstrlcat=no +for ac_func in strlcat +do : + ac_fn_c_check_func "$LINENO" "strlcat" "ac_cv_func_strlcat" +if test "x$ac_cv_func_strlcat" = xyes; then : + cat >>confdefs.h <<_ACEOF +#define HAVE_STRLCAT 1 +_ACEOF + +else + needstrlcat=yes +fi +done + +if test $needstrlcat = yes; then + case " $LIBOBJS " in + *" strlcat.$ac_objext "* ) ;; + *) LIBOBJS="$LIBOBJS strlcat.$ac_objext" + ;; +esac + +fi + +needstrlcpy=no +for ac_func in strlcpy +do : + ac_fn_c_check_func "$LINENO" "strlcpy" "ac_cv_func_strlcpy" +if test "x$ac_cv_func_strlcpy" = xyes; then : + cat >>confdefs.h <<_ACEOF +#define HAVE_STRLCPY 1 +_ACEOF + +else + needstrlcpy=yes +fi +done + +if test $needstrlcpy = yes; then + case " $LIBOBJS " in + *" strlcpy.$ac_objext "* ) ;; + *) LIBOBJS="$LIBOBJS strlcpy.$ac_objext" + ;; +esac + +fi + needstrtok_r=no for ac_func in strtok_r do : diff --git a/configure.ac b/configure.ac index d5fe3fae..604de849 100644 --- a/configure.ac +++ b/configure.ac @@ -94,7 +94,7 @@ esac AC_LBL_FIXINCLUDES -AC_CHECK_FUNCS(strerror strerror_r strerror_s strlcpy strlcat) +AC_CHECK_FUNCS(strerror strerror_r strerror_s) needsnprintf=no AC_CHECK_FUNCS(vsnprintf snprintf,, @@ -103,6 +103,20 @@ if test $needsnprintf = yes; then AC_LIBOBJ([snprintf]) fi +needstrlcat=no +AC_CHECK_FUNCS(strlcat,, + [needstrlcat=yes]) +if test $needstrlcat = yes; then + AC_LIBOBJ([strlcat]) +fi + +needstrlcpy=no +AC_CHECK_FUNCS(strlcpy,, + [needstrlcpy=yes]) +if test $needstrlcpy = yes; then + AC_LIBOBJ([strlcpy]) +fi + needstrtok_r=no AC_CHECK_FUNCS(strtok_r,, [needstrtok_r=yes]) @@ -610,7 +610,7 @@ sdup(compiler_state_t *cstate, const char *s) size_t n = strlen(s) + 1; char *cp = newchunk(cstate, n); - strlcpy(cp, s, n); + pcap_strlcpy(cp, s, n); return (cp); } diff --git a/missing/strlcat.c b/missing/strlcat.c new file mode 100644 index 00000000..bb78a3d0 --- /dev/null +++ b/missing/strlcat.c @@ -0,0 +1,61 @@ +/* $OpenBSD: pcap_strlcat.c,v 1.15 2015/03/02 21:41:08 millert Exp $ */ + +/* + * Copyright (c) 1998, 2015 Todd C. Miller <Todd.Miller@courtesan.com> + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +#ifdef HAVE_CONFIG_H +#include <config.h> +#endif + +#include <stddef.h> +#include <string.h> + +#include "portability.h" + +/* + * Appends src to string dst of size dsize (unlike strncat, dsize is the + * full size of dst, not space left). At most dsize-1 characters + * will be copied. Always NUL terminates (unless dsize <= strlen(dst)). + * Returns strlen(src) + MIN(dsize, strlen(initial dst)). + * If retval >= dsize, truncation occurred. + */ +size_t +pcap_strlcat(char * restrict dst, const char * restrict src, size_t dsize) +{ + const char *odst = dst; + const char *osrc = src; + size_t n = dsize; + size_t dlen; + + /* Find the end of dst and adjust bytes left but don't go past end. */ + while (n-- != 0 && *dst != '\0') + dst++; + dlen = dst - odst; + n = dsize - dlen; + + if (n-- == 0) + return(dlen + strlen(src)); + while (*src != '\0') { + if (n != 0) { + *dst++ = *src; + n--; + } + src++; + } + *dst = '\0'; + + return(dlen + (src - osrc)); /* count does not include NUL */ +} diff --git a/missing/strlcpy.c b/missing/strlcpy.c new file mode 100644 index 00000000..c552e0d5 --- /dev/null +++ b/missing/strlcpy.c @@ -0,0 +1,56 @@ +/* $OpenBSD: pcap_strlcpy.c,v 1.12 2015/01/15 03:54:12 millert Exp $ */ + +/* + * Copyright (c) 1998, 2015 Todd C. Miller <Todd.Miller@courtesan.com> + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +#ifdef HAVE_CONFIG_H +#include <config.h> +#endif + +#include <stddef.h> +#include <string.h> + +#include "portability.h" + +/* + * Copy string src to buffer dst of size dsize. At most dsize-1 + * chars will be copied. Always NUL terminates (unless dsize == 0). + * Returns strlen(src); if retval >= dsize, truncation occurred. + */ +size_t +pcap_strlcpy(char * restrict dst, const char * restrict src, size_t dsize) +{ + const char *osrc = src; + size_t nleft = dsize; + + /* Copy as many bytes as will fit. */ + if (nleft != 0) { + while (--nleft != 0) { + if ((*dst++ = *src++) == '\0') + break; + } + } + + /* Not enough room in dst, add NUL and traverse rest of src. */ + if (nleft == 0) { + if (dsize != 0) + *dst = '\0'; /* NUL-terminate dst */ + while (*src++) + ; + } + + return(src - osrc - 1); /* count does not include NUL */ +} @@ -799,8 +799,8 @@ pcap_can_set_rfmon_bpf(pcap_t *p) errno, "socket"); return (PCAP_ERROR); } - strlcpy(ifr.ifr_name, "wlt", sizeof(ifr.ifr_name)); - strlcat(ifr.ifr_name, p->opt.device + 2, sizeof(ifr.ifr_name)); + pcap_strlcpy(ifr.ifr_name, "wlt", sizeof(ifr.ifr_name)); + pcap_strlcat(ifr.ifr_name, p->opt.device + 2, sizeof(ifr.ifr_name)); if (ioctl(fd, SIOCGIFFLAGS, (char *)&ifr) < 0) { /* * No such device? @@ -1469,7 +1469,7 @@ pcap_cleanup_bpf(pcap_t *p) s = socket(AF_LOCAL, SOCK_DGRAM, 0); if (s >= 0) { - strlcpy(ifr.ifr_name, pb->device, + pcap_strlcpy(ifr.ifr_name, pb->device, sizeof(ifr.ifr_name)); ioctl(s, SIOCIFDESTROY, &ifr); close(s); @@ -1532,9 +1532,9 @@ check_setif_failure(pcap_t *p, int error) */ fd = socket(AF_INET, SOCK_DGRAM, 0); if (fd != -1) { - strlcpy(ifr.ifr_name, "en", + pcap_strlcpy(ifr.ifr_name, "en", sizeof(ifr.ifr_name)); - strlcat(ifr.ifr_name, p->opt.device + 3, + pcap_strlcat(ifr.ifr_name, p->opt.device + 3, sizeof(ifr.ifr_name)); if (ioctl(fd, SIOCGIFFLAGS, (char *)&ifr) < 0) { /* @@ -1721,7 +1721,7 @@ pcap_activate_bpf(pcap_t *p) goto bad; } znamelen = zonesep - p->opt.device; - (void) strlcpy(path_zname, p->opt.device, znamelen + 1); + (void) pcap_strlcpy(path_zname, p->opt.device, znamelen + 1); ifr.lifr_zoneid = getzoneidbyname(path_zname); if (ifr.lifr_zoneid == -1) { pcap_fmt_errmsg_for_errno(p->errbuf, PCAP_ERRBUF_SIZE, @@ -1786,7 +1786,7 @@ pcap_activate_bpf(pcap_t *p) */ sockfd = socket(AF_INET, SOCK_DGRAM, 0); if (sockfd != -1) { - strlcpy(ifrname, + pcap_strlcpy(ifrname, p->opt.device, ifnamsiz); if (ioctl(sockfd, SIOCGIFFLAGS, (char *)&ifr) < 0) { @@ -1888,7 +1888,7 @@ pcap_activate_bpf(pcap_t *p) /* * Create the interface. */ - strlcpy(ifr.ifr_name, p->opt.device, sizeof(ifr.ifr_name)); + pcap_strlcpy(ifr.ifr_name, p->opt.device, sizeof(ifr.ifr_name)); if (ioctl(s, SIOCIFCREATE2, &ifr) < 0) { if (errno == EINVAL) { pcap_snprintf(p->errbuf, PCAP_ERRBUF_SIZE, @@ -728,7 +728,7 @@ dag_read(pcap_t *p, int cnt, pcap_handler callback, u_char *user) static int dag_inject(pcap_t *p, const void *buf _U_, int size _U_) { - strlcpy(p->errbuf, "Sending packets isn't supported on DAG cards", + pcap_strlcpy(p->errbuf, "Sending packets isn't supported on DAG cards", PCAP_ERRBUF_SIZE); return (-1); } diff --git a/pcap-dlpi.c b/pcap-dlpi.c index 389b2ac5..a8bfe649 100644 --- a/pcap-dlpi.c +++ b/pcap-dlpi.c @@ -302,7 +302,7 @@ pcap_inject_dlpi(pcap_t *p, const void *buf, int size) * it should check "p->linktype" and reject the send request if * it's anything other than DLT_EN10MB. */ - strlcpy(p->errbuf, "send: Not supported on this version of this OS", + pcap_strlcpy(p->errbuf, "send: Not supported on this version of this OS", PCAP_ERRBUF_SIZE); ret = -1; #endif /* raw mode */ @@ -358,9 +358,9 @@ open_dlpi_device(const char *name, u_int *ppa, char *errbuf) */ cp = strrchr(name, '/'); if (cp == NULL) - strlcpy(dname, name, sizeof(dname)); + pcap_strlcpy(dname, name, sizeof(dname)); else - strlcpy(dname, cp + 1, sizeof(dname)); + pcap_strlcpy(dname, cp + 1, sizeof(dname)); /* * Split the device name into a device type name and a unit number; @@ -410,7 +410,7 @@ open_dlpi_device(const char *name, u_int *ppa, char *errbuf) * device name. */ if (*name == '/') - strlcpy(dname, name, sizeof(dname)); + pcap_strlcpy(dname, name, sizeof(dname)); else pcap_snprintf(dname, sizeof(dname), "%s/%s", PCAP_DEV_PREFIX, name); @@ -427,7 +427,7 @@ open_dlpi_device(const char *name, u_int *ppa, char *errbuf) * Make a copy of the device pathname, and then remove the unit * number from the device pathname. */ - strlcpy(dname2, dname, sizeof(dname)); + pcap_strlcpy(dname2, dname, sizeof(dname)); *cp = '\0'; /* Try device without unit number */ @@ -963,7 +963,7 @@ dl_dohpuxbind(int fd, char *ebuf) *ebuf = '\0'; hpsap++; if (hpsap > 100) { - strlcpy(ebuf, + pcap_strlcpy(ebuf, "All SAPs from 22 through 100 are in use", PCAP_ERRBUF_SIZE); return (-1); @@ -1542,7 +1542,7 @@ get_release(char *buf, size_t bufsize, bpf_u_int32 *majorp, *minorp = 0; *microp = 0; if (sysinfo(SI_RELEASE, buf, bufsize) < 0) { - strlcpy(buf, "?", bufsize); + pcap_strlcpy(buf, "?", bufsize); return; } cp = buf; @@ -413,14 +413,14 @@ int pcap_stats_ex (pcap_t *p, struct pcap_stat_ex *se) if (!dev || !dev->get_stats) { - strlcpy (p->errbuf, "detailed device statistics not available", + pcap_strlcpy (p->errbuf, "detailed device statistics not available", PCAP_ERRBUF_SIZE); return (-1); } if (!strnicmp(dev->name,"pkt",3)) { - strlcpy (p->errbuf, "pktdrvr doesn't have detailed statistics", + pcap_strlcpy (p->errbuf, "pktdrvr doesn't have detailed statistics", PCAP_ERRBUF_SIZE); return (-1); } diff --git a/pcap-libdlpi.c b/pcap-libdlpi.c index af167212..aef18fa2 100644 --- a/pcap-libdlpi.c +++ b/pcap-libdlpi.c @@ -80,7 +80,7 @@ list_interfaces(const char *linkname, void *arg) lwp->lw_err = ENOMEM; return (B_TRUE); } - (void) strlcpy(entry->linkname, linkname, DLPI_LINKNAME_MAX); + (void) pcap_strlcpy(entry->linkname, linkname, DLPI_LINKNAME_MAX); if (lwp->lw_list == NULL) { lwp->lw_list = entry; diff --git a/pcap-linux.c b/pcap-linux.c index 38d4a71a..55ba6062 100644 --- a/pcap-linux.c +++ b/pcap-linux.c @@ -990,7 +990,7 @@ added: * Now configure the monitor interface up. */ memset(&ifr, 0, sizeof(ifr)); - strlcpy(ifr.ifr_name, handlep->mondevice, sizeof(ifr.ifr_name)); + pcap_strlcpy(ifr.ifr_name, handlep->mondevice, sizeof(ifr.ifr_name)); if (ioctl(sock_fd, SIOCGIFFLAGS, &ifr) == -1) { pcap_fmt_errmsg_for_errno(handle->errbuf, PCAP_ERRBUF_SIZE, errno, "%s: Can't get flags for %s", device, @@ -1051,7 +1051,7 @@ is_bonding_device(int fd, const char *device) ifbond ifb; memset(&ifr, 0, sizeof ifr); - strlcpy(ifr.ifr_name, device, sizeof ifr.ifr_name); + pcap_strlcpy(ifr.ifr_name, device, sizeof ifr.ifr_name); memset(&ifb, 0, sizeof ifb); ifr.ifr_data = (caddr_t)&ifb; if (ioctl(fd, BOND_INFO_QUERY_IOCTL, &ifr) == 0) @@ -1140,7 +1140,7 @@ pcap_can_set_rfmon_linux(pcap_t *handle) /* * Attempt to get the current mode. */ - strlcpy(ireq.ifr_ifrn.ifrn_name, handle->opt.device, + pcap_strlcpy(ireq.ifr_ifrn.ifrn_name, handle->opt.device, sizeof ireq.ifr_ifrn.ifrn_name); if (ioctl(sock_fd, SIOCGIWMODE, &ireq) != -1) { /* @@ -1264,7 +1264,7 @@ static void pcap_cleanup_linux( pcap_t *handle ) * in 2.0[.x] kernels. */ memset(&ifr, 0, sizeof(ifr)); - strlcpy(ifr.ifr_name, handlep->device, + pcap_strlcpy(ifr.ifr_name, handlep->device, sizeof(ifr.ifr_name)); if (ioctl(handle->fd, SIOCGIFFLAGS, &ifr) == -1) { fprintf(stderr, @@ -1328,7 +1328,7 @@ static void pcap_cleanup_linux( pcap_t *handle ) */ oldflags = 0; memset(&ifr, 0, sizeof(ifr)); - strlcpy(ifr.ifr_name, handlep->device, + pcap_strlcpy(ifr.ifr_name, handlep->device, sizeof(ifr.ifr_name)); if (ioctl(handle->fd, SIOCGIFFLAGS, &ifr) != -1) { if (ifr.ifr_flags & IFF_UP) { @@ -1342,7 +1342,7 @@ static void pcap_cleanup_linux( pcap_t *handle ) /* * Now restore the mode. */ - strlcpy(ireq.ifr_ifrn.ifrn_name, handlep->device, + pcap_strlcpy(ireq.ifr_ifrn.ifrn_name, handlep->device, sizeof ireq.ifr_ifrn.ifrn_name); ireq.u.mode = handlep->oldmode; if (ioctl(handle->fd, SIOCSIWMODE, &ireq) == -1) { @@ -2177,7 +2177,7 @@ pcap_inject_linux(pcap_t *handle, const void *buf, int size) /* * We don't support sending on the "any" device. */ - strlcpy(handle->errbuf, + pcap_strlcpy(handle->errbuf, "Sending packets isn't supported on the \"any\" device", PCAP_ERRBUF_SIZE); return (-1); @@ -2191,7 +2191,7 @@ pcap_inject_linux(pcap_t *handle, const void *buf, int size) * socket? * Is a "sendto()" required there? */ - strlcpy(handle->errbuf, + pcap_strlcpy(handle->errbuf, "Sending packets isn't supported in cooked mode", PCAP_ERRBUF_SIZE); return (-1); @@ -2405,7 +2405,7 @@ add_linux_if(pcap_if_list_t *devlistp, const char *ifname, int fd, char *errbuf) /* * Get the flags for this interface. */ - strlcpy(ifrflags.ifr_name, name, sizeof(ifrflags.ifr_name)); + pcap_strlcpy(ifrflags.ifr_name, name, sizeof(ifrflags.ifr_name)); if (ioctl(fd, SIOCGIFFLAGS, (char *)&ifrflags) < 0) { if (errno == ENXIO || errno == ENODEV) return (0); /* device doesn't actually exist - ignore it */ @@ -2764,7 +2764,7 @@ get_if_flags(const char *name, bpf_u_int32 *flags, char *errbuf) #ifdef ETHTOOL_GLINK memset(&ifr, 0, sizeof(ifr)); - strlcpy(ifr.ifr_name, name, sizeof(ifr.ifr_name)); + pcap_strlcpy(ifr.ifr_name, name, sizeof(ifr.ifr_name)); info.cmd = ETHTOOL_GLINK; ifr.ifr_data = (caddr_t)&info; if (ioctl(sock, SIOCETHTOOL, &ifr) == -1) { @@ -2892,7 +2892,7 @@ pcap_setfilter_linux_common(pcap_t *handle, struct bpf_program *filter, if (!handle) return -1; if (!filter) { - strlcpy(handle->errbuf, "setfilter: No filter specified", + pcap_strlcpy(handle->errbuf, "setfilter: No filter specified", PCAP_ERRBUF_SIZE); return -1; } @@ -4008,7 +4008,7 @@ activate_new(pcap_t *handle) return 1; #else /* HAVE_PF_PACKET_SOCKETS */ - strlcpy(ebuf, + pcap_strlcpy(ebuf, "New packet capturing interface not supported by build " "environment", PCAP_ERRBUF_SIZE); return 0; @@ -4643,7 +4643,7 @@ create_ring(pcap_t *handle, int *status) hwconfig.rx_filter = HWTSTAMP_FILTER_ALL; memset(&ifr, 0, sizeof(ifr)); - strlcpy(ifr.ifr_name, handle->opt.device, sizeof(ifr.ifr_name)); + pcap_strlcpy(ifr.ifr_name, handle->opt.device, sizeof(ifr.ifr_name)); ifr.ifr_data = (void *)&hwconfig; if (ioctl(handle->fd, SIOCSHWTSTAMP, &ifr) < 0) { @@ -5754,7 +5754,7 @@ iface_get_id(int fd, const char *device, char *ebuf) struct ifreq ifr; memset(&ifr, 0, sizeof(ifr)); - strlcpy(ifr.ifr_name, device, sizeof(ifr.ifr_name)); + pcap_strlcpy(ifr.ifr_name, device, sizeof(ifr.ifr_name)); if (ioctl(fd, SIOCGIFINDEX, &ifr) == -1) { pcap_fmt_errmsg_for_errno(ebuf, PCAP_ERRBUF_SIZE, @@ -5839,7 +5839,7 @@ has_wext(int sock_fd, const char *device, char *ebuf) if (is_bonding_device(sock_fd, device)) return 0; /* bonding device, so don't even try */ - strlcpy(ireq.ifr_ifrn.ifrn_name, device, + pcap_strlcpy(ireq.ifr_ifrn.ifrn_name, device, sizeof ireq.ifr_ifrn.ifrn_name); if (ioctl(sock_fd, SIOCGIWNAME, &ireq) >= 0) return 1; /* yes */ @@ -5976,7 +5976,7 @@ enter_rfmon_mode_wext(pcap_t *handle, int sock_fd, const char *device) * return EOPNOTSUPP. */ memset(&ireq, 0, sizeof ireq); - strlcpy(ireq.ifr_ifrn.ifrn_name, device, + pcap_strlcpy(ireq.ifr_ifrn.ifrn_name, device, sizeof ireq.ifr_ifrn.ifrn_name); ireq.u.data.pointer = (void *)args; ireq.u.data.length = 0; @@ -6176,7 +6176,7 @@ enter_rfmon_mode_wext(pcap_t *handle, int sock_fd, const char *device) /* * Get the old mode. */ - strlcpy(ireq.ifr_ifrn.ifrn_name, device, + pcap_strlcpy(ireq.ifr_ifrn.ifrn_name, device, sizeof ireq.ifr_ifrn.ifrn_name); if (ioctl(sock_fd, SIOCGIWMODE, &ireq) == -1) { /* @@ -6232,7 +6232,7 @@ enter_rfmon_mode_wext(pcap_t *handle, int sock_fd, const char *device) * If it fails, just fall back on SIOCSIWMODE. */ memset(&ireq, 0, sizeof ireq); - strlcpy(ireq.ifr_ifrn.ifrn_name, device, + pcap_strlcpy(ireq.ifr_ifrn.ifrn_name, device, sizeof ireq.ifr_ifrn.ifrn_name); ireq.u.data.length = 1; /* 1 argument */ args[0] = 3; /* request Prism header */ @@ -6264,7 +6264,7 @@ enter_rfmon_mode_wext(pcap_t *handle, int sock_fd, const char *device) * might get EBUSY. */ memset(&ifr, 0, sizeof(ifr)); - strlcpy(ifr.ifr_name, device, sizeof(ifr.ifr_name)); + pcap_strlcpy(ifr.ifr_name, device, sizeof(ifr.ifr_name)); if (ioctl(sock_fd, SIOCGIFFLAGS, &ifr) == -1) { pcap_fmt_errmsg_for_errno(handle->errbuf, PCAP_ERRBUF_SIZE, errno, "%s: Can't get flags", device); @@ -6285,7 +6285,7 @@ enter_rfmon_mode_wext(pcap_t *handle, int sock_fd, const char *device) /* * Then turn monitor mode on. */ - strlcpy(ireq.ifr_ifrn.ifrn_name, device, + pcap_strlcpy(ireq.ifr_ifrn.ifrn_name, device, sizeof ireq.ifr_ifrn.ifrn_name); ireq.u.mode = IW_MODE_MONITOR; if (ioctl(sock_fd, SIOCSIWMODE, &ireq) == -1) { @@ -6325,7 +6325,7 @@ enter_rfmon_mode_wext(pcap_t *handle, int sock_fd, const char *device) * Try to select the radiotap header. */ memset(&ireq, 0, sizeof ireq); - strlcpy(ireq.ifr_ifrn.ifrn_name, device, + pcap_strlcpy(ireq.ifr_ifrn.ifrn_name, device, sizeof ireq.ifr_ifrn.ifrn_name); args[0] = 3; /* request radiotap header */ memcpy(ireq.u.name, args, sizeof (int)); @@ -6336,7 +6336,7 @@ enter_rfmon_mode_wext(pcap_t *handle, int sock_fd, const char *device) * That failed. Try to select the AVS header. */ memset(&ireq, 0, sizeof ireq); - strlcpy(ireq.ifr_ifrn.ifrn_name, device, + pcap_strlcpy(ireq.ifr_ifrn.ifrn_name, device, sizeof ireq.ifr_ifrn.ifrn_name); args[0] = 2; /* request AVS header */ memcpy(ireq.u.name, args, sizeof (int)); @@ -6347,7 +6347,7 @@ enter_rfmon_mode_wext(pcap_t *handle, int sock_fd, const char *device) * That failed. Try to select the Prism header. */ memset(&ireq, 0, sizeof ireq); - strlcpy(ireq.ifr_ifrn.ifrn_name, device, + pcap_strlcpy(ireq.ifr_ifrn.ifrn_name, device, sizeof ireq.ifr_ifrn.ifrn_name); args[0] = 1; /* request Prism header */ memcpy(ireq.u.name, args, sizeof (int)); @@ -6365,7 +6365,7 @@ enter_rfmon_mode_wext(pcap_t *handle, int sock_fd, const char *device) * Select the Prism header. */ memset(&ireq, 0, sizeof ireq); - strlcpy(ireq.ifr_ifrn.ifrn_name, device, + pcap_strlcpy(ireq.ifr_ifrn.ifrn_name, device, sizeof ireq.ifr_ifrn.ifrn_name); args[0] = 3; /* request Prism header */ memcpy(ireq.u.name, args, sizeof (int)); @@ -6377,7 +6377,7 @@ enter_rfmon_mode_wext(pcap_t *handle, int sock_fd, const char *device) * Get the current channel. */ memset(&ireq, 0, sizeof ireq); - strlcpy(ireq.ifr_ifrn.ifrn_name, device, + pcap_strlcpy(ireq.ifr_ifrn.ifrn_name, device, sizeof ireq.ifr_ifrn.ifrn_name); if (ioctl(sock_fd, SIOCGIWFREQ, &ireq) == -1) { pcap_fmt_errmsg_for_errno(handle->errbuf, @@ -6391,7 +6391,7 @@ enter_rfmon_mode_wext(pcap_t *handle, int sock_fd, const char *device) * current value. */ memset(&ireq, 0, sizeof ireq); - strlcpy(ireq.ifr_ifrn.ifrn_name, device, + pcap_strlcpy(ireq.ifr_ifrn.ifrn_name, device, sizeof ireq.ifr_ifrn.ifrn_name); args[0] = 1; /* request Prism header */ args[1] = channel; /* set channel */ @@ -6405,7 +6405,7 @@ enter_rfmon_mode_wext(pcap_t *handle, int sock_fd, const char *device) * Prism header. */ memset(&ireq, 0, sizeof ireq); - strlcpy(ireq.ifr_ifrn.ifrn_name, device, + pcap_strlcpy(ireq.ifr_ifrn.ifrn_name, device, sizeof ireq.ifr_ifrn.ifrn_name); args[0] = 0; /* disallow transmitting */ memcpy(ireq.u.name, args, sizeof (int)); @@ -6417,7 +6417,7 @@ enter_rfmon_mode_wext(pcap_t *handle, int sock_fd, const char *device) * Force the Prism header. */ memset(&ireq, 0, sizeof ireq); - strlcpy(ireq.ifr_ifrn.ifrn_name, device, + pcap_strlcpy(ireq.ifr_ifrn.ifrn_name, device, sizeof ireq.ifr_ifrn.ifrn_name); args[0] = 1; /* request Prism header */ memcpy(ireq.u.name, args, sizeof (int)); @@ -6429,7 +6429,7 @@ enter_rfmon_mode_wext(pcap_t *handle, int sock_fd, const char *device) * Force the Prism header. */ memset(&ireq, 0, sizeof ireq); - strlcpy(ireq.ifr_ifrn.ifrn_name, device, + pcap_strlcpy(ireq.ifr_ifrn.ifrn_name, device, sizeof ireq.ifr_ifrn.ifrn_name); ireq.u.data.length = 1; /* 1 argument */ ireq.u.data.pointer = "1"; @@ -6442,7 +6442,7 @@ enter_rfmon_mode_wext(pcap_t *handle, int sock_fd, const char *device) * Force the Prism header. */ memset(&ireq, 0, sizeof ireq); - strlcpy(ireq.ifr_ifrn.ifrn_name, device, + pcap_strlcpy(ireq.ifr_ifrn.ifrn_name, device, sizeof ireq.ifr_ifrn.ifrn_name); args[0] = 1; /* request Prism header */ memcpy(ireq.u.name, args, sizeof (int)); @@ -6590,7 +6590,7 @@ iface_ethtool_get_ts_info(const char *device, pcap_t *handle, char *ebuf) } memset(&ifr, 0, sizeof(ifr)); - strlcpy(ifr.ifr_name, device, sizeof(ifr.ifr_name)); + pcap_strlcpy(ifr.ifr_name, device, sizeof(ifr.ifr_name)); memset(&info, 0, sizeof(info)); info.cmd = ETHTOOL_GET_TS_INFO; ifr.ifr_data = (caddr_t)&info; @@ -6726,7 +6726,7 @@ iface_ethtool_flag_ioctl(pcap_t *handle, int cmd, const char *cmdname, struct ethtool_value eval; memset(&ifr, 0, sizeof(ifr)); - strlcpy(ifr.ifr_name, handle->opt.device, sizeof(ifr.ifr_name)); + pcap_strlcpy(ifr.ifr_name, handle->opt.device, sizeof(ifr.ifr_name)); eval.cmd = cmd; eval.data = 0; ifr.ifr_data = (caddr_t)&eval; @@ -6890,7 +6890,7 @@ activate_old(pcap_t *handle) /* Bind to the given device */ if (strcmp(device, "any") == 0) { - strlcpy(handle->errbuf, "pcap_activate: The \"any\" device isn't supported on 2.0[.x]-kernel systems", + pcap_strlcpy(handle->errbuf, "pcap_activate: The \"any\" device isn't supported on 2.0[.x]-kernel systems", PCAP_ERRBUF_SIZE); return PCAP_ERROR; } @@ -6919,7 +6919,7 @@ activate_old(pcap_t *handle) if (handle->opt.promisc) { memset(&ifr, 0, sizeof(ifr)); - strlcpy(ifr.ifr_name, device, sizeof(ifr.ifr_name)); + pcap_strlcpy(ifr.ifr_name, device, sizeof(ifr.ifr_name)); if (ioctl(handle->fd, SIOCGIFFLAGS, &ifr) == -1) { pcap_fmt_errmsg_for_errno(handle->errbuf, PCAP_ERRBUF_SIZE, errno, "SIOCGIFFLAGS"); @@ -7056,7 +7056,7 @@ iface_bind_old(int fd, const char *device, char *ebuf) socklen_t errlen = sizeof(err); memset(&saddr, 0, sizeof(saddr)); - strlcpy(saddr.sa_data, device, sizeof(saddr.sa_data)); + pcap_strlcpy(saddr.sa_data, device, sizeof(saddr.sa_data)); if (bind(fd, &saddr, sizeof(saddr)) == -1) { pcap_fmt_errmsg_for_errno(ebuf, PCAP_ERRBUF_SIZE, errno, "bind"); @@ -7095,7 +7095,7 @@ iface_get_mtu(int fd, const char *device, char *ebuf) return BIGGER_THAN_ALL_MTUS; memset(&ifr, 0, sizeof(ifr)); - strlcpy(ifr.ifr_name, device, sizeof(ifr.ifr_name)); + pcap_strlcpy(ifr.ifr_name, device, sizeof(ifr.ifr_name)); if (ioctl(fd, SIOCGIFMTU, &ifr) == -1) { pcap_fmt_errmsg_for_errno(ebuf, PCAP_ERRBUF_SIZE, @@ -7115,7 +7115,7 @@ iface_get_arptype(int fd, const char *device, char *ebuf) struct ifreq ifr; memset(&ifr, 0, sizeof(ifr)); - strlcpy(ifr.ifr_name, device, sizeof(ifr.ifr_name)); + pcap_strlcpy(ifr.ifr_name, device, sizeof(ifr.ifr_name)); if (ioctl(fd, SIOCGIFHWADDR, &ifr) == -1) { pcap_fmt_errmsg_for_errno(ebuf, PCAP_ERRBUF_SIZE, @@ -299,7 +299,7 @@ int pcap_findalldevs_ex(char *source, struct pcap_rmtauth *auth, pcap_if_t **all return -1; } - strlcpy(dev->name, tmpstring, stringlen); + pcap_strlcpy(dev->name, tmpstring, stringlen); dev->name[stringlen] = 0; @@ -321,7 +321,7 @@ int pcap_findalldevs_ex(char *source, struct pcap_rmtauth *auth, pcap_if_t **all } /* Copy the new device description into the correct memory location */ - strlcpy(dev->description, tmpstring, stringlen + 1); + pcap_strlcpy(dev->description, tmpstring, stringlen + 1); pcap_close(fp); } @@ -345,7 +345,7 @@ int pcap_findalldevs_ex(char *source, struct pcap_rmtauth *auth, pcap_if_t **all return pcap_findalldevs_ex_remote(source, auth, alldevs, errbuf); default: - strlcpy(errbuf, "Source type not supported", PCAP_ERRBUF_SIZE); + pcap_strlcpy(errbuf, "Source type not supported", PCAP_ERRBUF_SIZE); return -1; } } @@ -389,7 +389,7 @@ pcap_t *pcap_open(const char *source, int snaplen, int flags, int read_timeout, return pcap_open_rpcap(source, snaplen, flags, read_timeout, auth, errbuf); default: - strlcpy(errbuf, "Source type not supported", PCAP_ERRBUF_SIZE); + pcap_strlcpy(errbuf, "Source type not supported", PCAP_ERRBUF_SIZE); return NULL; } @@ -1316,7 +1316,7 @@ pcap_setfilter_win32_dag(pcap_t *p, struct bpf_program *fp) { if(!fp) { - strlcpy(p->errbuf, "setfilter: No filter specified", sizeof(p->errbuf)); + pcap_strlcpy(p->errbuf, "setfilter: No filter specified", sizeof(p->errbuf)); return (-1); } diff --git a/pcap-null.c b/pcap-null.c index 92a5e2d8..a0851480 100644 --- a/pcap-null.c +++ b/pcap-null.c @@ -32,7 +32,7 @@ static char nosup[] = "live packet capture not supported on this system"; pcap_t * pcap_create_interface(const char *device _U_, char *ebuf) { - (void)strlcpy(ebuf, nosup, PCAP_ERRBUF_SIZE); + (void)pcap_strlcpy(ebuf, nosup, PCAP_ERRBUF_SIZE); return (NULL); } @@ -50,7 +50,7 @@ int pcap_lookupnet(const char *device _U_, bpf_u_int32 *netp _U_, bpf_u_int32 *maskp _U_, char *errbuf) { - (void)strlcpy(errbuf, nosup, PCAP_ERRBUF_SIZE); + (void)pcap_strlcpy(errbuf, nosup, PCAP_ERRBUF_SIZE); return (-1); } #endif diff --git a/pcap-rpcap.c b/pcap-rpcap.c index a35eaf24..a62296d6 100644 --- a/pcap-rpcap.c +++ b/pcap-rpcap.c @@ -2528,7 +2528,7 @@ pcap_findalldevs_ex_remote(char *source, struct pcap_rmtauth *auth, pcap_if_t ** } /* Copy the new device name into the correct memory location */ - strlcpy(dev->name, tmpstring2, stringlen + 1); + pcap_strlcpy(dev->name, tmpstring2, stringlen + 1); } if (findalldevs_if.desclen) @@ -2561,7 +2561,7 @@ pcap_findalldevs_ex_remote(char *source, struct pcap_rmtauth *auth, pcap_if_t ** } /* Copy the new device description into the correct memory location */ - strlcpy(dev->description, tmpstring2, stringlen + 1); + pcap_strlcpy(dev->description, tmpstring2, stringlen + 1); } dev->flags = ntohl(findalldevs_if.flags); @@ -2983,7 +2983,7 @@ int pcap_remoteact_list(char *hostlist, char sep, int size, char *errbuf) return -1; } - strlcat(hostlist, hoststr, PCAP_ERRBUF_SIZE); + pcap_strlcat(hostlist, hoststr, PCAP_ERRBUF_SIZE); hostlist[len - 1] = sep; hostlist[len] = 0; diff --git a/pcap-septel.c b/pcap-septel.c index c8ea8eaa..beb1cb38 100644 --- a/pcap-septel.c +++ b/pcap-septel.c @@ -182,7 +182,7 @@ loop: static int septel_inject(pcap_t *handle, const void *buf _U_, int size _U_) { - strlcpy(handle->errbuf, "Sending packets isn't supported on Septel cards", + pcap_strlcpy(handle->errbuf, "Sending packets isn't supported on Septel cards", PCAP_ERRBUF_SIZE); return (-1); } diff --git a/pcap-sita.c b/pcap-sita.c index 4a1db8e1..a12aa5a3 100644 --- a/pcap-sita.c +++ b/pcap-sita.c @@ -884,7 +884,7 @@ static void acn_start_monitor(int fd, int snaplen, int timeout, int promiscuous, } static int pcap_inject_acn(pcap_t *p, const void *buf _U_, int size _U_) { - strlcpy(p->errbuf, "Sending packets isn't supported on ACN adapters", + pcap_strlcpy(p->errbuf, "Sending packets isn't supported on ACN adapters", PCAP_ERRBUF_SIZE); return (-1); } @@ -237,7 +237,7 @@ snf_inject(pcap_t *p, const void *buf _U_, int size _U_) return (-1); } #else - strlcpy(p->errbuf, "Sending packets isn't supported with this snf version", + pcap_strlcpy(p->errbuf, "Sending packets isn't supported with this snf version", PCAP_ERRBUF_SIZE); return (-1); #endif diff --git a/pcap-usb-linux.c b/pcap-usb-linux.c index e86a3afd..9787eab0 100644 --- a/pcap-usb-linux.c +++ b/pcap-usb-linux.c @@ -279,7 +279,7 @@ usb_findalldevs(pcap_if_list_t *devlistp, char *err_str) * Split LINUX_USB_MON_DEV into a directory that we'll * scan and a file name prefix that we'll check for. */ - strlcpy(usb_mon_dir, LINUX_USB_MON_DEV, sizeof usb_mon_dir); + pcap_strlcpy(usb_mon_dir, LINUX_USB_MON_DEV, sizeof usb_mon_dir); usb_mon_prefix = strrchr(usb_mon_dir, '/'); if (usb_mon_prefix == NULL) { /* @@ -655,7 +655,7 @@ get_if_description(const char *name) * Get the description for the interface. */ memset(&ifrdesc, 0, sizeof ifrdesc); - strlcpy(ifrdesc.ifr_name, name, sizeof ifrdesc.ifr_name); + pcap_strlcpy(ifrdesc.ifr_name, name, sizeof ifrdesc.ifr_name); s = socket(AF_INET, SOCK_DGRAM, 0); if (s >= 0) { #ifdef __FreeBSD__ @@ -1288,14 +1288,14 @@ pcap_lookupdev(char *errbuf) * on the list, there aren't any non-loopback devices, * so why not just supply it as the default device? */ - (void)strlcpy(errbuf, "no suitable device found", + (void)pcap_strlcpy(errbuf, "no suitable device found", PCAP_ERRBUF_SIZE); ret = NULL; } else { /* * Return the name of the first device on the list. */ - (void)strlcpy(device, alldevs->name, sizeof(device)); + (void)pcap_strlcpy(device, alldevs->name, sizeof(device)); ret = device; } @@ -1362,7 +1362,7 @@ pcap_lookupnet(const char *device, bpf_u_int32 *netp, bpf_u_int32 *maskp, /* XXX Work around Linux kernel bug */ ifr.ifr_addr.sa_family = AF_INET; #endif - (void)strlcpy(ifr.ifr_name, device, sizeof(ifr.ifr_name)); + (void)pcap_strlcpy(ifr.ifr_name, device, sizeof(ifr.ifr_name)); if (ioctl(fd, SIOCGIFADDR, (char *)&ifr) < 0) { if (errno == EADDRNOTAVAIL) { (void)pcap_snprintf(errbuf, PCAP_ERRBUF_SIZE, @@ -1381,7 +1381,7 @@ pcap_lookupnet(const char *device, bpf_u_int32 *netp, bpf_u_int32 *maskp, /* XXX Work around Linux kernel bug */ ifr.ifr_addr.sa_family = AF_INET; #endif - (void)strlcpy(ifr.ifr_name, device, sizeof(ifr.ifr_name)); + (void)pcap_strlcpy(ifr.ifr_name, device, sizeof(ifr.ifr_name)); if (ioctl(fd, SIOCGIFNETMASK, (char *)&ifr) < 0) { pcap_fmt_errmsg_for_errno(errbuf, PCAP_ERRBUF_SIZE, errno, "SIOCGIFNETMASK: %s", device); @@ -1801,9 +1801,9 @@ pcap_createsrcstr(char *source, int type, const char *host, const char *port, switch (type) { case PCAP_SRC_FILE: - strlcpy(source, PCAP_SRC_FILE_STRING, PCAP_BUF_SIZE); + pcap_strlcpy(source, PCAP_SRC_FILE_STRING, PCAP_BUF_SIZE); if (name != NULL && *name != '\0') { - strlcat(source, name, PCAP_BUF_SIZE); + pcap_strlcat(source, name, PCAP_BUF_SIZE); return (0); } else { pcap_snprintf(errbuf, PCAP_ERRBUF_SIZE, @@ -1812,7 +1812,7 @@ pcap_createsrcstr(char *source, int type, const char *host, const char *port, } case PCAP_SRC_IFREMOTE: - strlcpy(source, PCAP_SRC_IF_STRING, PCAP_BUF_SIZE); + pcap_strlcpy(source, PCAP_SRC_IF_STRING, PCAP_BUF_SIZE); if (host != NULL && *host != '\0') { if (strchr(host, ':') != NULL) { /* @@ -1820,18 +1820,18 @@ pcap_createsrcstr(char *source, int type, const char *host, const char *port, * probably an IPv6 address, and needs to * be included in square brackets. */ - strlcat(source, "[", PCAP_BUF_SIZE); - strlcat(source, host, PCAP_BUF_SIZE); - strlcat(source, "]", PCAP_BUF_SIZE); + pcap_strlcat(source, "[", PCAP_BUF_SIZE); + pcap_strlcat(source, host, PCAP_BUF_SIZE); + pcap_strlcat(source, "]", PCAP_BUF_SIZE); } else - strlcat(source, host, PCAP_BUF_SIZE); + pcap_strlcat(source, host, PCAP_BUF_SIZE); if (port != NULL && *port != '\0') { - strlcat(source, ":", PCAP_BUF_SIZE); - strlcat(source, port, PCAP_BUF_SIZE); + pcap_strlcat(source, ":", PCAP_BUF_SIZE); + pcap_strlcat(source, port, PCAP_BUF_SIZE); } - strlcat(source, "/", PCAP_BUF_SIZE); + pcap_strlcat(source, "/", PCAP_BUF_SIZE); } else { pcap_snprintf(errbuf, PCAP_ERRBUF_SIZE, "The host name cannot be NULL."); @@ -1839,15 +1839,15 @@ pcap_createsrcstr(char *source, int type, const char *host, const char *port, } if (name != NULL && *name != '\0') - strlcat(source, name, PCAP_BUF_SIZE); + pcap_strlcat(source, name, PCAP_BUF_SIZE); return (0); case PCAP_SRC_IFLOCAL: - strlcpy(source, PCAP_SRC_IF_STRING, PCAP_BUF_SIZE); + pcap_strlcpy(source, PCAP_SRC_IF_STRING, PCAP_BUF_SIZE); if (name != NULL && *name != '\0') - strlcat(source, name, PCAP_BUF_SIZE); + pcap_strlcat(source, name, PCAP_BUF_SIZE); return (0); @@ -1886,7 +1886,7 @@ pcap_parsesrcstr(const char *source, int *type, char *host, char *port, * Local device. */ if (name && tmppath) - strlcpy(name, tmppath, PCAP_BUF_SIZE); + pcap_strlcpy(name, tmppath, PCAP_BUF_SIZE); if (type) *type = PCAP_SRC_IFLOCAL; free(tmppath); @@ -1908,12 +1908,12 @@ pcap_parsesrcstr(const char *source, int *type, char *host, char *port, pcap_snprintf(host, PCAP_BUF_SIZE, "%s@%s", tmpuserinfo, tmphost); else - strlcpy(host, tmphost, PCAP_BUF_SIZE); + pcap_strlcpy(host, tmphost, PCAP_BUF_SIZE); } if (port && tmpport) - strlcpy(port, tmpport, PCAP_BUF_SIZE); + pcap_strlcpy(port, tmpport, PCAP_BUF_SIZE); if (name && tmppath) - strlcpy(name, tmppath, PCAP_BUF_SIZE); + pcap_strlcpy(name, tmppath, PCAP_BUF_SIZE); if (type) *type = PCAP_SRC_IFREMOTE; free(tmppath); @@ -1929,7 +1929,7 @@ pcap_parsesrcstr(const char *source, int *type, char *host, char *port, * file:// */ if (name && tmppath) - strlcpy(name, tmppath, PCAP_BUF_SIZE); + pcap_strlcpy(name, tmppath, PCAP_BUF_SIZE); if (type) *type = PCAP_SRC_FILE; free(tmppath); @@ -1945,7 +1945,7 @@ pcap_parsesrcstr(const char *source, int *type, char *host, char *port, * as a local device. */ if (name) - strlcpy(name, source, PCAP_BUF_SIZE); + pcap_strlcpy(name, source, PCAP_BUF_SIZE); if (type) *type = PCAP_SRC_IFLOCAL; free(tmppath); @@ -3163,7 +3163,7 @@ pcap_getnonblock(pcap_t *p, char *errbuf) * We copy the error message to errbuf, so callers * can find it in either place. */ - strlcpy(errbuf, p->errbuf, PCAP_ERRBUF_SIZE); + pcap_strlcpy(errbuf, p->errbuf, PCAP_ERRBUF_SIZE); } return (ret); } @@ -3207,7 +3207,7 @@ pcap_setnonblock(pcap_t *p, int nonblock, char *errbuf) * We copy the error message to errbuf, so callers * can find it in either place. */ - strlcpy(errbuf, p->errbuf, PCAP_ERRBUF_SIZE); + pcap_strlcpy(errbuf, p->errbuf, PCAP_ERRBUF_SIZE); } return (ret); } @@ -3343,7 +3343,7 @@ pcap_strerror(int errnum) errno_t err = strerror_s(errbuf, PCAP_ERRBUF_SIZE, errnum); if (err != 0) /* err = 0 if successful */ - strlcpy(errbuf, "strerror_s() error", PCAP_ERRBUF_SIZE); + pcap_strlcpy(errbuf, "strerror_s() error", PCAP_ERRBUF_SIZE); return (errbuf); #else return (strerror(errnum)); @@ -3565,7 +3565,7 @@ pcap_do_addexit(pcap_t *p) /* * "atexit()" failed; let our caller know. */ - strlcpy(p->errbuf, "atexit failed", PCAP_ERRBUF_SIZE); + pcap_strlcpy(p->errbuf, "atexit failed", PCAP_ERRBUF_SIZE); return (0); } did_atexit = 1; diff --git a/portability.h b/portability.h index 6786d570..47c9f470 100644 --- a/portability.h +++ b/portability.h @@ -45,46 +45,40 @@ extern "C" { #endif -#ifndef HAVE_STRLCPY - /* - * Macro that does the same thing as strlcpy(). - */ - #if defined(_MSC_VER) || defined(__MINGW32__) - /* - * strncpy_s() is supported at least back to Visual - * Studio 2005. - */ - #define strlcpy(x, y, z) \ - strncpy_s((x), (z), (y), _TRUNCATE) - - #else - #define strlcpy(x, y, z) \ - (strncpy((x), (y), (z)), \ - ((z) <= 0 ? 0 : ((x)[(z) - 1] = '\0')), \ - (void) strlen((y))) - #endif +#ifdef HAVE_STRLCAT + #define pcap_strlcat strlcat +#else + #if defined(_MSC_VER) || defined(__MINGW32__) + /* + * strncat_s() is supported at least back to Visual + * Studio 2005. + */ + #define pcap_strlcat(x, y, z) \ + strncat_s((x), (z), (y), _TRUNCATE) + #else + /* + * Define it ourselves. + */ + extern size_t pcap_strlcat(char * restrict dst, const char * restrict src, size_t dstsize); + #endif #endif -#ifndef HAVE_STRLCAT - /* - * Macro that does the same thing as strlcat(). - */ - #if defined(_MSC_VER) || defined(__MINGW32__) - /* - * strncat_s() is supported at least back to Visual - * Studio 2005. - */ - #define strlcat(x, y, z) \ - strncat_s((x), (z), (y), _TRUNCATE) - #else - /* - * ANSI C says strncat() always null-terminates its first argument, - * so 1) we don't need to explicitly null-terminate the string - * ourselves and 2) we need to leave room for the null terminator. - */ - #define strlcat(x, y, z) \ - strncat((x), (y), (z) - strlen((x)) - 1) - #endif +#ifdef HAVE_STRLCPY + #define pcap_strlcpy strlcpy +#else + #if defined(_MSC_VER) || defined(__MINGW32__) + /* + * strncpy_s() is supported at least back to Visual + * Studio 2005. + */ + #define pcap_strlcpy(x, y, z) \ + strncpy_s((x), (z), (y), _TRUNCATE) + #else + /* + * Define it ourselves. + */ + extern size_t pcap_strlcpy(char * restrict dst, const char * restrict src, size_t dstsize); + #endif #endif #ifdef _MSC_VER @@ -148,7 +142,6 @@ extern int pcap_vsnprintf(char *, size_t, const char *, va_list ap); /* * Define it ourselves. */ - #define NEED_STRTOK_R extern char *pcap_strtok_r(char *, const char *, char **); #endif #endif /* HAVE_STRTOK_R */ diff --git a/rpcapd/fileconf.c b/rpcapd/fileconf.c index 8a35a7b9..0f02f4eb 100644 --- a/rpcapd/fileconf.c +++ b/rpcapd/fileconf.c @@ -315,7 +315,7 @@ void fileconf_read(void) // it. // *ptr++ = '\0'; - result = strlcpy(activelist[num_active_clients].address, address, sizeof(activelist[num_active_clients].address)); + result = pcap_strlcpy(activelist[num_active_clients].address, address, sizeof(activelist[num_active_clients].address)); if (result >= sizeof(activelist[num_active_clients].address)) { // @@ -328,9 +328,9 @@ void fileconf_read(void) continue; } if (strcmp(port, "DEFAULT") == 0) // the user choose a custom port - result = strlcpy(activelist[num_active_clients].port, RPCAP_DEFAULT_NETPORT_ACTIVE, sizeof(activelist[num_active_clients].port)); + result = pcap_strlcpy(activelist[num_active_clients].port, RPCAP_DEFAULT_NETPORT_ACTIVE, sizeof(activelist[num_active_clients].port)); else - result = strlcpy(activelist[num_active_clients].port, port, sizeof(activelist[num_active_clients].port)); + result = pcap_strlcpy(activelist[num_active_clients].port, port, sizeof(activelist[num_active_clients].port)); if (result >= sizeof(activelist[num_active_clients].address)) { // @@ -390,7 +390,7 @@ void fileconf_read(void) // The list is not empty, so prepend // a comma before adding this host. // - result = strlcat(hostlist, ",", sizeof(hostlist)); + result = pcap_strlcat(hostlist, ",", sizeof(hostlist)); if (result >= sizeof(hostlist)) { // @@ -406,7 +406,7 @@ void fileconf_read(void) continue; } } - result = strlcat(hostlist, host, sizeof(hostlist)); + result = pcap_strlcat(hostlist, host, sizeof(hostlist)); if (result >= sizeof(hostlist)) { // diff --git a/rpcapd/rpcapd.c b/rpcapd/rpcapd.c index e8b3b1d6..6ad922ec 100644 --- a/rpcapd/rpcapd.c +++ b/rpcapd/rpcapd.c @@ -241,12 +241,12 @@ int main(int argc, char *argv[]) { tmpport = pcap_strtok_r(NULL, RPCAP_HOSTLIST_SEP, &lasts); - strlcpy(activelist[i].address, tmpaddress, MAX_LINE); + pcap_strlcpy(activelist[i].address, tmpaddress, MAX_LINE); if ((tmpport == NULL) || (strcmp(tmpport, "DEFAULT") == 0)) // the user choose a custom port - strlcpy(activelist[i].port, RPCAP_DEFAULT_NETPORT_ACTIVE, MAX_LINE); + pcap_strlcpy(activelist[i].port, RPCAP_DEFAULT_NETPORT_ACTIVE, MAX_LINE); else - strlcpy(activelist[i].port, tmpport, MAX_LINE); + pcap_strlcpy(activelist[i].port, tmpport, MAX_LINE); tmpaddress = pcap_strtok_r(NULL, RPCAP_HOSTLIST_SEP, &lasts); @@ -261,10 +261,10 @@ int main(int argc, char *argv[]) break; } case 'f': - strlcpy(loadfile, optarg, MAX_LINE); + pcap_strlcpy(loadfile, optarg, MAX_LINE); break; case 's': - strlcpy(savefile, optarg, MAX_LINE); + pcap_strlcpy(savefile, optarg, MAX_LINE); break; case 'h': printusage(); @@ -179,7 +179,7 @@ sf_oid_set_request(pcap_t *p, bpf_u_int32 oid _U_, const void *data _U_, static u_int sf_sendqueue_transmit(pcap_t *p, pcap_send_queue *queue, int sync) { - strlcpy(p->errbuf, "Sending packets isn't supported on savefiles", + pcap_strlcpy(p->errbuf, "Sending packets isn't supported on savefiles", PCAP_ERRBUF_SIZE); return (0); } @@ -218,7 +218,7 @@ sf_get_airpcap_handle(pcap_t *pcap) static int sf_inject(pcap_t *p, const void *buf _U_, int size _U_) { - strlcpy(p->errbuf, "Sending packets isn't supported on savefiles", + pcap_strlcpy(p->errbuf, "Sending packets isn't supported on savefiles", PCAP_ERRBUF_SIZE); return (-1); } diff --git a/sockutils.c b/sockutils.c index d2ceaaba..4bb97a71 100644 --- a/sockutils.c +++ b/sockutils.c @@ -1385,7 +1385,7 @@ int sock_getascii_addrport(const struct sockaddr_storage *sockaddr, char *addres (memcmp(&((struct sockaddr_in6 *) sockaddr)->sin6_addr, "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0", sizeof(struct in6_addr)) == 0)) { if (address) - strlcpy(address, SOCKET_NAME_NULL_DAD, addrlen); + pcap_strlcpy(address, SOCKET_NAME_NULL_DAD, addrlen); return retval; } } @@ -1401,13 +1401,13 @@ int sock_getascii_addrport(const struct sockaddr_storage *sockaddr, char *addres if (address) { - strlcpy(address, SOCKET_NO_NAME_AVAILABLE, addrlen); + pcap_strlcpy(address, SOCKET_NO_NAME_AVAILABLE, addrlen); address[addrlen - 1] = 0; } if (port) { - strlcpy(port, SOCKET_NO_PORT_AVAILABLE, portlen); + pcap_strlcpy(port, SOCKET_NO_PORT_AVAILABLE, portlen); port[portlen - 1] = 0; } |