/*
- * Copyright (c) 1999 Apple Computer, Inc. All rights reserved.
+ * Copyright (c) 2008 Apple Inc. All rights reserved.
+ *
+ * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
*
- * @APPLE_LICENSE_HEADER_START@
- *
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* 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. Please obtain a copy of the License at
- * http://www.opensource.apple.com/apsl/ and read it before using this
- * file.
- *
+ * 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,
* 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_LICENSE_HEADER_END@
+ *
+ * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
*/
/*
* Copyright (c) 1983, 1989, 1991, 1993
* SUCH DAMAGE.
*/
+#include <sys/cdefs.h>
#ifndef lint
-static const char copyright[] =
+__unused static const char copyright[] =
"@(#) Copyright (c) 1983, 1989, 1991, 1993\n\
The Regents of the University of California. All rights reserved.\n";
#endif /* not lint */
#if 0
static char sccsid[] = "@(#)route.c 8.3 (Berkeley) 3/19/94";
#endif
-static const char rcsid[] =
- "$Id: route.c,v 1.3 2003/01/07 21:03:05 bbraun Exp $";
+__unused static const char rcsid[] =
+ "$Id: route.c,v 1.4 2006/02/07 06:22:29 lindak Exp $";
#endif /* not lint */
#include <sys/param.h>
#include <net/route.h>
#include <net/if_dl.h>
#include <netinet/in.h>
-#ifndef __APPLE__
-#include <netatalk/at.h>
-#endif
-#ifdef NS
-#include <netns/ns.h>
-#endif
#include <arpa/inet.h>
#include <netdb.h>
{0, 0}
};
-struct ortentry route;
union sockunion {
struct sockaddr sa;
struct sockaddr_in sin;
#ifdef INET6
struct sockaddr_in6 sin6;
-#endif
-#ifndef __APPLE__
- struct sockaddr_at sat;
-#endif
-#ifdef NS
- struct sockaddr_ns sns;
#endif
struct sockaddr_dl sdl;
struct sockaddr_storage ss; /* added to avoid memory overrun */
int locking, lockrest, debugonly;
struct rt_metrics rt_metrics;
u_long rtm_inits;
-#ifndef __APPLE__
-int atalk_aton __P((const char *, struct at_addr *));
-char *atalk_ntoa __P((struct at_addr));
-#endif
+unsigned int ifscope;
const char *routename(), *netname();
void flushroutes(), newroute(), monitor(), sockaddr(), sodump(), bprintf();
void print_getmsg(), print_rtmsg(), pmsg_common(), pmsg_addrs(), mask_addr();
int prefixlen();
extern char *iso_ntoa();
-void usage __P((const char *));
+void usage __P((const char *)) __dead2;
void
usage(cp)
}
#define ROUNDUP(a) \
- ((a) > 0 ? (1 + (((a) - 1) | (sizeof(long) - 1))) : sizeof(long))
+ ((a) > 0 ? (1 + (((a) - 1) | (sizeof(uint32_t) - 1))) : sizeof(uint32_t))
#define ADVANCE(x, n) (x += ROUNDUP((n)->sa_len))
int
case K_INET6:
af = AF_INET6;
break;
-#endif
-#ifndef __APPLE__
- case K_ATALK:
- af = AF_APPLETALK;
- break;
-#endif
-#ifdef NS
- case K_XNS:
- af = AF_NS;
- break;
#endif
case K_LINK:
af = AF_LINK;
struct hostent *hp;
static char domain[MAXHOSTNAMELEN + 1];
static int first = 1;
-#ifdef NS
- char *ns_print();
-#endif
if (first) {
first = 0;
return(line);
}
#endif
-#ifndef __APPLE__
- case AF_APPLETALK:
- (void) snprintf(line, sizeof(line), "atalk %s",
- atalk_ntoa(((struct sockaddr_at *)sa)->sat_addr));
- break;
-#endif
-
-#ifdef NS
- case AF_NS:
- return (ns_print((struct sockaddr_ns *)sa));
-#endif
case AF_LINK:
return (link_ntoa((struct sockaddr_dl *)sa));
char *cp = 0;
static char line[MAXHOSTNAMELEN + 1];
struct netent *np = 0;
- u_long net, mask;
- register u_long i;
+ in_addr_t net, mask;
+ register in_addr_t i;
int subnetshift;
-#ifdef NS
- char *ns_print();
-#endif
switch (sa->sa_family) {
* width subnet fields.
*/
while (in.s_addr &~ mask)
- mask = (long)mask >> subnetshift;
+ mask = mask >> subnetshift;
net = in.s_addr & mask;
while ((mask & 1) == 0)
mask >>= 1, net >>= 1;
}
#endif
-#ifndef __APPLE__
- case AF_APPLETALK:
- (void) snprintf(line, sizeof(line), "atalk %s",
- atalk_ntoa(((struct sockaddr_at *)sa)->sat_addr));
- break;
-#endif
-
-#ifdef NS
- case AF_NS:
- return (ns_print((struct sockaddr_ns *)sa));
- break;
-#endif
-
case AF_LINK:
return (link_ntoa((struct sockaddr_dl *)sa));
int key;
{
int flag = 0;
- u_long noval, *valp = &noval;
+ u_int noval, *valp = &noval;
switch (key) {
-#define caseof(x, y, z) case x: valp = &rt_metrics.z; flag = y; break
+#define caseof(x, y, z) case x: valp = (u_int *)&rt_metrics.z; flag = y; break
caseof(K_MTU, RTV_MTU, rmx_mtu);
caseof(K_HOPCOUNT, RTV_HOPCOUNT, rmx_hopcount);
caseof(K_EXPIRE, RTV_EXPIRE, rmx_expire);
af = AF_INET6;
aflen = sizeof(struct sockaddr_in6);
break;
-#endif
-#ifndef __APPLE__
- case K_ATALK:
- af = AF_APPLETALK;
- aflen = sizeof(struct sockaddr_at);
- break;
#endif
case K_SA:
af = PF_ROUTE;
aflen = sizeof(union sockunion);
break;
-#ifdef NS
- case K_XNS:
- af = AF_NS;
- aflen = sizeof(struct sockaddr_ns);
- break;
-#endif
case K_IFACE:
case K_INTERFACE:
iflag++;
usage((char *)NULL);
set_metric(*++argv, key);
break;
+ case K_IFSCOPE:
+ if (!--argc)
+ usage((char *)NULL);
+ if ((ifscope = if_nametoindex(*++argv)) != 0)
+ flags |= RTF_IFSCOPE;
+ else
+ errx(1, "bad interface name");
+ break;
default:
usage(1+*argv);
}
if (*gateway) {
(void) printf(": gateway %s", gateway);
if (attempts > 1 && ret == 0 && af == AF_INET)
- (void) printf(" (%s)",
- inet_ntoa(((struct sockaddr_in *)&route.rt_gateway)->sin_addr));
+ (void) printf(" (%s)", inet_ntoa(so_gate.sin.sin_addr));
}
if (ret == 0)
(void) printf("\n");
void
inet_makenetandmask(net, sin, bits)
- u_long net, bits;
+ in_addr_t net, bits;
register struct sockaddr_in *sin;
{
- u_long addr, mask = 0;
+ in_addr_t addr, mask = 0;
register char *cp;
rtm_addrs |= RTA_NETMASK;
char *s;
struct hostent **hpp;
{
- register sup su;
+ register sup su = NULL;
struct hostent *hp;
struct netent *np;
- u_long val;
+ in_addr_t val;
char *q;
int afamily; /* local copy of af so we can change it */
}
#endif /* INET6 */
-#ifdef NS
- case AF_NS:
- if (which == RTA_DST) {
- extern short ns_bh[3];
- struct sockaddr_ns *sms = &(so_mask.sns);
- bzero((char *)sms, sizeof(*sms));
- sms->sns_family = 0;
- sms->sns_len = 6;
- sms->sns_addr.x_net = *(union ns_net *)ns_bh;
- rtm_addrs |= RTA_NETMASK;
- }
- su->sns.sns_addr = ns_addr(s);
- return (!ns_nullhost(su->sns.sns_addr));
-#endif
-
-
-#ifndef __APPLE__
- case AF_APPLETALK:
- if (!atalk_aton(s, &su->sat.sat_addr))
- errx(EX_NOHOST, "bad address: %s", s);
- rtm_addrs |= RTA_NETMASK;
- return(forcehost || su->sat.sat_addr.s_node != 0);
-#endif
-
case AF_LINK:
link_addr(s, &su->sdl);
return (1);
return len;
}
-#ifdef NS
-short ns_nullh[] = {0,0,0};
-short ns_bh[] = {-1,-1,-1};
-
-char *
-ns_print(sns)
- struct sockaddr_ns *sns;
-{
- struct ns_addr work;
- union { union ns_net net_e; u_long long_e; } net;
- u_short port;
- static char mybuf[50+MAXHOSTNAMELEN], cport[10], chost[25];
- char *host = "";
- register char *p;
- register u_char *q;
-
- work = sns->sns_addr;
- port = ntohs(work.x_port);
- work.x_port = 0;
- net.net_e = work.x_net;
- if (ns_nullhost(work) && net.long_e == 0) {
- if (!port)
- return ("*.*");
- (void) sprintf(mybuf, "*.%XH", port);
- return (mybuf);
- }
-
- if (bcmp((char *)ns_bh, (char *)work.x_host.c_host, 6) == 0)
- host = "any";
- else if (bcmp((char *)ns_nullh, (char *)work.x_host.c_host, 6) == 0)
- host = "*";
- else {
- q = work.x_host.c_host;
- (void) sprintf(chost, "%02X%02X%02X%02X%02X%02XH",
- q[0], q[1], q[2], q[3], q[4], q[5]);
- for (p = chost; *p == '0' && p < chost + 12; p++)
- /* void */;
- host = p;
- }
- if (port)
- (void) sprintf(cport, ".%XH", htons(port));
- else
- *cport = 0;
-
- (void) snprintf(mybuf, sizeof(mybuf), "%lxH.%s%s",
- (unsigned long)ntohl(net.long_e),
- host, cport);
- return (mybuf);
-}
-#endif
-
void
interfaces()
{
rtm.rtm_addrs = rtm_addrs;
rtm.rtm_rmx = rt_metrics;
rtm.rtm_inits = rtm_inits;
+ rtm.rtm_index = ifscope;
if (rtm_addrs & RTA_NETMASK)
mask_addr();
if ((rtm_addrs & RTA_DST) == 0)
return;
switch (so_dst.sa.sa_family) {
-#ifdef NS
- case AF_NS:
-#endif
case AF_INET:
#ifdef INET6
case AF_INET6:
"\011pksent\010rttvar\7rtt\6ssthresh\5sendpipe\4recvpipe\3expire\2hopcount"
"\1mtu";
char routeflags[] =
-"\1UP\2GATEWAY\3HOST\4REJECT\5DYNAMIC\6MODIFIED\7DONE\010MASK_PRESENT"
+"\1UP\2GATEWAY\3HOST\4REJECT\5DYNAMIC\6MODIFIED\7DONE\010DELCLONE"
"\011CLONING\012XRESOLVE\013LLINFO\014STATIC\015BLACKHOLE\016b016"
-"\017PROTO2\020PROTO1\021PRCLONING\022WASCLONED\023PROTO3\024CHAINDELETE"
-"\025PINNED\026LOCAL\027BROADCAST\030MULTICAST";
+"\017PROTO2\020PROTO1\021PRCLONING\022WASCLONED\023PROTO3\024b024"
+"\025PINNED\026LOCAL\027BROADCAST\030MULTICAST\031IFSCOPE\032CONDEMNED"
+"\033IFREF";
char ifnetflags[] =
"\1UP\2BROADCAST\3DEBUG\4LOOPBACK\5PTP\6b6\7RUNNING\010NOARP"
"\011PPROMISC\012ALLMULTI\013OACTIVE\014SIMPLEX\015LINK0\016LINK1"
break;
#endif
default:
- (void) printf("pid: %ld, seq %d, errno %d, flags:",
+ (void) printf("pid: %ld, seq %d, errno %d, ",
(long)rtm->rtm_pid, rtm->rtm_seq, rtm->rtm_errno);
+ if (rtm->rtm_flags & RTF_IFSCOPE)
+ (void) printf("ifscope %d, ", rtm->rtm_index);
+#ifdef RTF_IFREF
+ if (rtm->rtm_flags & RTF_IFREF)
+ (void) printf("ifref, ");
+#endif /* RTF_IFREF */
+ (void) printf("flags:");
bprintf(stdout, rtm->rtm_flags, routeflags);
pmsg_common(rtm);
}
(void) printf("\n%s\n", "\
recvpipe sendpipe ssthresh rtt,msec rttvar hopcount mtu expire");
- printf("%8ld%c ", rtm->rtm_rmx.rmx_recvpipe, lock(RPIPE));
- printf("%8ld%c ", rtm->rtm_rmx.rmx_sendpipe, lock(SPIPE));
- printf("%8ld%c ", rtm->rtm_rmx.rmx_ssthresh, lock(SSTHRESH));
- printf("%8ld%c ", msec(rtm->rtm_rmx.rmx_rtt), lock(RTT));
- printf("%8ld%c ", msec(rtm->rtm_rmx.rmx_rttvar), lock(RTTVAR));
- printf("%8ld%c ", rtm->rtm_rmx.rmx_hopcount, lock(HOPCOUNT));
- printf("%8ld%c ", rtm->rtm_rmx.rmx_mtu, lock(MTU));
+ printf("%8u%c ", rtm->rtm_rmx.rmx_recvpipe, lock(RPIPE));
+ printf("%8u%c ", rtm->rtm_rmx.rmx_sendpipe, lock(SPIPE));
+ printf("%8u%c ", rtm->rtm_rmx.rmx_ssthresh, lock(SSTHRESH));
+ printf("%8u%c ", msec(rtm->rtm_rmx.rmx_rtt), lock(RTT));
+ printf("%8u%c ", msec(rtm->rtm_rmx.rmx_rttvar), lock(RTTVAR));
+ printf("%8u%c ", rtm->rtm_rmx.rmx_hopcount, lock(HOPCOUNT));
+ printf("%8u%c ", rtm->rtm_rmx.rmx_mtu, lock(MTU));
if (rtm->rtm_rmx.rmx_expire)
rtm->rtm_rmx.rmx_expire -= time(0);
- printf("%8ld%c\n", rtm->rtm_rmx.rmx_expire, lock(EXPIRE));
+ printf("%8d%c\n", rtm->rtm_rmx.rmx_expire, lock(EXPIRE));
#undef lock
#undef msec
#define RTA_IGN (RTA_DST|RTA_GATEWAY|RTA_NETMASK|RTA_IFP|RTA_IFA|RTA_BRD)
(void) printf("%s: inet %s; ",
which, inet_ntoa(su->sin.sin_addr));
break;
-#ifndef __APPLE__
- case AF_APPLETALK:
- (void) printf("%s: atalk %s; ",
- which, atalk_ntoa(su->sat.sat_addr));
- break;
-#endif
-#ifdef NS
- case AF_NS:
- (void) printf("%s: xns %s; ",
- which, ns_ntoa(su->sns.sns_addr));
- break;
-#endif
}
(void) fflush(stdout);
}
} while (cp < cplim);
sa->sa_len = cp - (char *)sa;
}
-
-#ifndef __APPLE__
-int
-atalk_aton(const char *text, struct at_addr *addr)
-{
- u_int net, node;
-
- if (sscanf(text, "%u.%u", &net, &node) != 2
- || net > 0xffff || node > 0xff)
- return(0);
- addr->s_net = htons(net);
- addr->s_node = node;
- return(1);
-}
-
-char *
-atalk_ntoa(struct at_addr at)
-{
- static char buf[20];
-
- (void) snprintf(buf, sizeof(buf), "%u.%u", ntohs(at.s_net), at.s_node);
- return(buf);
-}
-#endif