rem: char * any_ntoa(sa) const struct sockaddr *sa;
add: char * any_ntoa(const struct sockaddr *sa)
context: char	*routename __P((struct sockaddr *));char	*netname __P((struct sockaddr *));void	 flushroutes __P((int, char **));int	 newroute __P((int, char **));void	 monitor __P((void));#ifdef INET6static int prefixlen __P((char *));#endifvoid	 sockaddr __P((char *, struct sockaddr *));void	 sodump __P((sup, char *));void	 print_getmsg __P((struct rt_msghdr *, int));void	 print_rtmsg __P((struct rt_msghdr *, int));void	 pmsg_common __P((struct rt_msghdr *));void	 pmsg_addrs __P((char *, int));void	 bprintf __P((FILE *, int, u_char *));void	 mask_addr __P((void));//int	 getaddr __P((int, char *, struct hostent **));int	 rtmsg __P((int, int));int	 x25_makemask __P((void));extern void show __P((int, char **));	/* XXX - from show.c */int opterr = 1;int optind = 1;int optopt = 0;int optreset = 0;char *optarg;#define BADCH (int)'?'#define BADARG (int)':'#define EMSG ""int _getopt(int nargc, char *const *nargv, const char *ostr){	static char *place = EMSG;	char *oli;		if (optreset || !*place) {		optreset = 0;		if (optind >= nargc || *(place = nargv[optind]) != '-') {			place = EMSG;			return -1;		}		if (place[1] && *++place=='-') {			++optind;			place=EMSG;			return -1;		}	}	if ((optopt = (int)*place++) == (int)':' || 	    !(oli = strchr(ostr, optopt))) {		if (optopt==(int)'-')			return -1;		if (!*place)			++optind;		if (opterr && *ostr != ':')			fprintf(stderr, "illegal option --%c\n", optopt);		return BADCH;	}	if (*++oli != ':') {		optarg = NULL;		if (!*place)			++optind;	} else {		if (*place)			optarg = place;		else if (nargc <= ++optind) {			place = EMSG;			if (*ostr==':')				return BADARG;			if (opterr)				printf("option requires an argument -- %c\n", optopt);			return BADCH;		} else 			optarg = nargv[optind];		place = EMSG;		++optind;	}	return optopt;} 	void usage(char *cp){	printf("route for OpenBeOS!\n");	if (cp)		(void) fprintf(stderr, "route: botched keyword: %s\n", cp);	(void) fprintf(stderr,	    "usage: route [ -nqv ] cmd [[ -<modifiers> ] args ]\n");	(void) fprintf(stderr,	    "keywords: get, add, change, delete, show, flush, monitor.\n");	exit(1);	/* NOTREACHED */}void quit(char *s){	int sverrno = errno;	(void) fprintf(stderr, "route: ");	if (s)		(void) fprintf(stderr, "%s: ", s);	(void) fprintf(stderr, "%s\n", strerror(sverrno));	exit(1);	/* NOTREACHED */}#define ROUNDUP(a) \	((a) > 0 ? (1 + (((a) - 1) | (sizeof(long) - 1))) : sizeof(long))#define ADVANCE(x, n) (x += ROUNDUP((n)->sa_len))intmain(argc, argv)	int argc;	char **argv;{	int ch;	int rval = 0;	if (argc < 2)		usage(NULL);	while ((ch = _getopt(argc, argv, "nqdtv")) != -1) {		switch(ch) {			case (int)'n':				nflag = 1;				break;			case 'q':				qflag = 1;				break;			case 'v':				verbose = 1;				break;			case 't':				tflag = 1;				break;			case 'd':				debugonly = 1;				break;			default:				usage(NULL);		}	}	argc -= optind;	argv += optind;	pid = getpid();	uid = getuid();	if (tflag)		s = open("/dev/null", O_WRONLY);	else		s = socket(PF_ROUTE, SOCK_RAW, 0);	if (s < 0)		quit("socket");	if (*argv == NULL)		goto no_cmd;	switch (keyword(*argv)) {	case K_GET:		uid = 0;		/* FALLTHROUGH */	case K_CHANGE:	case K_ADD:	case K_DELETE:		rval = newroute(argc, argv);		break;	case K_SHOW:		uid = 0;		show(argc, argv);		break;	case K_MONITOR:		monitor();		break;	case K_FLUSH:		flushroutes(argc, argv);		break;	no_cmd:	default:		usage(*argv);	}	exit(rval);}/* * Purge all entries in the routing tables not * associated with network interfaces. */voidflushroutes(argc, argv)	int argc;	char *argv[];{	size_t needed;	int mib[6], rlen, seqno;	char *buf = NULL, *next, *lim = NULL;	struct rt_msghdr *rtm;	struct sockaddr *sa;	if (uid) {		errno = EACCES;		quit("must be root to alter routing table");	}	shutdown(s, 0); /* Don't want to read back our messages */	if (argc > 1) {		argv++;		if (argc == 2 && **argv == '-')		    switch (keyword(*argv + 1)) {			case K_INET:				af = AF_INET;				break;#ifdef INET6			case K_INET6:				af = AF_INET6;				break;#endif			case K_LINK:				af = AF_LINK;				break;			default:				goto bad;		} elsebad:			usage(*argv);	}	mib[0] = PF_ROUTE;	mib[1] = 0;		/* protocol */	mib[2] = 0;		/* wildcard address family */	mib[3] = NET_RT_DUMP;	mib[4] = 0;		/* no flags */	if (sysctl(mib, 5, NULL, &needed, NULL, 0) < 0)		quit("route-sysctl-estimate");	if (needed) {		if ((buf = malloc(needed)) == NULL)			quit("malloc");		if (sysctl(mib, 5, buf, &needed, NULL, 0) < 0)			quit("actual retrieval of routing table");		lim = buf + needed;	}	if (verbose) {		(void) printf("Examining routing table from sysctl\n");		 if (af)			printf("(address family %s)\n", (*argv + 1));	}	if (buf == NULL)		return;	seqno = 0;		/* ??? */	for (next = buf; next < lim; next += rtm->rtm_msglen) {		rtm = (struct rt_msghdr *)next;		if (verbose)			print_rtmsg(rtm, rtm->rtm_msglen);		if ((rtm->rtm_flags & (RTF_GATEWAY|RTF_STATIC|RTF_LLINFO)) == 0)			continue;		sa = (struct sockaddr *)(rtm + 1);		if (af) {			if (sa->sa_family != af)				continue;		}		if (debugonly)			continue;		rtm->rtm_type = RTM_DELETE;		rtm->rtm_seq = seqno;		rlen = write(s, next, rtm->rtm_msglen);printf("write gave %d\n", rlen);		if (rlen < (int)rtm->rtm_msglen) {			(void) fprintf(stderr,			    "route: write to routing socket: %s\n",			    strerror(errno));			(void) printf("got only %d for rlen\n", rlen);			break;		}		seqno++;		if (qflag)			continue;		if (verbose)			print_rtmsg(rtm, rlen);		else {			struct sockaddr *sa = (struct sockaddr *)(rtm + 1);			(void) printf("%-20.20s ", rtm->rtm_flags & RTF_HOST ?			    routename(sa) : netname(sa));			sa = (struct sockaddr *)(ROUNDUP(sa->sa_len) + (char *)sa);			(void) printf("%-20.20s ", routename(sa));			(void) printf("done\n");		}	}	free(buf);}static char hexlist[] = "0123456789abcdef";char *any_ntoa(sa)	const struct sockaddr *sa;{	static char obuf[240];	const char *in = sa->sa_data;	char *out = obuf;	int len = sa->sa_len;	*out++ = 'Q';	do {		*out++ = hexlist[(*in >> 4) & 15];		*out++ = hexlist[(*in++)    & 15];		*out++ = '.';	} while (--len > 0 && (out + 3) < &obuf[sizeof obuf-1]);	out[-1] = '\0';	return (obuf);}char *routename(struct sockaddr *sa){	char *cp = NULL;	static char line[MAXHOSTNAMELEN];	struct hostent *hp;	static char domain[MAXHOSTNAMELEN];	static int first = 1;	char *ns_print();	char *ipx_print();	if (first) {		first = 0;		if (gethostname(domain, sizeof domain) == 0 &&		    (cp = strchr(domain, '.')))			(void) strcpy(domain, cp + 1);		else			domain[0] = 0;		cp = NULL;	}	if (sa->sa_len == 0)		strcpy(line, "default");	else switch (sa->sa_family) {	case AF_INET:	    {	struct in_addr in;		in = ((struct sockaddr_in *)sa)->sin_addr;		if (in.s_addr == INADDR_ANY || sa->sa_len < 4)			cp = "default";		if (!cp && !nflag) {			if ((hp = gethostbyaddr((char *)&in.s_addr,			    sizeof (in.s_addr), AF_INET)) != NULL) {				if ((cp = strchr(hp->h_name, '.')) &&				    !strcmp(cp + 1, domain))					*cp = 0;				cp = hp->h_name;			}		}		strncpy(line, cp ? cp : inet_ntoa(in), sizeof line);		break;	    }#ifdef INET6	case AF_INET6:	    {		struct sockaddr_in6 sin6;		int niflags;#ifdef NI_WITHSCOPEID		niflags = NI_WITHSCOPEID;#else		niflags = 0;#endif		if (nflag)			niflags |= NI_NUMERICHOST;		memset(&sin6, 0, sizeof(sin6));		memcpy(&sin6, sa, sa->sa_len);		sin6.sin6_len = sizeof(struct sockaddr_in6);		sin6.sin6_family = AF_INET6;#ifdef __KAME__		if (sa->sa_len == sizeof(struct sockaddr_in6) &&		    (IN6_IS_ADDR_LINKLOCAL(&sin6.sin6_addr) ||		     IN6_IS_ADDR_MC_LINKLOCAL(&sin6.sin6_addr)) &&		    sin6.sin6_scope_id == 0) {			sin6.sin6_scope_id =			    ntohs(*(uint16 *)&sin6.sin6_addr.s6_addr[2]);			sin6.sin6_addr.s6_addr[2] = 0;			sin6.sin6_addr.s6_addr[3] = 0;		}#endif		if (getnameinfo((struct sockaddr *)&sin6, sin6.sin6_len,		    line, sizeof(line), NULL, 0, niflags) != 0)			strncpy(line, "invalid", sizeof(line));		break;	    }#endif	case AF_LINK:		return (link_ntoa((struct sockaddr_dl *)sa));	default:		(void) snprintf(line, sizeof line, "(%d) %s",		    sa->sa_family, any_ntoa(sa));		break;	}	return (line);}