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)
missing/getopt.c \
missing/getopt.h \
missing/snprintf.c \
+ missing/strlcat.c \
+ missing/strlcpy.c \
missing/strtok_r.c \
missing/win_snprintf.c \
mkdep \
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
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"
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 :
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,,
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])
size_t n = strlen(s) + 1;
char *cp = newchunk(cstate, n);
- strlcpy(cp, s, n);
+ pcap_strlcpy(cp, s, n);
return (cp);
}
--- /dev/null
+/* $OpenBSD: pcap_strlcat.c,v 1.15 2015/03/02 21:41:08 millert Exp $ */
+
+/*
+ *
+ * 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 */
+}
--- /dev/null
+/* $OpenBSD: pcap_strlcpy.c,v 1.12 2015/01/15 03:54:12 millert Exp $ */
+
+/*
+ *
+ * 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 */
+}
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?
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);
*/
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) {
/*
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,
*/
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) {
/*
* 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,
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);
}
* 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 */
*/
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;
* 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);
* 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 */
*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);
*minorp = 0;
*microp = 0;
if (sysinfo(SI_RELEASE, buf, bufsize) < 0) {
- strlcpy(buf, "?", bufsize);
+ pcap_strlcpy(buf, "?", bufsize);
return;
}
cp = buf;
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);
}
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;
* 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,
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)
/*
* 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) {
/*
* 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,
*/
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) {
/*
* 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) {
/*
* 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);
* 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);
/*
* 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 */
#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) {
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;
}
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;
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) {
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,
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 */
* 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;
/*
* 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) {
/*
* 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 */
* 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);
/*
* 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) {
* 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));
* 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));
* 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));
* 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));
* 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,
* 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 */
* 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));
* 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));
* 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";
* 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));
}
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;
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;
/* 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;
}
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");
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");
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,
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,
return -1;
}
- strlcpy(dev->name, tmpstring, stringlen);
+ pcap_strlcpy(dev->name, tmpstring, stringlen);
dev->name[stringlen] = 0;
}
/* 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);
}
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;
}
}
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;
}
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);
}
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);
}
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
}
/* 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)
}
/* 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);
return -1;
}
- strlcat(hostlist, hoststr, PCAP_ERRBUF_SIZE);
+ pcap_strlcat(hostlist, hoststr, PCAP_ERRBUF_SIZE);
hostlist[len - 1] = sep;
hostlist[len] = 0;
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);
}
}
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);
}
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
* 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) {
/*
* 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__
* 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;
}
/* 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,
/* 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);
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,
}
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) {
/*
* 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.");
}
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);
* 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);
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);
* 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);
* 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);
* 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);
}
* 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);
}
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));
/*
* "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;
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
/*
* Define it ourselves.
*/
- #define NEED_STRTOK_R
extern char *pcap_strtok_r(char *, const char *, char **);
#endif
#endif /* HAVE_STRTOK_R */
// 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))
{
//
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))
{
//
// 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))
{
//
continue;
}
}
- result = strlcat(hostlist, host, sizeof(hostlist));
+ result = pcap_strlcat(hostlist, host, sizeof(hostlist));
if (result >= sizeof(hostlist))
{
//
{
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);
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();
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);
}
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);
}
(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;
}
}
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;
}