Ejemplo n.º 1
0
void
conf_print_rtm(FILE *output, struct rt_msghdr *rtm, char *delim, int af)
{
	int i;
	char *cp, flags[64];
	struct sockaddr *dst = NULL, *gate = NULL, *mask = NULL;
	struct sockaddr *sa;
	struct sockaddr_in sin;

	sin.sin_addr.s_addr = htonl(INADDR_BROADCAST);

	cp = ((char *)rtm + rtm->rtm_hdrlen);
	for (i = 1; i; i <<= 1)
		if (i & rtm->rtm_addrs) {
			sa = (struct sockaddr *)cp;
			switch (i) {
			case RTA_DST:
				/* allow arp to get printed with af==AF_LINK */
				if ((sa->sa_family == af) ||
				    (af == AF_LINK && sa->sa_family == AF_INET)) {
					if (rtm->rtm_flags & RTF_REJECT)
						snprintf(flags, sizeof(flags),
						    " reject");
					else
						flags[0] = '\0';
					dst = sa;
				}
				break;
			case RTA_GATEWAY:
				if (sa->sa_family == af)
					gate = sa;
				break;
			case RTA_NETMASK:
				/* netmasks will not have a valid sa_family */
				mask = sa;
				break;
			}
			ADVANCE(cp, sa);
		}
	if (dst && gate && mask && (af == AF_INET || af == AF_INET6)) {
		/*
		 * Suppress printing IPv4 route if it's the default
		 * route and dhcp (dhclient) is enabled.
		 */
		if (!(af == AF_INET && isdefaultroute(dst, mask)
		    && dhclient_isenabled(routename(gate)))) {
			fprintf(output, "%s%s ", delim, netname(dst, mask));
			fprintf(output, "%s%s\n", routename(gate), flags);
		}
	} else if (dst && gate && (af == AF_LINK)) {
		/* print arp */
		fprintf(output, "%s%s ", delim, routename(dst));
		fprintf(output, "%s\n", routename(gate));
	}
}
Ejemplo n.º 2
0
void
conf_print_rtm(FILE *output, struct rt_msghdr *rtm, char *delim, int af)
{
	int i;
	char *cp;
	struct sockaddr *dst = NULL, *gate = NULL, *mask = NULL;
	struct sockaddr *sa;

	cp = ((char *)rtm + rtm->rtm_hdrlen);
	for (i = 1; i; i <<= 1)
		if (i & rtm->rtm_addrs) {
			sa = (struct sockaddr *)cp;
			switch (i) {
			case RTA_DST:
				/* allow arp to get printed with af==AF_LINK */
				if ((sa->sa_family == af) ||
				    (af == AF_LINK && sa->sa_family == AF_INET))
					dst = sa;
				break;
			case RTA_GATEWAY:
				if (sa->sa_family == af)
					gate = sa;
				break;
			case RTA_NETMASK:
				/* netmasks will not have a valid sa_family */
				mask = sa;
				break;
			}
			ADVANCE(cp, sa);
		}
	if (dst && mask && gate && (af == AF_INET || af == AF_INET6)) {
		/*
		 * suppress printing IP route if it's the default
		 * v4 route and dhcp (dhclient) is enabled
		 */
		if (!(isdefaultroute4(dst) && dhclient_isenabled(routename(gate)))) {
			fprintf(output, "%s%s ", delim, netname(dst, mask));
			fprintf(output, "%s\n", routename(gate));
		}
	} else
	if (dst && gate && (af == AF_LINK))
		/* print arp */
		fprintf(output, "%s%s %s\n", delim, routename(dst),
		    routename(gate));
}