+/*
+ * Copyright (c) 2004-2015 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) 1988, 1989, 1991, 1994, 1995, 1996, 1997, 1998, 1999, 2000
* The Regents of the University of California. All rights reserved.
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*/
+#include <sys/cdefs.h>
+
#ifndef lint
-static const char copyright[] =
+__unused static const char copyright[] =
"@(#) Copyright (c) 1988, 1989, 1991, 1994, 1995, 1996, 1997, 1998, 1999, 2000\n\
The Regents of the University of California. All rights reserved.\n";
-#if 0
-static const char rcsid[] =
- "@(#)$Id: traceroute.c,v 1.4 2006/02/07 06:22:57 lindak Exp $ (LBL)";
-#endif
-static const char rcsid[] =
- "$FreeBSD: src/contrib/traceroute/traceroute.c,v 1.35 2008/02/20 23:29:52 rpaulo Exp $";
#endif
/*
int sump = 0;
int sockerrno = 0;
+ if (argv[0] == NULL)
+ prog = "traceroute";
+ else if ((cp = strrchr(argv[0], '/')) != NULL)
+ prog = cp + 1;
+ else
+ prog = argv[0];
+
/* Insure the socket fds won't be 0, 1 or 2 */
if (open(devnull, O_RDONLY) < 0 ||
open(devnull, O_RDONLY) < 0 ||
max_ttl = 30;
#endif
- if (argv[0] == NULL)
- prog = "traceroute";
- else if ((cp = strrchr(argv[0], '/')) != NULL)
- prog = cp + 1;
- else
- prog = argv[0];
-
opterr = 0;
while ((op = getopt(argc, argv, "aA:edDFInrSvxf:g:i:M:m:P:p:q:s:t:w:z:")) != EOF)
switch (op) {
Fprintf(stderr, "%s: icmp socket: %s\n", prog, strerror(errno));
exit(1);
}
+ (void) setsockopt(s, SOL_SOCKET, SO_RECV_ANYIF, (char *)&on,
+ sizeof(on));
if (options & SO_DEBUG)
(void)setsockopt(s, SOL_SOCKET, SO_DEBUG, (char *)&on,
sizeof(on));
sizeof(on));
/* Get the interface address list */
- n = ifaddrlist(&al, errbuf);
+ n = ifaddrlist(&al, errbuf, sizeof(errbuf));
if (n < 0) {
Fprintf(stderr, "%s: ifaddrlist: %s\n", prog, errbuf);
exit(1);
socklen_t fromlen = sizeof(*fromp);
nfds = howmany(sock + 1, NFDBITS);
- if ((fdsp = malloc(nfds * sizeof(fd_mask))) == NULL)
+ if ((fdsp = malloc(nfds * sizeof(fd_set))) == NULL)
err(1, "malloc");
- memset(fdsp, 0, nfds * sizeof(fd_mask));
+ memset(fdsp, 0, nfds * sizeof(fd_set));
FD_SET(sock, fdsp);
wait.tv_sec = tp->tv_sec + waittime;
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);
}
}