for (ifr = ifc.ifc_req; ifr < ifend; ifr = NEXTIFR(ifr) ) {
if (ifr->ifr_addr.sa_family != AF_INET)
continue;
- strncpy(ifreq.ifr_name, ifr->ifr_name,
+ strlcpy(ifreq.ifr_name, ifr->ifr_name,
sizeof(ifreq.ifr_name));
ifreq.ifr_addr = ifr->ifr_addr;
/*
* set clocking interface or bandwidth value
*/
if (av[0][0] >= 'a' && av[0][0] <= 'z') {
- int l = sizeof(p.if_name)-1;
/* interface name */
- strncpy(p.if_name, av[0], l);
- p.if_name[l] = '\0';
+ strlcpy(p.if_name, av[0], sizeof(p.if_name));
p.bandwidth = 0;
} else {
p.if_name[0] = '\0';
exit(-1);
}
- strncpy(source, InetAddress(sourceIP), sizeof(source) - 1);
- strncpy(target, InetAddress(targetIP), sizeof(target) - 1);
+ strlcpy(source, InetAddress(sourceIP), sizeof(source));
+ strlcpy(target, InetAddress(targetIP), sizeof(target));
/* Setup initial filter */
sprintf(filtercmds,
extern struct TcpSession session;
void usage (char *name);
-int GetCannonicalInfo(char *string, u_int32_t *address);
+int GetCannonicalInfo(char *string, size_t str_size, u_int32_t *address);
int BindTcpPort(int sockfd) ;
void usage(char *name)
exit(-1);
}
-int GetCannonicalInfo(char *string, u_int32_t *address)
+int GetCannonicalInfo(char *string, size_t str_size, u_int32_t *address)
{
struct hostent *hp;
/* Is string in dotted decimal format? */
"RETURN CODE: %d\n", string, FAIL);
return(-1);
} else {
- strncpy(string, hp->h_name, MAXHOSTNAMELEN-1);
+ strlcpy(string, hp->h_name, str_size);
memcpy((void *)address, (void *)hp->h_addr,
hp->h_length);
}
" name for %s\nRETURN CODE: %d",
string, NO_SRC_CANON_INFO);
}
- /* strncpy(name, string, MAXHOSTNAMELEN - 1);*/
+ /* strlcpy(name, string, MAXHOSTNAMELEN);*/
} else {
- /* strncpy(name, hp->h_name, MAXHOSTNAMELEN - 1);*/
+ /* strlcpy(name, hp->h_name, MAXHOSTNAMELEN);*/
}
}
return(0);
printf("Target host name too long, max %u chars\n", MAXHOSTNAMELEN);
Quit(FAIL);
}
- strncpy(session.targetHostName, optarg,
- MAXHOSTNAMELEN);
- strncpy(session.targetName, session.targetHostName,
- MAXHOSTNAMELEN);
+ strlcpy(session.targetHostName, optarg,
+ sizeof(session.targetHostName));
+ strlcpy(session.targetName, session.targetHostName,
+ sizeof(session.targetName));
break;
case 'p':
targetPort = atoi(optarg);
printf("Source host name too long, max %u chars\n", MAXHOSTNAMELEN);
Quit(FAIL);
}
- strncpy(session.sourceHostName, optarg,
+ strlcpy(session.sourceHostName, optarg,
MAXHOSTNAMELEN);
break;
case 'd':
Quit(FAIL);
}
bzero(dev, sizeof(dev));
- strncpy(dev, optarg, (sizeof(dev) - 1));
+ strlcpy(dev, optarg, sizeof(dev));
usedev = 1;
break;
case 'f':
signal(SIGINT, SigHandle);
signal(SIGHUP, SigHandle);
- if (GetCannonicalInfo(session.targetHostName, &targetIpAddress) < 0)
+ if (GetCannonicalInfo(session.targetHostName, sizeof(session.targetHostName),
+ &targetIpAddress) < 0)
{
printf("Failed to convert targetIP address\n");
Quit(NO_TARGET_CANON_INFO);
}
- /*
- if (GetCannonicalInfo(session.sourceHostName, &sourceIpAddress) < 0)
- {
- printf("Failed to convert source IP address\n");
- Quit(NO_TARGET_CANON_INFO);
- }
- */
rc = getifaddrs(&ifap);
if (rc != 0 || ifap == NULL) {
printf("Failed to get source addresswith getifaddrs: %d\n", rc);
if (strcmp(dev, tmp->ifa_name) == 0) {
sin = (struct sockaddr_in *)tmp->ifa_addr;
sourceIpAddress = sin->sin_addr.s_addr;
- strncpy(session.sourceHostName,
+ strlcpy(session.sourceHostName,
inet_ntoa(sin->sin_addr),
- MAXHOSTNAMELEN);
+ sizeof(session.sourceHostName));
} else {
continue;
}
bzero(dev, sizeof(dev));
sin = (struct sockaddr_in *)tmp->ifa_addr;
sourceIpAddress = sin->sin_addr.s_addr;
- strncpy(session.sourceHostName,
+ strlcpy(session.sourceHostName,
inet_ntoa(sin->sin_addr),
- MAXHOSTNAMELEN);
- strncpy(dev, tmp->ifa_name, sizeof(dev));
+ sizeof(session.sourceHostName));
+ strlcpy(dev, tmp->ifa_name, sizeof(dev));
}
}
freeifaddrs(ifap);
const struct sockaddr *sa = (const struct sockaddr *) &ifr.ifr_addr;
memset(&ifr, 0, sizeof(ifr));
- strncpy(ifr.ifr_name, name, IFNAMSIZ);
+ strlcpy(ifr.ifr_name, name, sizeof(ifr.ifr_name));
if (ioctl(s, SIOCGIFPSRCADDR, (caddr_t)&ifr) < 0)
return;
struct ifaliasreq addreq;
memset(&addreq, 0, sizeof(addreq));
- strncpy(addreq.ifra_name, name, IFNAMSIZ);
+ strlcpy(addreq.ifra_name, name, sizeof(addreq.ifra_name));
memcpy(&addreq.ifra_addr, srcres->ai_addr, srcres->ai_addr->sa_len);
memcpy(&addreq.ifra_dstaddr, dstres->ai_addr, dstres->ai_addr->sa_len);
struct ifreq ifr;
bzero(&ifr, sizeof (ifr));
- strncpy(ifr.ifr_name, name, IFNAMSIZ);
+ strlcpy(ifr.ifr_name, name, sizeof(ifr.ifr_name));
ifr.ifr_intval = enable;
if (ioctl(s, SIOCSETROUTERMODE, &ifr) < 0)
int error;
memset(&nd, 0, sizeof(nd));
- strncpy(nd.ifname, ifr.ifr_name, sizeof(nd.ifname));
+ strlcpy(nd.ifname, ifr.ifr_name, sizeof(nd.ifname));
error = ioctl(s, SIOCGIFINFO_IN6, &nd);
if (error) {
warn("ioctl(SIOCGIFINFO_IN6)");
if (sin == NULL)
return;
- strncpy(ifr6.ifr_name, ifr.ifr_name, sizeof(ifr.ifr_name));
+ strlcpy(ifr6.ifr_name, ifr.ifr_name, sizeof(ifr.ifr_name));
if ((s6 = socket(AF_INET6, SOCK_DGRAM, 0)) < 0) {
warn("socket(AF_INET6,SOCK_DGRAM)");
return;
const struct sockaddr *sa = (const struct sockaddr *) &in6_ifr.ifr_addr;
memset(&in6_ifr, 0, sizeof(in6_ifr));
- strncpy(in6_ifr.ifr_name, name, IFNAMSIZ);
+ strlcpy(in6_ifr.ifr_name, name, sizeof(in6_ifr.ifr_name));
if (ioctl(s, SIOCGIFPSRCADDR_IN6, (caddr_t)&in6_ifr) < 0)
return;
int error;
memset(&nd, 0, sizeof(nd));
- strncpy(nd.ifname, ifr.ifr_name, sizeof(nd.ifname));
+ strlcpy(nd.ifname, ifr.ifr_name, sizeof(nd.ifname));
if ((s6 = socket(AF_INET6, SOCK_DGRAM, 0)) < 0) {
if (errno != EPROTONOSUPPORT)
warn("socket(AF_INET6, SOCK_DGRAM)");
struct in6_aliasreq in6_addreq;
memset(&in6_addreq, 0, sizeof(in6_addreq));
- strncpy(in6_addreq.ifra_name, name, IFNAMSIZ);
+ strlcpy(in6_addreq.ifra_name, name, sizeof(in6_addreq.ifra_name));
memcpy(&in6_addreq.ifra_addr, srcres->ai_addr, srcres->ai_addr->sa_len);
memcpy(&in6_addreq.ifra_dstaddr, dstres->ai_addr,
dstres->ai_addr->sa_len);
struct ifreq ifr;
bzero(&ifr, sizeof (ifr));
- strncpy(ifr.ifr_name, name, IFNAMSIZ);
+ strlcpy(ifr.ifr_name, name, sizeof(ifr.ifr_name));
ifr.ifr_intval = enable;
if (ioctl(s, SIOCSETROUTERMODE_IN6, &ifr) < 0)
--- /dev/null
+/*
+ * Copyright (c) 2017-2018 Apple Inc. All rights reserved.
+ *
+ * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
+ *
+ * This file contains Original Code and/or Modifications of Original Code
+ * as defined in and that are subject to the Apple Public Source License
+ * Version 2.0 (the 'License'). You may not use this file except in
+ * compliance with the License. The rights granted to you under the License
+ * may not be used to create, or enable the creation or redistribution of,
+ * unlawful or unlicensed copies of an Apple operating system, or to
+ * circumvent, violate, or enable the circumvention or violation of, any
+ * terms of an Apple operating system software license agreement.
+ *
+ * Please obtain a copy of the License at
+ * http://www.opensource.apple.com/apsl/ and read it before using this file.
+ *
+ * The Original Code and all software distributed under the License are
+ * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
+ * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
+ * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
+ * Please see the License for the specific language governing rights and
+ * limitations under the License.
+ *
+ * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
+ */
+
+/*
+ * Copyright (c) 1999
+ * Bill Paul <wpaul@ctr.columbia.edu>. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by Bill Paul.
+ * 4. Neither the name of the author nor the names of any co-contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY Bill Paul AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL Bill Paul OR THE VOICES IN HIS HEAD
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <sys/param.h>
+#include <sys/ioctl.h>
+#include <sys/socket.h>
+#include <sys/sockio.h>
+
+#include <stdlib.h>
+#include <unistd.h>
+
+#include <net/ethernet.h>
+#include <net/if.h>
+#include <net/if_var.h>
+#include <net/if_6lowpan_var.h>
+#include <net/route.h>
+
+#include <ctype.h>
+#include <stdio.h>
+#include <string.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <err.h>
+#include <errno.h>
+
+#include "ifconfig.h"
+
+#include <sys/cdefs.h>
+
+
+static boolean_t is_sixlowpan_inited = FALSE;
+static struct sixlowpanreq params;
+
+static int
+get6lowpan(int s, struct ifreq *ifr, struct sixlowpanreq *req)
+{
+ bzero((char *)req, sizeof(*req));
+ ifr->ifr_data = (caddr_t)req;
+ return ioctl(s, SIOCGIF6LOWPAN, (caddr_t)ifr);
+}
+
+static void
+sixlowpan_status(int s)
+{
+ struct sixlowpanreq req;
+
+ if (get6lowpan(s, &ifr, &req) != -1)
+ printf("\t6lowpan: parent interface: %s\n",
+ req.parent[0] == '\0' ?
+ "<none>" : req.parent);
+}
+
+
+static void
+set6lowpandev(const char *val, int d, int s, const struct afswtch *afp)
+{
+ struct sixlowpanreq req;
+
+ strlcpy(params.parent, val, sizeof(params.parent));
+ is_sixlowpan_inited = TRUE;
+ fprintf(stderr, "val %s\n", val);
+
+ strlcpy(req.parent, val, sizeof(req.parent));
+ ifr.ifr_data = (caddr_t) &req;
+ if (ioctl(s, SIOCSIF6LOWPAN, (caddr_t)&ifr) == -1)
+ err(1, "SIOCSIF6LOWPAN");
+}
+
+static void
+unset6lowpandev(const char *val, int d, int s, const struct afswtch *afp)
+{
+ struct sixlowpanreq req;
+
+ bzero((char *)&req, sizeof(req));
+ ifr.ifr_data = (caddr_t)&req;
+
+ if (ioctl(s, SIOCGIF6LOWPAN, (caddr_t)&ifr) == -1)
+ err(1, "SIOCGIF6LOWPAN");
+
+ bzero((char *)&req, sizeof(req));
+ if (ioctl(s, SIOCSIF6LOWPAN, (caddr_t)&ifr) == -1)
+ err(1, "SIOCSIF6LOWPAN");
+}
+
+static void
+sixlowpan_create(const char *val, int d, int s, const struct afswtch *afp)
+{
+ strlcpy(params.parent, val, sizeof(params.parent));
+ is_sixlowpan_inited = TRUE;
+}
+
+static void
+sixlowpan_clone_cb(int s, void *arg)
+{
+ if (is_sixlowpan_inited == TRUE && params.parent[0] == '\0')
+ errx(1, "6lowpandev must be specified");
+}
+
+static struct cmd sixlowpan_cmds[] = {
+ DEF_CLONE_CMD_ARG("6lowpandev", sixlowpan_create),
+ DEF_CMD_OPTARG("6lowpansetdev", set6lowpandev),
+ DEF_CMD_OPTARG("6lowpanunsetdev", unset6lowpandev),
+};
+static struct afswtch af_6lowpan = {
+ .af_name = "af_6lowpan",
+ .af_af = AF_UNSPEC,
+ .af_other_status = sixlowpan_status,
+};
+
+static __constructor void
+sixlowpan_ctor(void)
+{
+#define N(a) (sizeof(a) / sizeof(a[0]))
+ int i;
+
+ for (i = 0; i < N(sixlowpan_cmds); i++)
+ cmd_register(&sixlowpan_cmds[i]);
+ af_register(&af_6lowpan);
+ callback_register(sixlowpan_clone_cb, NULL);
+#undef N
+}
static
DECL_CMD_FUNC(clone_destroy, arg, d)
{
- (void) strncpy(ifr.ifr_name, name, sizeof(ifr.ifr_name));
+ (void) strlcpy(ifr.ifr_name, name, sizeof(ifr.ifr_name));
if (ioctl(s, SIOCIFDESTROY, &ifr) < 0)
err(1, "SIOCIFDESTROY");
}
/*
- * Copyright (c) 2009-2018 Apple Inc. All rights reserved.
+ * Copyright (c) 2009-2019 Apple Inc. All rights reserved.
*
* @APPLE_OSREFERENCE_LICENSE_HEADER_START@
*
#include <err.h>
#include <errno.h>
#include <fcntl.h>
+#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
+#include <strings.h>
#include <unistd.h>
#include <sysexits.h>
#include <syslog.h>
#include "ifconfig.h"
+#ifdef __APPLE__
+#include <TargetConditionals.h>
+#endif
+
/*
* Since "struct ifreq" is composed of various union members, callers
* should pay special attention to interprete the value.
int bond_details = 0;
int supmedia = 0;
-#if TARGET_OS_EMBEDDED
+#if (TARGET_OS_IPHONE && !TARGET_OS_SIMULATOR)
int verbose = 1;
int showrtref = 1;
-#else /* !TARGET_OS_EMBEDDED */
+#else /* (TARGET_OS_IPHONE && !TARGET_OS_SIMULATOR) */
int verbose = 0;
int showrtref = 0;
-#endif /* !TARGET_OS_EMBEDDED */
+#endif /* (TARGET_OS_IPHONE && !TARGET_OS_SIMULATOR) */
int printkeys = 0; /* Print keying material for interfaces. */
static int ifconfig(int argc, char *const *argv, int iscreate,
static char *sched2str(unsigned int s);
static char *tl2str(unsigned int s);
static char *ift2str(unsigned int t, unsigned int f, unsigned int sf);
+static char *iffunct2str(u_int32_t functional_type);
static struct afswtch *af_getbyname(const char *name);
static struct afswtch *af_getbyfamily(int af);
ifindex = 0;
for (ifa = ifap; ifa; ifa = ifa->ifa_next) {
memset(&paifr, 0, sizeof(paifr));
- strncpy(paifr.ifr_name, ifa->ifa_name, sizeof(paifr.ifr_name));
+ strlcpy(paifr.ifr_name, ifa->ifa_name, sizeof(paifr.ifr_name));
if (sizeof(paifr.ifr_addr) >= ifa->ifa_addr->sa_len) {
memcpy(&paifr.ifr_addr, ifa->ifa_addr,
ifa->ifa_addr->sa_len);
{
const struct afswtch *nafp;
struct callback *cb;
- int s;
+ int ret, s;
- strncpy(ifr.ifr_name, name, sizeof ifr.ifr_name);
+ strlcpy(ifr.ifr_name, name, sizeof ifr.ifr_name);
top:
if (afp == NULL)
afp = af_getbyname("inet");
p->c_name);
p->c_u.c_func2(argv[1], argv[2], s, afp);
argc -= 2, argv += 2;
- } else
+ } else if (p->c_parameter == VAARGS) {
+ ret = p->c_u.c_funcv(argc - 1, argv + 1, s, afp);
+ if (ret < 0)
+ errx(1, "'%s' command error",
+ p->c_name);
+ argc -= ret, argv += ret;
+ } else {
p->c_u.c_func(*argv, p->c_parameter, s, afp);
+ }
}
argc--, argv++;
}
}
}
if (clearaddr) {
- int ret;
- strncpy(afp->af_ridreq, name, sizeof ifr.ifr_name);
+ strlcpy(afp->af_ridreq, name, sizeof ifr.ifr_name);
ret = ioctl(s, afp->af_difaddr, afp->af_ridreq);
if (ret < 0) {
if (errno == EADDRNOTAVAIL && (doalias >= 0)) {
}
}
if (newaddr && (setaddr || setmask)) {
- strncpy(afp->af_addreq, name, sizeof ifr.ifr_name);
+ strlcpy(afp->af_addreq, name, sizeof ifr.ifr_name);
if (ioctl(s, afp->af_aifaddr, afp->af_addreq) < 0)
Perror("ioctl (SIOCAIFADDR)");
}
Perror("ioctl (SIOCGIFFLAGS)");
exit(1);
}
- strncpy(my_ifr.ifr_name, name, sizeof (my_ifr.ifr_name));
+ strlcpy(my_ifr.ifr_name, name, sizeof (my_ifr.ifr_name));
flags = my_ifr.ifr_flags;
if (value < 0) {
setifmetric(const char *val, int dummy __unused, int s,
const struct afswtch *afp)
{
- strncpy(ifr.ifr_name, name, sizeof (ifr.ifr_name));
+ strlcpy(ifr.ifr_name, name, sizeof (ifr.ifr_name));
ifr.ifr_metric = atoi(val);
if (ioctl(s, SIOCSIFMETRIC, (caddr_t)&ifr) < 0)
warn("ioctl (set metric)");
setifmtu(const char *val, int dummy __unused, int s,
const struct afswtch *afp)
{
- strncpy(ifr.ifr_name, name, sizeof (ifr.ifr_name));
+ strlcpy(ifr.ifr_name, name, sizeof (ifr.ifr_name));
ifr.ifr_mtu = atoi(val);
if (ioctl(s, SIOCSIFMTU, (caddr_t)&ifr) < 0)
warn("ioctl (set mtu)");
struct if_descreq ifdr;
bzero(&ifdr, sizeof (ifdr));
- strncpy(ifdr.ifdr_name, name, sizeof (ifdr.ifdr_name));
+ strlcpy(ifdr.ifdr_name, name, sizeof (ifdr.ifdr_name));
ifdr.ifdr_len = strlen(val);
- strncpy((char *)ifdr.ifdr_desc, val, sizeof (ifdr.ifdr_desc));
+ strlcpy((char *)ifdr.ifdr_desc, val, sizeof (ifdr.ifdr_desc));
if (ioctl(s, SIOCSIFDESC, (caddr_t)&ifdr) < 0) {
warn("ioctl (set desc)");
errno = 0;
bzero(&iflpr, sizeof (iflpr));
- strncpy(iflpr.iflpr_name, name, sizeof (iflpr.iflpr_name));
+ strlcpy(iflpr.iflpr_name, name, sizeof (iflpr.iflpr_name));
bps = strtold(val, &cp);
if (val == cp || errno != 0) {
warn("ioctl (set link params)");
} else if (errno == ENXIO) {
printf("TBR cannot be set on %s\n", name);
- } else if (errno == ENOENT || rate == 0) {
+ } else if (errno == 0 && rate == 0) {
printf("%s: TBR is now disabled\n", name);
} else if (errno == ENODEV) {
printf("%s: requires absolute TBR rate\n", name);
}
}
+static int
+get_int64(uint64_t *i, char const *s)
+{
+ char *cp;
+ *i = strtol(s, &cp, 10);
+ if (cp == s || errno != 0) {
+ return (-1);
+ }
+ return (0);
+}
+
+static int
+get_int32(uint32_t *i, char const *s)
+{
+ char *cp;
+ *i = strtol(s, &cp, 10);
+ if (cp == s || errno != 0) {
+ return (-1);
+ }
+ return (0);
+}
+
+static int
+get_percent(double *d, const char *s)
+{
+ char *cp;
+ *d = strtod(s, &cp) / (double)100;
+ if (*d == HUGE_VALF || *d == HUGE_VALL) {
+ return (-1);
+ }
+ if (*d == 0.0 || (*cp != '\0' && strcmp(cp, "%") != 0)) {
+ return (-1);
+ }
+ return (0);
+}
+
+static int
+get_percent_fixed_point(uint32_t *i, const char *s)
+{
+ double p;
+
+ if (get_percent(&p, s) != 0){
+ return (-1);
+ }
+
+ *i = p * IF_NETEM_PARAMS_PSCALE;
+ return (0);
+}
+
+static int
+netem_parse_args(struct if_netem_params *p, int argc, char *const *argv)
+{
+ int argc_saved = argc;
+ uint64_t bandwitdh = 0;
+ uint32_t latency = 0, jitter = 0;
+ uint32_t corruption = 0;
+ uint32_t duplication = 0;
+ uint32_t loss_p_gr_gl = 0, loss_p_gr_bl = 0, loss_p_bl_br = 0,
+ loss_p_bl_gr = 0, loss_p_br_bl = 0;
+ uint32_t reordering = 0;
+
+ bzero(p, sizeof (*p));
+
+ /* take out "input"/"output" */
+ argc--, argv++;
+
+ for ( ; argc > 0; ) {
+ if (strcmp(*argv, "bandwidth") == 0) {
+ argc--, argv++;
+ if (argc <= 0 || get_int64(&bandwitdh, *argv) != 0) {
+ err(1, "Invalid value '%s'", *argv);
+ }
+ argc--, argv++;
+ } else if (strcmp(*argv, "corruption") == 0) {
+ argc--, argv++;
+ if (argc <= 0 ||
+ get_percent_fixed_point(&corruption, *argv) != 0) {
+ err(1, "Invalid value '%s'", *argv);
+ }
+ argc--, argv++;
+ } else if (strcmp(*argv, "delay") == 0) {
+ argc--, argv++;
+ if (argc <= 0 || get_int32(&latency, *argv) != 0) {
+ err(1, "Invalid value '%s'", *argv);
+ }
+ argc--, argv++;
+ if (argc > 0 && get_int32(&jitter, *argv) == 0) {
+ argc--, argv++;
+ }
+ } else if (strcmp(*argv, "duplication") == 0) {
+ argc--, argv++;
+ if (argc <= 0 ||
+ get_percent_fixed_point(&duplication, *argv) != 0) {
+ err(1, "Invalid value '%s'", *argv);
+ return (-1);
+ }
+ argc--, argv++;
+ } else if (strcmp(*argv, "loss") == 0) {
+ argc--, argv++;
+ if (argc <= 0 || get_percent_fixed_point(&loss_p_gr_gl, *argv) != 0) {
+ err(1, "Invalid value '%s'", *argv);
+ }
+ /* we may have all 5 probs, use naive model if not */
+ argc--, argv++;
+ if (argc <= 0 || get_percent_fixed_point(&loss_p_gr_bl, *argv) != 0) {
+ continue;
+ }
+ /* if more than p_gr_gl, then should have all probs */
+ argc--, argv++;
+ if (argc <= 0 || get_percent_fixed_point(&loss_p_bl_br, *argv) != 0) {
+ err(1, "Invalid value '%s' for p_bl_br", *argv);
+ }
+ argc--, argv++;
+ if (argc <= 0 || get_percent_fixed_point(&loss_p_bl_gr, *argv) != 0) {
+ err(1, "Invalid value '%s' for p_bl_gr", *argv);
+ }
+ argc--, argv++;
+ if (argc <= 0 || get_percent_fixed_point(&loss_p_br_bl, *argv) != 0) {
+ err(1, "Invalid value '%s' for p_br_bl", *argv);
+ }
+ argc--, argv++;
+ } else if (strcmp(*argv, "reordering") == 0) {
+ argc--, argv++;
+ if (argc <= 0 || get_percent_fixed_point(&reordering, *argv) != 0) {
+ err(1, "Invalid value '%s'", *argv);
+ }
+ argc--, argv++;
+ } else {
+ return (-1);
+ }
+ }
+
+ if (corruption > IF_NETEM_PARAMS_PSCALE) {
+ err(1, "corruption percentage > 100%%");
+ }
+
+ if (duplication > IF_NETEM_PARAMS_PSCALE) {
+ err(1, "duplication percentage > 100%%");
+ }
+
+ if (duplication > 0 && latency == 0) {
+ /* we need to insert dup'ed packet with latency */
+ err(1, "duplication needs latency param");
+ }
+
+ if (latency > 1000) {
+ err(1, "latency %dms too big (> 1 sec)", latency);
+ }
+
+ if (jitter * 3 > latency) {
+ err(1, "jitter %dms too big (latency %dms)", jitter, latency);
+ }
+
+ /* if gr_gl == 0 (no loss), other prob should all be zero */
+ if (loss_p_gr_gl == 0 &&
+ (loss_p_gr_bl != 0 || loss_p_bl_br != 0 || loss_p_bl_gr != 0 ||
+ loss_p_br_bl != 0)) {
+ err(1, "loss params not all zero when gr_gl is zero");
+ }
+
+ /* check state machine transition prob integrity */
+ if (loss_p_gr_gl > IF_NETEM_PARAMS_PSCALE ||
+ /* gr_gl = IF_NETEM_PARAMS_PSCALE for total loss */
+ loss_p_gr_bl > IF_NETEM_PARAMS_PSCALE ||
+ loss_p_bl_br > IF_NETEM_PARAMS_PSCALE ||
+ loss_p_bl_gr > IF_NETEM_PARAMS_PSCALE ||
+ loss_p_br_bl > IF_NETEM_PARAMS_PSCALE ||
+ loss_p_gr_gl + loss_p_gr_bl > IF_NETEM_PARAMS_PSCALE ||
+ loss_p_bl_br + loss_p_bl_gr > IF_NETEM_PARAMS_PSCALE) {
+ err(1, "loss params too big");
+ }
+
+ if (reordering > IF_NETEM_PARAMS_PSCALE) {
+ err(1, "reordering percentage > 100%%");
+ }
+
+ p->ifnetem_bandwidth_bps = bandwitdh;
+ p->ifnetem_latency_ms = latency;
+ p->ifnetem_jitter_ms = jitter;
+ p->ifnetem_corruption_p = corruption;
+ p->ifnetem_duplication_p = duplication;
+ p->ifnetem_loss_p_gr_gl = loss_p_gr_gl;
+ p->ifnetem_loss_p_gr_bl = loss_p_gr_bl;
+ p->ifnetem_loss_p_bl_br = loss_p_bl_br;
+ p->ifnetem_loss_p_bl_gr = loss_p_bl_gr;
+ p->ifnetem_loss_p_br_bl = loss_p_br_bl;
+ p->ifnetem_reordering_p = reordering;
+
+ return (argc_saved - argc);
+}
+
+void
+print_netem_params(struct if_netem_params *p, const char *desc)
+{
+ struct if_netem_params zero_params;
+ double pscale = IF_NETEM_PARAMS_PSCALE / 100;
+ bzero(&zero_params, sizeof (zero_params));
+
+ if (memcmp(p, &zero_params, sizeof (zero_params)) == 0) {
+ printf("%s NetEm Disabled\n\n", desc);
+ } else {
+ printf(
+ "%s NetEm Parameters\n"
+ "\tbandwidth rate %llubps\n"
+ "\tdelay latency %dms\n"
+ "\t jitter %dms\n",
+ desc, p->ifnetem_bandwidth_bps,
+ p->ifnetem_latency_ms, p->ifnetem_jitter_ms);
+ if (p->ifnetem_loss_p_gr_bl == 0 &&
+ p->ifnetem_loss_p_bl_br == 0 &&
+ p->ifnetem_loss_p_bl_gr == 0 &&
+ p->ifnetem_loss_p_br_bl == 0) {
+ printf(
+ "\tloss %.3f%%\n",
+ (double) p->ifnetem_loss_p_gr_gl / pscale);
+ } else {
+ printf(
+ "\tloss GAP_RECV -> GAP_LOSS %.3f%%\n"
+ "\t GAP_RECV -> BURST_LOSS %.3f%%\n"
+ "\t BURST_LOSS -> BURST_RECV %.3f%%\n"
+ "\t BURST_LOSS -> GAP_RECV %.3f%%\n"
+ "\t BURST_RECV -> BURST_LOSS %.3f%%\n",
+ (double) p->ifnetem_loss_p_gr_gl / pscale,
+ (double) p->ifnetem_loss_p_gr_bl / pscale,
+ (double) p->ifnetem_loss_p_bl_br / pscale,
+ (double) p->ifnetem_loss_p_bl_gr / pscale,
+ (double) p->ifnetem_loss_p_br_bl / pscale);
+ }
+ printf(
+ "\tcorruption %.3f%%\n"
+ "\treordering %.3f%%\n\n",
+ (double) p->ifnetem_corruption_p / pscale,
+ (double) p->ifnetem_reordering_p / pscale);
+ }
+}
+
+static int
+setnetem(int argc, char *const *argv, int s, const struct afswtch *afp)
+{
+ struct if_linkparamsreq iflpr;
+ struct if_netem_params input_params, output_params;
+ int ret = 0, error = 0;
+
+ bzero(&iflpr, sizeof (iflpr));
+ bzero(&input_params, sizeof (input_params));
+ bzero(&output_params, sizeof (output_params));
+
+ if (argc > 1) {
+ if (strcmp(argv[0], "input") == 0) {
+ ret = netem_parse_args(&input_params, argc, argv);
+ } else if (strcmp(argv[0], "output") == 0) {
+ ret = netem_parse_args(&output_params, argc, argv);
+ } else if (strcmp(argv[0], "-h") == 0 || strcmp(argv[0], "--help") == 0) {
+ goto bad_args;
+ } else {
+ fprintf(stderr, "uknown option %s\n", argv[0]);
+ goto bad_args;
+ }
+ if (ret < 0) {
+ goto bad_args;
+ }
+ }
+
+ errno = 0;
+ strlcpy(iflpr.iflpr_name, name, sizeof (iflpr.iflpr_name));
+ error = ioctl(s, SIOCGIFLINKPARAMS, &iflpr);
+ if (error < 0) {
+ warn("ioctl (get link params)");
+ }
+
+ if (argc == 0) {
+ print_netem_params(&iflpr.iflpr_input_netem, "Input");
+ print_netem_params(&iflpr.iflpr_output_netem, "Output");
+ return (0);
+ } else if (argc == 1) {
+ if (strcmp(argv[0], "input") == 0) {
+ bzero(&iflpr.iflpr_input_netem,
+ sizeof (iflpr.iflpr_input_netem));
+ } else if (strcmp(argv[0], "output") == 0) {
+ bzero(&iflpr.iflpr_output_netem,
+ sizeof (iflpr.iflpr_output_netem));
+ } else {
+ fprintf(stderr, "uknown option %s\n", argv[0]);
+ goto bad_args;
+ }
+ printf("%s: netem is now disabled for %s\n", name, argv[0]);
+ ret = 1;
+ } else {
+ if (strcmp(argv[0], "input") == 0) {
+ iflpr.iflpr_input_netem = input_params;
+ } else if (strcmp(argv[0], "output") == 0) {
+ iflpr.iflpr_output_netem = output_params;
+ }
+ }
+
+ error = ioctl(s, SIOCSIFLINKPARAMS, &iflpr);
+ if (error < 0 && errno != ENOENT && errno != ENXIO && errno != ENODEV) {
+ warn("ioctl (set link params)");
+ } else if (errno == ENXIO) {
+ printf("netem cannot be set on %s\n", name);
+ } else {
+ printf("%s: netem configured\n", name);
+ }
+
+ return (ret);
+bad_args:
+ fprintf(stderr, "Usage:\n"
+ "\tTo enable/set netem params\n"
+ "\t\tnetem <input|output>\n"
+ "\t\t [ bandwidth BIT_PER_SEC ]\n"
+ "\t\t [ delay DELAY_MSEC [ JITTER_MSEC ] ]\n"
+ "\t\t [ loss PERCENTAGE ]\n"
+ "\t\t [ duplication PERCENTAGE ]\n"
+ "\t\t [ reordering PERCENTAGE ]\n\n"
+ "\tTo disable <input|output> netem\n"
+ "\t\tnetem <input|output>\n\n"
+ "\tTo show current settings\n"
+ "\t\tnetem\n\n");
+ return (-1);
+}
+
static void
setthrottle(const char *val, int dummy __unused, int s,
const struct afswtch *afp)
errno = 0;
bzero(&iftr, sizeof (iftr));
- strncpy(iftr.ifthr_name, name, sizeof (iftr.ifthr_name));
+ strlcpy(iftr.ifthr_name, name, sizeof (iftr.ifthr_name));
iftr.ifthr_level = strtold(val, &cp);
if (val == cp || errno != 0) {
char *cp;
errno = 0;
bzero(&ifr, sizeof (ifr));
- strncpy(ifr.ifr_name, name, sizeof (ifr.ifr_name));
+ strlcpy(ifr.ifr_name, name, sizeof (ifr.ifr_name));
ifr.ifr_ifru.ifru_disable_output = strtold(val, &cp);
if (val == cp || errno != 0) {
char *cp;
errno = 0;
- strncpy(ifr.ifr_name, name, sizeof(ifr.ifr_name));
+ strlcpy(ifr.ifr_name, name, sizeof(ifr.ifr_name));
ifr.ifr_log.ifl_level = strtold(val, &cp);
if (val == cp || errno != 0) {
void
setcl2k(const char *vname, int value, int s, const struct afswtch *afp)
{
- strncpy(ifr.ifr_name, name, sizeof(ifr.ifr_name));
+ strlcpy(ifr.ifr_name, name, sizeof(ifr.ifr_name));
ifr.ifr_ifru.ifru_2kcl = value;
if (ioctl(s, SIOCSIF2KCL, (caddr_t)&ifr) < 0)
void
setexpensive(const char *vname, int value, int s, const struct afswtch *afp)
{
- strncpy(ifr.ifr_name, name, sizeof(ifr.ifr_name));
+ strlcpy(ifr.ifr_name, name, sizeof(ifr.ifr_name));
ifr.ifr_ifru.ifru_expensive = value;
if (ioctl(s, SIOCSIFEXPENSIVE, (caddr_t)&ifr) < 0)
Perror(vname);
}
+#ifdef SIOCSIFCONSTRAINED
+void
+setconstrained(const char *vname, int value, int s, const struct afswtch *afp)
+{
+ strlcpy(ifr.ifr_name, name, sizeof(ifr.ifr_name));
+ ifr.ifr_ifru.ifru_constrained = value;
+
+ if (ioctl(s, SIOCSIFCONSTRAINED, (caddr_t)&ifr) < 0)
+ Perror(vname);
+}
+#endif
+
+static void
+setifmpklog(const char *vname, int value, int s, const struct afswtch *afp)
+{
+ strlcpy(ifr.ifr_name, name, sizeof(ifr.ifr_name));
+ ifr.ifr_ifru.ifru_mpk_log = value;
+
+ if (ioctl(s, SIOCSIFMPKLOG, (caddr_t)&ifr) < 0)
+ Perror(vname);
+}
+
void
settimestamp(const char *vname, int value, int s, const struct afswtch *afp)
{
- strncpy(ifr.ifr_name, name, sizeof(ifr.ifr_name));
+ strlcpy(ifr.ifr_name, name, sizeof(ifr.ifr_name));
if (value == 0) {
if (ioctl(s, SIOCSIFTIMESTAMPDISABLE, (caddr_t)&ifr) < 0)
}
}
- strncpy(ifr.ifr_name, name, sizeof(ifr.ifr_name));
+ strlcpy(ifr.ifr_name, name, sizeof(ifr.ifr_name));
if (ioctl(s, SIOCSECNMODE, (caddr_t)&ifr) < 0)
Perror("ioctl(SIOCSECNMODE)");
printf("%s(%s, %s)\n", __func__, cmd, arg);
#endif /* (DEBUG | DEVELOPMENT) */
- strncpy(ifr.ifr_name, name, sizeof(ifr.ifr_name));
+ strlcpy(ifr.ifr_name, name, sizeof(ifr.ifr_name));
if (strcmp(cmd, "mode") == 0) {
ioc = SIOCSQOSMARKINGMODE;
if (strcmp(arg, "fastlane") == 0)
ifr.ifr_qosmarking_mode = IFRTYPE_QOSMARKING_FASTLANE;
+ else if (strcmp(arg, "rfc4594") == 0)
+ ifr.ifr_qosmarking_mode = IFRTYPE_QOSMARKING_RFC4594;
else if (strcasecmp(arg, "none") == 0 || strcasecmp(arg, "off") == 0)
ifr.ifr_qosmarking_mode = IFRTYPE_QOSMARKING_MODE_NONE;
else
void
setfastlane(const char *cmd, const char *arg, int s, const struct afswtch *afp)
{
- strncpy(ifr.ifr_name, name, sizeof(ifr.ifr_name));
+ strlcpy(ifr.ifr_name, name, sizeof(ifr.ifr_name));
warnx("### fastlane is obsolete, use qosmarking ###");
int value;
u_long ioc;
- strncpy(ifr.ifr_name, name, sizeof(ifr.ifr_name));
+ strlcpy(ifr.ifr_name, name, sizeof(ifr.ifr_name));
if (strcmp(cmd, "capable") == 0)
ioc = SIOCSFASTLANECAPABLE;
Perror(vname);
}
+struct str2num {
+ const char *str;
+ uint32_t num;
+};
+
+static struct str2num subfamily_str2num[] = {
+ { .str = "any", .num = IFRTYPE_SUBFAMILY_ANY },
+ { .str = "USB", .num = IFRTYPE_SUBFAMILY_USB },
+ { .str = "Bluetooth", .num = IFRTYPE_SUBFAMILY_BLUETOOTH },
+ { .str = "Wi-Fi", .num = IFRTYPE_SUBFAMILY_WIFI },
+ { .str = "wifi", .num = IFRTYPE_SUBFAMILY_WIFI },
+ { .str = "Thunderbolt", .num = IFRTYPE_SUBFAMILY_THUNDERBOLT },
+ { .str = "reserverd", .num = IFRTYPE_SUBFAMILY_RESERVED },
+ { .str = "intcoproc", .num = IFRTYPE_SUBFAMILY_INTCOPROC },
+ { .str = "QuickRelay", .num = IFRTYPE_SUBFAMILY_QUICKRELAY },
+ { .str = "Default", .num = IFRTYPE_SUBFAMILY_DEFAULT },
+ { .str = NULL, .num = 0 },
+};
+
+static uint32_t
+get_num_from_str(struct str2num* str2nums, const char *str)
+{
+ struct str2num *str2num = str2nums;
+
+ while (str2num != NULL && str2num->str != NULL) {
+ if (strcasecmp(str2num->str, str) == 0) {
+ return str2num->num;
+ }
+ str2num++;
+ }
+ return 0;
+}
+
+static void
+setifsubfamily(const char *val, int dummy __unused, int s,
+ const struct afswtch *afp)
+{
+ strlcpy(ifr.ifr_name, name, sizeof (ifr.ifr_name));
+
+ char *endptr;
+ uint32_t subfamily = strtoul(val, &endptr, 0);
+ if (*endptr != 0) {
+ subfamily = get_num_from_str(subfamily_str2num, val);
+ if (subfamily == 0) {
+ return;
+ }
+ }
+
+ ifr.ifr_type.ift_subfamily = subfamily;
+ if (ioctl(s, SIOCSIFSUBFAMILY, (caddr_t)&ifr) < 0)
+ warn("ioctl(SIOCSIFSUBFAMILY)");
+}
+
+void
+setifavailability(const char *vname, int value, int s, const struct afswtch *afp)
+{
+ strlcpy(ifr.ifr_name, name, sizeof(ifr.ifr_name));
+ ifr.ifr_interface_state.valid_bitmask = IF_INTERFACE_STATE_INTERFACE_AVAILABILITY_VALID;
+ if (value == 0) {
+ ifr.ifr_interface_state.interface_availability = IF_INTERFACE_STATE_INTERFACE_UNAVAILABLE;
+ } else {
+ ifr.ifr_interface_state.interface_availability = IF_INTERFACE_STATE_INTERFACE_AVAILABLE;
+ }
+ if (ioctl(s, SIOCSIFINTERFACESTATE, (caddr_t)&ifr) < 0)
+ warn("ioctl(SIOCSIFINTERFACESTATE)");
+}
+
+
#define IFFBITS \
"\020\1UP\2BROADCAST\3DEBUG\4LOOPBACK\5POINTOPOINT\6SMART\7RUNNING" \
"\10NOARP\11PROMISC\12ALLMULTI\13OACTIVE\14SIMPLEX\15LINK0\16LINK1\17LINK2" \
"\27AWDL_RESTRICTED\30CL2K\31ECN_ENABLE\32ECN_DISABLE\33CHANNEL_DRV\34CA" \
"\35SENDLIST\36DIRECTLINK\37FASTLN_ON\40UPDOWNCHANGE"
+#define IFXFBITS \
+"\020\1WOL\2TIMESTAMP\3NOAUTONX\4LEGACY\5TXLOWINET\6RXLOWINET\7ALLOCKPI" \
+"\10LOWPOWER\11MPKLOG\12CONSTRAINED"
+
#define IFCAPBITS \
"\020\1RXCSUM\2TXCSUM\3VLAN_MTU\4VLAN_HWTAGGING\5JUMBO_MTU" \
"\6TSO4\7TSO6\10LRO\11AV\12TXSTATUS\13CHANNEL_IO\14HW_TIMESTAMP\15SW_TIMESTAMP" \
struct ifmibdata_supplemental ifmsupp;
size_t miblen = sizeof(struct ifmibdata_supplemental);
u_int64_t eflags = 0;
+ u_int64_t xflags = 0;
int curcap = 0;
if (afp == NULL) {
allfamilies = 0;
ifr.ifr_addr.sa_family = afp->af_af == AF_LINK ? AF_INET : afp->af_af;
- strncpy(ifr.ifr_name, name, sizeof(ifr.ifr_name));
+ strlcpy(ifr.ifr_name, name, sizeof(ifr.ifr_name));
s = socket(ifr.ifr_addr.sa_family, SOCK_DGRAM, 0);
if (s < 0)
if (ifindex != 0)
printf(" index %u", ifindex);
}
+#ifdef SIOCGIFCONSTRAINED
+ // Constrained is stored in if_xflags which isn't exposed directly
+ if (ioctl(s, SIOCGIFCONSTRAINED, (caddr_t)&ifr) == 0 &&
+ ifr.ifr_constrained != 0) {
+ printf(" constrained");
+ }
+#endif
putchar('\n');
if (verbose && ioctl(s, SIOCGIFEFLAGS, (caddr_t)&ifr) != -1 &&
putchar('\n');
}
+ if (verbose && ioctl(s, SIOCGIFXFLAGS, (caddr_t)&ifr) != -1 &&
+ (xflags = ifr.ifr_xflags) != 0) {
+ printb("\txflags", xflags, IFXFBITS);
+ putchar('\n');
+ }
+
if (ioctl(s, SIOCGIFCAP, (caddr_t)&ifr) == 0) {
if (ifr.ifr_curcap != 0) {
curcap = ifr.ifr_curcap;
putchar('\n');
}
}
-
+
tunnel_status(s);
for (ift = ifa; ift != NULL; ift = ift->ifa_next) {
else if (afp->af_other_status != NULL)
afp->af_other_status(s);
- strncpy(ifs.ifs_name, name, sizeof ifs.ifs_name);
+ strlcpy(ifs.ifs_name, name, sizeof ifs.ifs_name);
if (ioctl(s, SIOCGIFSTATUS, &ifs) == 0)
printf("%s", ifs.ascii);
printf("\ttype: %s\n", c);
}
+ if (verbose > 1) {
+ if (ioctl(s, SIOCGIFFUNCTIONALTYPE, &ifr) != -1) {
+ char *c = iffunct2str(ifr.ifr_functional_type);
+ if (c != NULL)
+ printf("\tfunctional type: %s\n", c);
+ }
+ }
+
if (verbose > 0) {
struct if_agentidsreq ifar;
memset(&ifar, 0, sizeof(ifar));
}
bzero(&iflpr, sizeof (iflpr));
- strncpy(iflpr.iflpr_name, name, sizeof (iflpr.iflpr_name));
+ strlcpy(iflpr.iflpr_name, name, sizeof (iflpr.iflpr_name));
if (ioctl(s, SIOCGIFLINKPARAMS, &iflpr) != -1) {
u_int64_t ibw_max = iflpr.iflpr_input_bw.max_bw;
u_int64_t ibw_eff = iflpr.iflpr_input_bw.eff_bw;
printf("\n");
bzero(&iftr, sizeof (iftr));
- strncpy(iftr.ifthr_name, name,
+ strlcpy(iftr.ifthr_name, name,
sizeof (iftr.ifthr_name));
if (ioctl(s, SIOCGIFTHROTTLE, &iftr) != -1 &&
iftr.ifthr_level != IFNET_THROTTLE_OFF)
}
bzero(&ifdr, sizeof (ifdr));
- strncpy(ifdr.ifdr_name, name, sizeof (ifdr.ifdr_name));
+ strlcpy(ifdr.ifdr_name, name, sizeof (ifdr.ifdr_name));
if (ioctl(s, SIOCGIFDESC, &ifdr) != -1 && ifdr.ifdr_len) {
printf("\tdesc: %s\n", ifdr.ifdr_desc);
}
case IFRTYPE_QOSMARKING_FASTLANE:
printf("fastlane\n");
break;
+ case IFRTYPE_QOSMARKING_RFC4594:
+ printf("RFC4594\n");
+ break;
case IFRTYPE_QOSMARKING_MODE_NONE:
printf("none\n");
break;
printf("\tlow power mode: %s\n",
(ifr.ifr_low_power_mode != 0) ? "enabled" : "disabled");
}
+ if (verbose > 0 && ioctl(s, SIOCGIFMPKLOG, &ifr) != -1) {
+ printf("\tmulti layer packet logging (mpklog): %s\n",
+ (ifr.ifr_mpk_log != 0) ? "enabled" : "disabled");
+ }
done:
close(s);
return;
DEF_CMD("monitor", IFF_MONITOR:, setifflags),
DEF_CMD("-monitor", -IFF_MONITOR, setifflags),
#endif /* IFF_MONITOR */
+ DEF_CMD("mpklog", 1, setifmpklog),
+ DEF_CMD("-mpklog", 0, setifmpklog),
#ifdef IFF_STATICARP
DEF_CMD("staticarp", IFF_STATICARP, setifflags),
DEF_CMD("-staticarp", -IFF_STATICARP, setifflags),
DEF_CMD("-router", 0, setrouter),
DEF_CMD_ARG("desc", setifdesc),
DEF_CMD_ARG("tbr", settbr),
+ DEF_CMD_VA("netem", setnetem),
DEF_CMD_ARG("throttle", setthrottle),
DEF_CMD_ARG("log", setlog),
DEF_CMD("cl2k", 1, setcl2k),
DEF_CMD("-cl2k", 0, setcl2k),
DEF_CMD("expensive", 1, setexpensive),
DEF_CMD("-expensive", 0, setexpensive),
+#ifdef SIOCSIFCONSTRAINED
+ DEF_CMD("constrained", 1, setconstrained),
+ DEF_CMD("-constrained", 0, setconstrained),
+#endif
DEF_CMD("timestamp", 1, settimestamp),
DEF_CMD("-timestamp", 0, settimestamp),
DEF_CMD_ARG("ecn", setecnmode),
DEF_CMD("-probe_connectivity", 0, setprobeconnectivity),
DEF_CMD("lowpowermode", 1, setlowpowermode),
DEF_CMD("-lowpowermode", 0, setlowpowermode),
+ DEF_CMD_ARG("subfamily", setifsubfamily),
+ DEF_CMD("available", 1, setifavailability),
+ DEF_CMD("-available", 0, setifavailability),
+ DEF_CMD("unavailable", 0, setifavailability),
};
static __constructor void
c = "Cellular";
break;
+ case IFT_OTHER:
+ if (ifr.ifr_type.ift_family == APPLE_IF_FAM_IPSEC) {
+ if (ifr.ifr_type.ift_subfamily == IFRTYPE_SUBFAMILY_BLUETOOTH) {
+ c = "Companion Link Bluetooth";
+ } else if (ifr.ifr_type.ift_subfamily == IFRTYPE_SUBFAMILY_QUICKRELAY) {
+ c = "Companion Link QuickRelay";
+ } else if (ifr.ifr_type.ift_subfamily == IFRTYPE_SUBFAMILY_WIFI) {
+ c = "Companion Link Wi-Fi";
+ } else if (ifr.ifr_type.ift_subfamily == IFRTYPE_SUBFAMILY_DEFAULT) {
+ c = "Companion Link Default";
+ }
+ }
+ break;
+
case IFT_BRIDGE:
case IFT_PFLOG:
case IFT_PFSYNC:
- case IFT_OTHER:
case IFT_PPP:
case IFT_LOOP:
case IFT_GIF:
return (c);
}
+
+static char *
+iffunct2str(u_int32_t functional_type)
+{
+ char *str = NULL;
+
+ switch (functional_type) {
+ case IFRTYPE_FUNCTIONAL_UNKNOWN:
+ break;
+
+ case IFRTYPE_FUNCTIONAL_LOOPBACK:
+ str = "loopback";
+ break;
+
+ case IFRTYPE_FUNCTIONAL_WIRED:
+ str = "wired";
+ break;
+
+ case IFRTYPE_FUNCTIONAL_WIFI_INFRA:
+ str = "wifi";
+ break;
+
+ case IFRTYPE_FUNCTIONAL_WIFI_AWDL:
+ str = "awdl";
+ break;
+
+ case IFRTYPE_FUNCTIONAL_CELLULAR:
+ str = "cellular";
+ break;
+
+ case IFRTYPE_FUNCTIONAL_INTCOPROC:
+ break;
+
+ case IFRTYPE_FUNCTIONAL_COMPANIONLINK:
+ str = "companionlink";
+ break;
+
+ default:
+ break;
+ }
+ return str;
+}
/*
- * Copyright (c) 2009-2011 Apple Inc. All rights reserved.
+ * Copyright (c) 2009-2018 Apple Inc. All rights reserved.
*
* @APPLE_OSREFERENCE_LICENSE_HEADER_START@
*
typedef void c_func(const char *cmd, int arg, int s, const struct afswtch *afp);
typedef void c_func2(const char *arg1, const char *arg2, int s, const struct afswtch *afp);
+typedef int c_funcv(int argc, char *const *argv, int s, const struct afswtch *afp);
struct cmd {
const char *c_name;
#define NEXTARG 0xffffff /* has following arg */
#define NEXTARG2 0xfffffe /* has 2 following args */
#define OPTARG 0xfffffd /* has optional following arg */
+#define VAARGS 0xfffffc /* has variable following args */
union {
c_func *c_func;
c_func2 *c_func2;
+ c_funcv *c_funcv;
} c_u;
int c_iscloneop;
struct cmd *c_next;
#define DEF_CMD_ARG(name, func) { name, NEXTARG, { .c_func = func } }
#define DEF_CMD_OPTARG(name, func) { name, OPTARG, { .c_func = func } }
#define DEF_CMD_ARG2(name, func) { name, NEXTARG2, { .c_func2 = func } }
+#define DEF_CMD_VA(name, func) { name, VAARGS, { .c_funcv = func } }
#define DEF_CLONE_CMD(name, param, func) { name, param, { .c_func = func }, 1 }
#define DEF_CLONE_CMD_ARG(name, func) { name, NEXTARG, { .c_func = func }, 1 }
int *media_list, i;
(void) memset(&ifmr, 0, sizeof(ifmr));
- (void) strncpy(ifmr.ifm_name, name, sizeof(ifmr.ifm_name));
+ (void) strlcpy(ifmr.ifm_name, name, sizeof(ifmr.ifm_name));
if (ioctl(s, SIOCGIFXMEDIA, (caddr_t)&ifmr) < 0) {
/*
if (ioctl(s, SIOCGIFXMEDIA, (caddr_t)&ifmr) < 0)
err(1, "SIOCGIFXMEDIA");
+
printf("\tmedia: ");
print_media_word(ifmr.ifm_current, 1);
if (ifmr.ifm_active != ifmr.ifm_current) {
err(1, "malloc");
(void) memset(ifmr, 0, sizeof(struct ifmediareq));
- (void) strncpy(ifmr->ifm_name, name,
+ (void) strlcpy(ifmr->ifm_name, name,
sizeof(ifmr->ifm_name));
ifmr->ifm_count = 0;
*/
subtype = get_media_subtype(IFM_TYPE(ifmr->ifm_ulist[0]), val);
- strncpy(ifr.ifr_name, name, sizeof(ifr.ifr_name));
+ strlcpy(ifr.ifr_name, name, sizeof(ifr.ifr_name));
ifr.ifr_media = (ifmr->ifm_current & ~(IFM_NMASK|IFM_TMASK)) |
IFM_TYPE(ifmr->ifm_ulist[0]) | subtype;
options = get_media_options(IFM_TYPE(ifmr->ifm_ulist[0]), val);
- strncpy(ifr.ifr_name, name, sizeof(ifr.ifr_name));
+ strlcpy(ifr.ifr_name, name, sizeof(ifr.ifr_name));
ifr.ifr_media = ifmr->ifm_current;
if (clear)
ifr.ifr_media &= ~options;
if (inst < 0 || inst > IFM_INST_MAX)
errx(1, "invalid media instance: %s", val);
- strncpy(ifr.ifr_name, name, sizeof(ifr.ifr_name));
+ strlcpy(ifr.ifr_name, name, sizeof(ifr.ifr_name));
ifr.ifr_media = (ifmr->ifm_current & ~IFM_IMASK) | inst << IFM_ISHIFT;
ifmr->ifm_current = ifr.ifr_media;
mode = get_media_mode(IFM_TYPE(ifmr->ifm_ulist[0]), val);
- strncpy(ifr.ifr_name, name, sizeof(ifr.ifr_name));
+ strlcpy(ifr.ifr_name, name, sizeof(ifr.ifr_name));
ifr.ifr_media = (ifmr->ifm_current & ~IFM_MMASK) | mode;
ifmr->ifm_current = ifr.ifr_media;
nexus_status(int s)
{
struct if_nexusreq ifnr;
- uuid_string_t multistack;
+ uuid_string_t flowswitch;
uuid_string_t netif;
if (!verbose) {
}
uuid_unparse_upper(ifnr.ifnr_netif, netif);
printf("\tnetif: %s\n", netif);
- if (uuid_is_null(ifnr.ifnr_multistack) == 0) {
- uuid_unparse_upper(ifnr.ifnr_multistack, multistack);
- printf("\tmultistack: %s\n", multistack);
+ if (uuid_is_null(ifnr.ifnr_flowswitch) == 0) {
+ uuid_unparse_upper(ifnr.ifnr_flowswitch, flowswitch);
+ printf("\tflowswitch: %s\n", flowswitch);
}
return;
}
- MNC - Multicast NetCat
+1 MNC - Multicast NetCat
------------------------
1. Introduction
return NULL;
bzero(buf, bufsz);
- strlcpy(buf, MSG_HDR, sizeof(MSG_HDR));
+ strlcpy(buf, MSG_HDR, bufsz);
for (i = sizeof(MSG_HDR); i < bufsz; i++) {
buf[i] = j;
return NULL;
bzero(buf, bufsz);
- strlcpy(buf, MSG_HDR, sizeof(MSG_HDR));
+ strlcpy(buf, MSG_HDR, bufsz);
for (i = sizeof(MSG_HDR); i < bufsz; i++) {
buf[i] = j;
warnc(EINVAL, "ether_aton");
break;
}
- strlcpy(ifr.ifr_name, str1, IF_NAMESIZE);
+ strlcpy(ifr.ifr_name, str1, sizeof(ifr.ifr_name));
memcpy(LLADDR(dlp), ep, ETHER_ADDR_LEN);
if (ioctl(s, (*cmd == 'a') ? SIOCADDMULTI : SIOCDELMULTI,
&ifr) == -1) {
/*
- * Copyright (c) 2009-2013 Apple Inc. All rights reserved.
+ * Copyright (c) 2009-2017 Apple Inc. All rights reserved.
*
* @APPLE_OSREFERENCE_LICENSE_HEADER_START@
*
int gai_error;
u_char *ea;
char *host = argv[0], *eaddr = argv[1];
+ int ealen;
getsocket();
argc -= 2;
}
#endif
ea = (u_char *)LLADDR(&sdl_m);
- if (ndp_ether_aton(eaddr, ea) == 0)
- sdl_m.sdl_alen = 6;
+
+ ealen = ndp_ether_aton(eaddr, ea);
+ if (ealen != -1)
+ sdl_m.sdl_alen = ealen;
flags = expire_time = 0;
while (argc-- > 0) {
if (strncmp(argv[0], "temp", 4) == 0) {
(rtm->rtm_flags & RTF_LLINFO) &&
!(rtm->rtm_flags & RTF_GATEWAY)) switch (sdl->sdl_type) {
case IFT_ETHER: case IFT_FDDI: case IFT_ISO88023:
- case IFT_ISO88024: case IFT_ISO88025:
+ case IFT_ISO88024: case IFT_ISO88025:
+ case IFT_6LOWPAN:
goto overwrite;
}
/*
static int
ndp_ether_aton(char *a, u_char *n)
{
- int i, o[6];
+ int i, o[8];
+ int len;
- i = sscanf(a, "%x:%x:%x:%x:%x:%x", &o[0], &o[1], &o[2], &o[3], &o[4],
- &o[5]);
- if (i != 6) {
+ len = sscanf(a, "%x:%x:%x:%x:%x:%x:%x:%x", &o[0], &o[1], &o[2], &o[3], &o[4],
+ &o[5], &o[6], &o[7]);
+ if (len != 6 && len != 8) {
fprintf(stderr, "ndp: invalid Ethernet address '%s'\n", a);
- return (1);
+ return (-1);
}
- for (i = 0; i < 6; i++)
+ for (i = 0; i < len; i++)
n[i] = o[i];
- return (0);
+ return (len);
}
static void
/*
- * Copyright (c) 2008-2015 Apple Inc. All rights reserved.
+ * Copyright (c) 2008-2019 Apple Inc. All rights reserved.
*
* @APPLE_OSREFERENCE_LICENSE_HEADER_START@
*
#include <errno.h>
#include <fcntl.h>
+#include <assert.h>
+
#include "netstat.h"
#define YES 1
}
if (!pfunc) {
- printf("%-5.5s %-5.5s %-13.13s %-15.15s %8.8s %5.5s",
- "Name", "Mtu", "Network", "Address", "Ipkts", "Ierrs");
+ if (lflag) {
+ printf("%-10.10s %-5.5s %-39.39s %-39.39s %8.8s %5.5s",
+ "Name", "Mtu", "Network", "Address", "Ipkts", "Ierrs");
+ } else {
+ printf("%-10.10s %-5.5s %-13.13s %-15.15s %8.8s %5.5s",
+ "Name", "Mtu", "Network", "Address", "Ipkts", "Ierrs");
+ }
if (prioflag >= 0)
printf(" %8.8s %8.8s", "Itcpkts", "Ipvpkts");
if (bflag) {
int mibname[6];
size_t miblen = sizeof(struct ifmibdata_supplemental);
- strncpy(name, sdl->sdl_data, sdl->sdl_nlen);
- name[sdl->sdl_nlen] = 0;
if (interface != 0 && if2m->ifm_index != ifindex)
continue;
- cp = index(name, '\0');
+
+ /* The interface name is not a zero-ended string */
+ memcpy(name, sdl->sdl_data, MIN(sizeof(name) - 1, sdl->sdl_nlen));
+ name[MIN(sizeof(name) - 1, sdl->sdl_nlen)] = 0;
if (pfunc) {
(*pfunc)(name);
continue;
}
+ cp = index(name, '\0');
if ((if2m->ifm_flags & IFF_UP) == 0)
*cp++ = '*';
*cp = '\0';
} else {
continue;
}
- printf("%-5.5s %-5u ", name, mtu);
+ if (lflag) {
+ printf("%-10.10s %-5u ", name, mtu);
+ } else {
+ printf("%-5.5s %-5u ", name, mtu);
+ }
if (sa == 0) {
- printf("%-13.13s ", "none");
- printf("%-15.15s ", "none");
+ printf(lflag ? "%-39.39s " : "%-13.13s ", "none");
+ printf(lflag ? "%-39.39s " : "%-15.15s ", "none");
} else {
switch (sa->sa_family) {
case AF_UNSPEC:
- printf("%-13.13s ", "none");
- printf("%-15.15s ", "none");
+ printf(lflag ? "%-39.39s " : "%-13.13s ", "none");
+ printf(lflag ? "%-39.39s " : "%-15.15s ", "none");
break;
case AF_INET: {
((struct sockaddr_in *)
rti_info[RTAX_NETMASK])->sin_len);
- printf("%-13.13s ",
+ printf(lflag ? "%-39.39s " : "%-13.13s ",
netname(sin->sin_addr.s_addr &
mask.sin_addr.s_addr,
ntohl(mask.sin_addr.s_addr)));
- printf("%-15.15s ",
+ printf(lflag ? "%-39.39s " : "%-15.15s ",
routename(sin->sin_addr.s_addr));
network_layer = 1;
struct sockaddr *mask =
(struct sockaddr *)rti_info[RTAX_NETMASK];
- printf("%-11.11s ", netname6(sin6, mask));
- printf("%-17.17s ", (char *)inet_ntop(AF_INET6,
+ printf(lflag ? "%-39.39s " : "%-11.11s ", netname6(sin6, mask));
+ printf(lflag ? "%-39.39s " : "%-17.17s ", (char *)inet_ntop(AF_INET6,
&sin6->sin6_addr, ntop_buf,
sizeof(ntop_buf)));
n = sdl->sdl_alen;
snprintf(linknum, sizeof(linknum),
"<Link#%d>", sdl->sdl_index);
- m = printf("%-11.11s ", linknum);
+ m = printf(lflag ? "%-39.39s " : "%-11.11s ", linknum);
goto hexprint;
}
while (--n >= 0)
m += printf("%02x%c", *cp++ & 0xff,
n > 0 ? ':' : ' ');
- m = 30 - m;
+ m = (lflag ? 80 : 30) - m;
while (m-- > 0)
putchar(' ');
size_t miblen = sizeof (ifmsupp);
struct itimerval timer_interval;
struct if_rxpoll_stats *sp;
+ struct if_netif_stats *np;
sigset_t sigset, oldsigset;
unsigned int ifindex;
int name[6];
interface, sp->ifi_poll_on_req, sp->ifi_poll_on_err);
printf(" [ poll off requests: %15u errors: %27u ]\n",
sp->ifi_poll_off_req, sp->ifi_poll_off_err);
- printf(" [ polled packets: %18llu polled bytes: %21llu ]\n",
- sp->ifi_poll_packets, sp->ifi_poll_bytes);
+ printf(" [ polled packets: %18llu per poll limit: %19lu ]\n",
+ sp->ifi_poll_packets, sp->ifi_poll_packets_limit);
+ printf(" [ polled bytes: %20llu ]\n", sp->ifi_poll_bytes);
+ printf(" [ poll interval: %14llu nsec ]\n",
+ sp->ifi_poll_interval_time);
printf(" [ sampled packets avg/min/max: %12u / %12u / %12u ]\n",
sp->ifi_poll_packets_avg, sp->ifi_poll_packets_min,
sp->ifi_poll_packets_max);
printf(" [ wakeups lowat/hiwat threshold: %10u / %10u ]\n",
sp->ifi_poll_wakeups_lowat, sp->ifi_poll_wakeups_hiwat);
+ np = &ifmsupp.ifmd_netif_stats;
+ printf(" [ mit mode: %24U cfg idx: %26u ]\n",
+ np->ifn_rx_mit_mode, np->ifn_rx_mit_cfg_idx);
+ printf(" [ cfg packets lo/hi threshold: %12u / %12u ]\n",
+ np->ifn_rx_mit_cfg_packets_lowat, np->ifn_rx_mit_cfg_packets_hiwat);
+ printf(" [ cfg bytes lo/hi threshold: %12u / %12u ]\n",
+ np->ifn_rx_mit_cfg_bytes_lowat, np->ifn_rx_mit_cfg_bytes_hiwat);
+ printf(" [ cfg interval: %15llu nsec ]\n",
+ np->ifn_rx_mit_cfg_interval);
+ printf(" [ mit interval: %15llu nsec ]\n",
+ np->ifn_rx_mit_interval);
+ printf(" [ mit packets avg/min/max: %12u / %12u / %12u ]\n",
+ np->ifn_rx_mit_packets_avg, np->ifn_rx_mit_packets_min,
+ np->ifn_rx_mit_packets_max);
+ printf(" [ mit bytes avg/min/max: %12u / %12u / %12u ]\n",
+ np->ifn_rx_mit_bytes_avg, np->ifn_rx_mit_bytes_min,
+ np->ifn_rx_mit_bytes_max);
+
fflush(stdout);
if (interval > 0) {
"Current listen queue sizes (qlen/incqlen/maxqlen)");
putchar('\n');
if (Aflag) {
-#if !TARGET_OS_EMBEDDED
printf("%-16.16s ", "Socket");
-#else
- printf("%-8.8s ", "Socket");
-#endif
printf("%-9.9s", "Flowhash");
}
if (Lflag)
}
if (Aflag) {
if (istcp)
-#if !TARGET_OS_EMBEDDED
printf("%16lx ", (u_long)inp->inp_ppcb);
-#else
- printf("%8lx ", (u_long)inp->inp_ppcb);
-
-#endif
else
-#if !TARGET_OS_EMBEDDED
printf("%16lx ", (u_long)so->so_pcb);
-#else
- printf("%8lx ", (u_long)so->so_pcb);
-#endif
printf("%8x ", inp->inp_flowhash);
}
if (Lflag) {
printf("%-11d", tp->t_state);
else {
printf("%-11s", tcpstates[tp->t_state]);
-#if defined(TF_NEEDSYN) && defined(TF_NEEDFIN)
- /* Show T/TCP `hidden state' */
- if (tp->t_flags & (TF_NEEDSYN|TF_NEEDFIN))
- putchar('*');
-#endif /* defined(TF_NEEDSYN) && defined(TF_NEEDFIN) */
}
}
if (!istcp)
p(tcps_keeptimeo, "\t%u keepalive timeout%s\n");
p(tcps_keepprobe, "\t\t%u keepalive probe%s sent\n");
p(tcps_keepdrops, "\t\t%u connection%s dropped by keepalive\n");
+ p(tcps_ka_offload_drops, "\t\t%u connection%s dropped by keepalive offload\n");
p(tcps_predack, "\t%u correct ACK header prediction%s\n");
p(tcps_preddat, "\t%u correct data packet header prediction%s\n");
#ifdef TCP_MAX_SACK
if (sysctlbyname("net.inet.ip.output_perf_data", &out_net_perf, &out_net_perf_len, 0, 0) < 0) {
warn("sysctl: net.inet.ip.output_perf_data");
- return;
+ bzero(&out_net_perf, out_net_perf_len);
}
if (sysctlbyname("net.inet.ip.input_perf_data", &in_net_perf, &in_net_perf_len, 0, 0) < 0) {
warn("sysctl: net.inet.ip.input_perf_data");
- return;
+ bzero(&in_net_perf, in_net_perf_len);
}
if (interval && vflag > 0)
if (inp->s_addr == INADDR_ANY)
strlcpy(line, "*", sizeof(line));
else if (cp) {
- strncpy(line, cp, sizeof(line) - 1);
- line[sizeof(line) - 1] = '\0';
+ strlcpy(line, cp, sizeof(line));
} else {
inp->s_addr = ntohl(inp->s_addr);
#define C(x) ((u_int)((x) & 0xff))
int gflag; /* show group (multicast) routing or stats */
#endif
int iflag; /* show interfaces */
-int lflag; /* show routing table with use and ref */
+int lflag; /* show routing table with more information */
int Lflag; /* show size of listen queues */
int mflag; /* show memory stats */
int nflag; /* show addresses numerically */
/* Interface upon which the membership exists */
psa = (sockunion_t *)ifma->ifma_name;
if (psa != NULL && psa->sa.sa_family == AF_LINK) {
- strlcpy(myifname, link_ntoa(&psa->sdl), IFNAMSIZ);
+ strlcpy(myifname, link_ntoa(&psa->sdl), sizeof(myifname));
pcolon = strchr(myifname, ':');
if (pcolon)
*pcolon = '\0';
if (af != 0 && pgsa->sa.sa_family != af)
continue;
- strlcpy(thisifname, link_ntoa(&psa->sdl), IFNAMSIZ);
+ strlcpy(thisifname, link_ntoa(&psa->sdl), sizeof(thisifname));
pcolon = strchr(thisifname, ':');
if (pcolon)
*pcolon = '\0';
extern int cflag; /* show specific classq */
extern int dflag; /* show i/f dropped packets */
extern int Fflag; /* show i/f forwarded packets */
-#if defined(__APPLE__) && !TARGET_OS_EMBEDDED
extern int gflag; /* show group (multicast) routing or stats */
-#endif
extern int iflag; /* show interfaces */
extern int lflag; /* show routing table with use and ref */
extern int Lflag; /* show size of listen queues */
#ifndef INET6
#define WID_DST(af) 18 /* width of destination column */
#define WID_GW(af) 18 /* width of gateway column */
+#define WID_RT_IFA(af) 18 /* width of source column */
#define WID_IF(af) 7 /* width of netif column */
#else
#define WID_DST(af) \
((af) == AF_INET6 ? (lflag ? 39 : (nflag ? 39: 18)) : 18)
#define WID_GW(af) \
((af) == AF_INET6 ? (lflag ? 31 : (nflag ? 31 : 18)) : 18)
+#define WID_RT_IFA(af) \
+ ((af) == AF_INET6 ? (lflag ? 39 : (nflag ? 39 : 18)) : 18)
#define WID_IF(af) ((af) == AF_INET6 ? 8 : 7)
#endif /*INET6*/
void
pr_rthdr(int af)
{
-
- if (Aflag)
- printf("%-8.8s ","Address");
- if (af == AF_INET || lflag) {
+ if (lflag) {
if (lflag > 2)
- printf("%-*.*s %-*.*s %-10.10s %6.6s %8.8s %6.6s %*.*s %6s "
- "%10s %10s %8s %8s %8s\n",
- WID_DST(af), WID_DST(af), "Destination",
- WID_GW(af), WID_GW(af), "Gateway",
- "Flags", "Refs", "Use", "Mtu",
- WID_IF(af), WID_IF(af), "Netif", "Expire",
- "rtt(ns)", "rttvar(ns)", "recvpipe", "sendpipe", "ssthresh");
+ printf("%-*.*s %-*.*s %-*.*s %-10.10s %6.6s %8.8s %6.6s %*.*s %6s "
+ "%10s %10s %8s %8s %8s\n",
+ WID_DST(af), WID_DST(af), "Destination",
+ WID_GW(af), WID_GW(af), "Gateway",
+ WID_RT_IFA(af), WID_RT_IFA(af), "RT_IFA",
+ "Flags", "Refs", "Use", "Mtu",
+ WID_IF(af), WID_IF(af), "Netif", "Expire",
+ "rtt(ms)", "rttvar(ms)", "recvpipe", "sendpipe", "ssthresh");
else if (lflag > 1)
- printf("%-*.*s %-*.*s %-10.10s %6.6s %8.8s %6.6s %*.*s %6s "
- "%10s %10s\n",
- WID_DST(af), WID_DST(af), "Destination",
- WID_GW(af), WID_GW(af), "Gateway",
- "Flags", "Refs", "Use", "Mtu",
- WID_IF(af), WID_IF(af), "Netif", "Expire",
- "rtt(ns)", "rttvar(ns)");
- else if (lflag == 1)
- printf("%-*.*s %-*.*s %-10.10s %6.6s %8.8s %6.6s %*.*s %6s\n",
+ printf("%-*.*s %-*.*s %-*.*s %-10.10s %6.6s %8.8s %6.6s %*.*s %6s "
+ "%10s %10s\n",
WID_DST(af), WID_DST(af), "Destination",
WID_GW(af), WID_GW(af), "Gateway",
+ WID_RT_IFA(af), WID_RT_IFA(af), "RT_IFA",
"Flags", "Refs", "Use", "Mtu",
- WID_IF(af), WID_IF(af), "Netif", "Expire");
+ WID_IF(af), WID_IF(af), "Netif", "Expire",
+ "rtt(ms)", "rttvar(ms)");
else
- printf("%-*.*s %-*.*s %-10.10s %6.6s %8.8s %*.*s %6s\n",
+ printf("%-*.*s %-*.*s %-*.*s %-10.10s %6.6s %8.8s %6.6s %*.*s %6s\n",
WID_DST(af), WID_DST(af), "Destination",
WID_GW(af), WID_GW(af), "Gateway",
- "Flags", "Refs", "Use",
+ WID_RT_IFA(af), WID_RT_IFA(af), "RT_IFA",
+ "Flags", "Refs", "Use", "Mtu",
WID_IF(af), WID_IF(af), "Netif", "Expire");
- } else {
- printf("%-*.*s %-*.*s %-10.10s %8.8s %6s\n",
+ } else {
+ printf("%-*.*s %-*.*s %-10.10s %*.*s %6s\n",
WID_DST(af), WID_DST(af), "Destination",
WID_GW(af), WID_GW(af), "Gateway",
- "Flags", "Netif", "Expire");
-}
+ "Flags", WID_IF(af), WID_IF(af), "Netif", "Expire");
+ }
}
/*
p_sockaddr(rti_info[RTAX_GATEWAY], NULL, RTF_HOST,
WID_GW(addr.u_sa.sa_family));
+
+ if (lflag && (rtm->rtm_addrs & RTA_IFA)) {
+ p_sockaddr(rti_info[RTAX_IFA], NULL, RTF_HOST,
+ WID_RT_IFA(addr.u_sa.sa_family));
+ }
p_flags(rtm->rtm_flags, "%-10.10s ");
- if (addr.u_sa.sa_family == AF_INET || lflag) {
+ if (lflag) {
printf("%6u %8u ", rtm->rtm_refcnt, (unsigned int)rtm->rtm_use);
- if (lflag) {
- if (rtm->rtm_rmx.rmx_mtu != 0)
- printf("%6u ", rtm->rtm_rmx.rmx_mtu);
- else
- printf("%6s ", "");
- }
+ if (rtm->rtm_rmx.rmx_mtu != 0)
+ printf("%6u ", rtm->rtm_rmx.rmx_mtu);
+ else
+ printf("%6s ", "");
}
+
if (rtm->rtm_index != lastindex) {
if_indextoname(rtm->rtm_index, ifname);
lastindex = rtm->rtm_index;
}
}
if (cp) {
- strncpy(line, cp, sizeof(line) - 1);
- line[sizeof(line) - 1] = '\0';
+ strlcpy(line, cp, sizeof(line));
} else {
#define C(x) ((x) & 0xff)
in = ntohl(in);
}
}
if (cp)
- strncpy(line, cp, sizeof(line) - 1);
+ strlcpy(line, cp, sizeof(line));
else {
switch (dmask) {
case IN_CLASSA_NET:
p(kcs_tbl_size_too_big, "\t%llu register failure%s because of too many kern_ctl_ref\n");
p(kcs_enqdata_mb_alloc_fail, "\t%llu enqueuedata failure%s because could not allocate a packet\n");
p(kcs_enqdata_sbappend_fail, "\t%llu enqueuedata failure%s due to full socket buffers\n");
-
+
#undef STATDIFF
#undef p
#undef p1a
#include <stdlib.h>
#include "netstat.h"
-#if !TARGET_OS_EMBEDDED
+#ifdef __APPLE__
+#include <TargetConditionals.h>
+#endif
+
+#if !(TARGET_OS_IPHONE && !TARGET_OS_SIMULATOR)
static void unixdomainpr __P((struct xunpcb64 *, struct xsocket64 *));
#else
static void unixdomainpr __P((struct xunpcb *, struct xsocket *));
int type;
size_t len;
struct xunpgen *xug, *oxug;
-#if !TARGET_OS_EMBEDDED
+#if !(TARGET_OS_IPHONE && !TARGET_OS_SIMULATOR)
struct xsocket64 *so;
struct xunpcb64 *xunp;
char mibvar[sizeof "net.local.seqpacket.pcblist64"];
#endif
for (type = SOCK_STREAM; type <= SOCK_RAW; type++) {
-#if !TARGET_OS_EMBEDDED
+#if !(TARGET_OS_IPHONE && !TARGET_OS_SIMULATOR)
snprintf(mibvar, sizeof(mibvar), "net.local.%s.pcblist64", socktype[type]);
#else
snprintf(mibvar, sizeof(mibvar), "net.local.%s.pcblist", socktype[type]);
for (xug = (struct xunpgen *)((char *)xug + xug->xug_len);
xug->xug_len > sizeof(struct xunpgen);
xug = (struct xunpgen *)((char *)xug + xug->xug_len)) {
-#if !TARGET_OS_EMBEDDED
+#if !(TARGET_OS_IPHONE && !TARGET_OS_SIMULATOR)
xunp = (struct xunpcb64 *)xug;
#else
xunp = (struct xunpcb *)xug;
so = &xunp->xu_socket;
/* Ignore PCBs which were freed during copyout. */
-#if !TARGET_OS_EMBEDDED
+#if !(TARGET_OS_IPHONE && !TARGET_OS_SIMULATOR)
if (xunp->xunp_gencnt > oxug->xug_gen)
#else
if (xunp->xu_unp.unp_gencnt > oxug->xug_gen)
static void
unixdomainpr(xunp, so)
-#if !TARGET_OS_EMBEDDED
+#if !(TARGET_OS_IPHONE && !TARGET_OS_SIMULATOR)
struct xunpcb64 *xunp;
struct xsocket64 *so;
#else
struct xsocket *so;
#endif
{
-#if TARGET_OS_EMBEDDED
+#if (TARGET_OS_IPHONE && !TARGET_OS_SIMULATOR)
struct unpcb *unp;
#endif
struct sockaddr_un *sa;
static int first = 1;
-#if !TARGET_OS_EMBEDDED
+#if !(TARGET_OS_IPHONE && !TARGET_OS_SIMULATOR)
sa = &xunp->xu_addr;
#else
unp = &xunp->xu_unp;
if (first) {
printf("Active LOCAL (UNIX) domain sockets\n");
printf(
-#if !TARGET_OS_EMBEDDED
+#if !(TARGET_OS_IPHONE && !TARGET_OS_SIMULATOR)
"%-16.16s %-6.6s %-6.6s %-6.6s %16.16s %16.16s %16.16s %16.16s Addr\n",
#else
"%-8.8s %-6.6s %-6.6s %-6.6s %8.8s %8.8s %8.8s %8.8s Addr\n",
"Inode", "Conn", "Refs", "Nextref");
first = 0;
}
-#if !TARGET_OS_EMBEDDED
+#if !(TARGET_OS_IPHONE && !TARGET_OS_SIMULATOR)
printf("%16lx %-6.6s %6u %6u %16lx %16lx %16lx %16lx",
(long)xunp->xu_unpp, socktype[so->so_type], so->so_rcv.sb_cc,
so->so_snd.sb_cc,
(long)unp->unp_refs.lh_first, (long)unp->unp_reflink.le_next);
#endif
-#if !TARGET_OS_EMBEDDED
+#if !(TARGET_OS_IPHONE && !TARGET_OS_SIMULATOR)
if (sa->sun_len)
#else
if (sa)
72B732DF1899B0380060E6D4 /* cfilutil.1 in CopyFiles */ = {isa = PBXBuildFile; fileRef = 72B732DE1899B0380060E6D4 /* cfilutil.1 */; };
72B732EF1899B23A0060E6D4 /* cfilutil.c in Sources */ = {isa = PBXBuildFile; fileRef = 72B732EE1899B23A0060E6D4 /* cfilutil.c */; };
72B732F11899B2430060E6D4 /* cfilstat.c in Sources */ = {isa = PBXBuildFile; fileRef = 72B732F01899B2430060E6D4 /* cfilstat.c */; };
+ 72B7F36B1BA69352003A9AA2 /* if6lowpan.c in Sources */ = {isa = PBXBuildFile; fileRef = 72B7F36A1BA69281003A9AA2 /* if6lowpan.c */; };
72B894EC0EEDB17C00C218D6 /* libipsec.dylib in Frameworks */ = {isa = PBXBuildFile; fileRef = 72CD1DB50EE8C619005F825D /* libipsec.dylib */; };
72D000C4142BB11100151981 /* dnctl.c in Sources */ = {isa = PBXBuildFile; fileRef = 72D000C3142BB11100151981 /* dnctl.c */; };
72D33F572271319400EF5B5E /* rtadvd_logging.c in Sources */ = {isa = PBXBuildFile; fileRef = 72D33F562271220100EF5B5E /* rtadvd_logging.c */; };
72B732DE1899B0380060E6D4 /* cfilutil.1 */ = {isa = PBXFileReference; lastKnownFileType = text.man; path = cfilutil.1; sourceTree = "<group>"; };
72B732EE1899B23A0060E6D4 /* cfilutil.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = cfilutil.c; sourceTree = "<group>"; };
72B732F01899B2430060E6D4 /* cfilstat.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = cfilstat.c; sourceTree = "<group>"; };
+ 72B7F36A1BA69281003A9AA2 /* if6lowpan.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = if6lowpan.c; sourceTree = "<group>"; };
72CD1DB50EE8C619005F825D /* libipsec.dylib */ = {isa = PBXFileReference; lastKnownFileType = "compiled.mach-o.dylib"; name = libipsec.dylib; path = /usr/lib/libipsec.dylib; sourceTree = "<absolute>"; };
72D000C3142BB11100151981 /* dnctl.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = dnctl.c; sourceTree = "<group>"; };
72D33F552271220100EF5B5E /* rtadvd_logging.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = rtadvd_logging.h; sourceTree = "<group>"; };
726120540EE86F0900AFED1B /* ifconfig.tproj */ = {
isa = PBXGroup;
children = (
+ 72B7F36A1BA69281003A9AA2 /* if6lowpan.c */,
72E650A2107BF2F000AAF325 /* af_inet.c */,
72E650A3107BF2F000AAF325 /* af_inet6.c */,
72E650A4107BF2F000AAF325 /* af_link.c */,
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
+ 72B7F36B1BA69352003A9AA2 /* if6lowpan.c in Sources */,
7261215A0EE8883900AFED1B /* ifbond.c in Sources */,
7261215B0EE8883900AFED1B /* ifconfig.c in Sources */,
7261215C0EE8883900AFED1B /* ifmedia.c in Sources */,
"__APPLE_USE_RFC_3542=1",
"__APPLE_API_OBSOLETE=1",
);
- "GCC_PREPROCESSOR_DEFINITIONS[sdk=iphoneos*][arch=*]" = (
- "$(inherited)",
- "TARGET_OS_EMBEDDED=1",
- );
GCC_TREAT_WARNINGS_AS_ERRORS = YES;
GCC_WARN_64_TO_32_BIT_CONVERSION = NO;
PREBINDING = NO;
"__APPLE_USE_RFC_3542=1",
"__APPLE_API_OBSOLETE=1",
);
- "GCC_PREPROCESSOR_DEFINITIONS[sdk=iphoneos*][arch=*]" = (
- "$(inherited)",
- "TARGET_OS_EMBEDDED=1",
- );
GCC_TREAT_WARNINGS_AS_ERRORS = YES;
GCC_WARN_64_TO_32_BIT_CONVERSION = NO;
PREBINDING = NO;
"__APPLE_USE_RFC_3542=1",
"__APPLE_API_OBSOLETE=1",
);
- "GCC_PREPROCESSOR_DEFINITIONS[sdk=iphoneos*][arch=*]" = (
- "$(inherited)",
- "TARGET_OS_EMBEDDED=1",
- );
GCC_TREAT_WARNINGS_AS_ERRORS = NO;
GCC_WARN_64_TO_32_BIT_CONVERSION = NO;
PREBINDING = NO;
COPY_PHASE_STRIP = NO;
GCC_DYNAMIC_NO_PIC = NO;
GCC_OPTIMIZATION_LEVEL = 0;
- "GCC_PREPROCESSOR_DEFINITIONS[sdk=yola4.0.internal][arch=*]" = (
- "$(inherited)",
- "TARGET_OS_EMBEDDED=1",
- );
PRODUCT_NAME = "All-EmbeddedOther";
SDKROOT = iphoneos;
SUPPORTED_PLATFORMS = "iphonesimulator iphoneos";
errx(1, "gethostbyname2: illegal address");
memcpy(&sock_in.sin_addr, hp->h_addr_list[0],
sizeof(sock_in.sin_addr));
- (void)strncpy(snamebuf, hp->h_name,
- sizeof(snamebuf) - 1);
- snamebuf[sizeof(snamebuf) - 1] = '\0';
+ (void)strlcpy(snamebuf, hp->h_name,
+ sizeof(snamebuf));
shostname = snamebuf;
}
if (bind(s, (struct sockaddr *)&sock_in, sizeof sock_in) == -1)
if ((unsigned)hp->h_length > sizeof(to->sin_addr))
errx(1, "gethostbyname2 returned an illegal address");
memcpy(&to->sin_addr, hp->h_addr_list[0], sizeof to->sin_addr);
- (void)strncpy(hnamebuf, hp->h_name, sizeof(hnamebuf) - 1);
- hnamebuf[sizeof(hnamebuf) - 1] = '\0';
+ (void)strlcpy(hnamebuf, hp->h_name, sizeof(hnamebuf));
hostname = hnamebuf;
}
{ NULL, 0, NULL, 0 }
};
-
#define IN6LEN sizeof(struct in6_addr)
#define SA6LEN sizeof(struct sockaddr_in6)
#define DUMMY_PORT 10101
t = strtod(optarg, &e);
if (*optarg == '\0' || *e != '\0')
errx(1, "illegal timing interval %s", optarg);
- if (t < 1 && getuid()) {
+ if (t < 0.1 && getuid()) {
errx(1, "%s: only root may use interval < 1s",
strerror(EPERM));
}
"Success", "Refused", "Unknown",
};
-
/*
* pr_icmph --
* Print a descriptive string about an ICMP header.
l = p - name;
if (l > 63 || l > sizeof(hbuf) - 1)
return NULL; /*label too long*/
- strncpy(hbuf, name, l);
+ strlcpy(hbuf, name, l);
hbuf[(int)l] = '\0';
for (q = name; *q; q++) {
{
struct ctl_info info;
memset(&info, 0, sizeof(info));
- strncpy(info.ctl_name, PACKET_MANGLER_CONTROL_NAME, sizeof(info.ctl_name));
+ strlcpy(info.ctl_name, PACKET_MANGLER_CONTROL_NAME, sizeof(info.ctl_name));
if (ioctl(sf, CTLIOCGINFO, &info)) {
perror("Could not get ID for kernel control.\n");
exit(-1);
err(FATAL, "BIOCIMMEDIATE: %s", strerror(errno));
/* NOTREACHED */
}
- (void) strncpy(ifr.ifr_name, device, sizeof ifr.ifr_name);
+ (void) strlcpy(ifr.ifr_name, device, sizeof ifr.ifr_name);
if (ioctl(fd, BIOCSETIF, (caddr_t) & ifr) < 0) {
err(FATAL, "BIOCSETIF: %s", strerror(errno));
/* NOTREACHED */
err(FATAL, "socket: %s", strerror(errno));
/* NOTREACHED */
}
- (void) strncpy(ifr.ifr_name, ifname, sizeof ifr.ifr_name);
+ (void) strlcpy(ifr.ifr_name, ifname, sizeof ifr.ifr_name);
if (ioctl(fd, SIOCGIFADDR, (char *) &ifr) < 0) {
err(FATAL, "SIOCGIFADDR: %s", strerror(errno));
/* NOTREACHED */
}
}
if (cp) {
- strncpy(line, cp, sizeof(line) - 1);
- line[sizeof(line) - 1] = '\0';
+ strlcpy(line, cp, sizeof(line));
} else {
/* XXX - why not inet_ntoa()? */
#define C(x) (unsigned)((x) & 0xff)
niflags |= NI_NUMERICHOST;
if (getnameinfo((struct sockaddr *)&sin6, sin6.sin6_len,
line, sizeof(line), NULL, 0, niflags) != 0)
- strncpy(line, "invalid", sizeof(line));
+ strlcpy(line, "invalid", sizeof(line));
return(line);
}
}
#define C(x) (unsigned)((x) & 0xff)
if (cp != NULL)
- strncpy(line, cp, sizeof(line));
+ strlcpy(line, cp, sizeof(line));
else if ((in.s_addr & 0xffffff) == 0)
(void) sprintf(line, "%u", C(in.s_addr >> 24));
else if ((in.s_addr & 0xffff) == 0)
niflags |= NI_NUMERICHOST;
if (getnameinfo((struct sockaddr *)&sin6, sin6.sin6_len,
line, sizeof(line), NULL, 0, niflags) != 0)
- strncpy(line, "invalid", sizeof(line));
+ strlcpy(line, "invalid", sizeof(line));
return(line);
}
}
break;
}
- if (cp >= bp + BUFSIZ) {
+ if (cp >= bp + BUFSIZ - 1) {
write(STDERR_FILENO, "Remcap entry too long\n",
- 23);
+ 22);
break;
} else
*cp++ = c;
exit(1);
}
memset(&ndi, 0, sizeof(ndi));
- strncpy(ndi.ifname, intface, IFNAMSIZ);
+ strlcpy(ndi.ifname, intface, sizeof(ndi.ifname));
if (ioctl(s, SIOCGIFINFO_IN6, (caddr_t)&ndi) < 0) {
infolog("<%s> ioctl:SIOCGIFINFO_IN6 at %s: %s",
__func__, intface, strerror(errno));
prefix->onlinkflg = ipr->ipr_raf_onlink;
prefix->autoconfflg = ipr->ipr_raf_auto;
prefix->origin = PREFIX_FROM_DYNAMIC;
+ prefix->rainfo = rai;
insque(prefix, &rai->prefix);
- prefix->rainfo = rai;
debuglog("<%s> new prefix %s/%d was added on %s",
__func__, inet_ntop(AF_INET6, &ipr->ipr_prefix.sin6_addr,
return(0);
ifr.ifr_addr.sa_family = AF_INET6;
- strncpy(ifr.ifr_name, name,
+ strlcpy(ifr.ifr_name, name,
sizeof(ifr.ifr_name));
if (ioctl(s, SIOCGIFMTU, (caddr_t)&ifr) < 0) {
close(s);
struct ifreq ifr;
int llflag;
- strncpy(ifr.ifr_name, name, sizeof(ifr.ifr_name));
+ strlcpy(ifr.ifr_name, name, sizeof(ifr.ifr_name));
if (ioctl(ifsock, SIOCGIFFLAGS, (caddr_t)&ifr) < 0) {
warnmsg(LOG_WARNING, __FUNCTION__, "ioctl(SIOCGIFFLAGS): %s",
/* get interface flags */
memset(&ifr, 0, sizeof(ifr));
- strncpy(ifr.ifr_name, ifname, sizeof(ifr.ifr_name));
+ strlcpy(ifr.ifr_name, ifname, sizeof(ifr.ifr_name));
if (ioctl(ifsock, SIOCGIFFLAGS, &ifr) < 0) {
warnmsg(LOG_ERR, __FUNCTION__, "ioctl(SIOCGIFFLAGS) on %s: %s",
ifname, strerror(errno));
if (!ifinfo->mediareqok)
goto active;
memset(&ifmr, 0, sizeof(ifmr));
- strncpy(ifmr.ifm_name, ifname, sizeof(ifmr.ifm_name));
+ strlcpy(ifmr.ifm_name, ifname, sizeof(ifmr.ifm_name));
if (ioctl(ifsock, SIOCGIFMEDIA, (caddr_t)&ifmr) < 0) {
if (errno != EINVAL) {
memset(ifinfo, 0, sizeof(*ifinfo));
ifinfo->sdl = sdl;
- strncpy(ifinfo->ifname, ifname, sizeof(ifinfo->ifname));
+ strlcpy(ifinfo->ifname, ifname, sizeof(ifinfo->ifname));
/* construct a router solicitation message */
if (make_packet(ifinfo))
}
if (target) {
- strncpy(ifname, target->ifa_name, sizeof(ifname) - 1);
- ifname[sizeof(ifname) - 1] = '\0';
+ strlcpy(ifname, target->ifa_name, sizeof(ifname));
argv[0] = ifname;
argv[1] = NULL;
* SIOCGIFFLAGS stomps over it because the requests
* are returned in a union.)
*/
- strncpy(ifr.ifr_name, ifrp->ifr_name, sizeof(ifr.ifr_name));
+ strlcpy(ifr.ifr_name, ifrp->ifr_name, sizeof(ifr.ifr_name));
if (ioctl(fd, SIOCGIFFLAGS, (char *)&ifr) < 0) {
if (errno == ENXIO)
continue;
continue;
- (void)strncpy(device, ifr.ifr_name, sizeof(ifr.ifr_name));
- device[sizeof(device) - 1] = '\0';
+ (void)strlcpy(device, ifr.ifr_name, sizeof(device));
#ifdef sun
/* Ignore sun virtual interfaces */
if (strchr(device, ':') != NULL)
domain[0] = '\0';
else {
++cp;
- (void)strncpy(domain, cp, sizeof(domain) - 1);
- domain[sizeof(domain) - 1] = '\0';
+ memmove(domain, cp, strlen(cp) + 1);
}
}
}
if ((cp = strchr(hp->h_name, '.')) != NULL &&
strcmp(cp + 1, domain) == 0)
*cp = '\0';
- (void)strncpy(line, hp->h_name, sizeof(line) - 1);
- line[sizeof(line) - 1] = '\0';
+ (void)strlcpy(line, hp->h_name, sizeof(line));
return (line);
}
}
*
* This file contains pipe service functions.
*/
+#include <sys/time.h>
#include "config.h"
#include "util/tube.h"
#include "util/log.h"