Date: Thu, 14 Jul 2011 19:05:48 +0000 (UTC) From: John Baldwin <jhb@FreeBSD.org> To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-8@freebsd.org Subject: svn commit: r224034 - stable/8/usr.sbin/mtest Message-ID: <201107141905.p6EJ5mEl042027@svn.freebsd.org>
next in thread | raw e-mail | index | archive | help
Author: jhb Date: Thu Jul 14 19:05:48 2011 New Revision: 224034 URL: http://svn.freebsd.org/changeset/base/224034 Log: MFC 223510: Don't die if either of INET or INET6 aren't in the running kernel. Instead, report "protocol not supported" errors at runtime if a user attempts to use a protocol that the kernel doesn't support. Modified: stable/8/usr.sbin/mtest/mtest.c Directory Properties: stable/8/usr.sbin/mtest/ (props changed) Modified: stable/8/usr.sbin/mtest/mtest.c ============================================================================== --- stable/8/usr.sbin/mtest/mtest.c Thu Jul 14 18:58:18 2011 (r224033) +++ stable/8/usr.sbin/mtest/mtest.c Thu Jul 14 19:05:48 2011 (r224034) @@ -204,14 +204,16 @@ main(int argc, char **argv) s6 = -1; #ifdef INET s = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP); - if (s == -1) + if (s == -1 && errno != EPROTONOSUPPORT) err(1, "can't open IPv4 socket"); #endif #ifdef INET6 s6 = socket(AF_INET6, SOCK_DGRAM, IPPROTO_UDP); - if (s6 == -1) + if (s6 == -1 && errno != EPROTONOSUPPORT) err(1, "can't open IPv6 socket"); #endif + if (s == -1 && s6 == -1) + errc(1, EPROTONOSUPPORT, "can't open socket"); if (argc < 2) { if (isatty(STDIN_FILENO)) { @@ -371,7 +373,7 @@ af2socklen(const int af) } static void -process_cmd(char *cmd, int s, int s6 __unused, FILE *fp __unused) +process_cmd(char *cmd, int s, int s6, FILE *fp __unused) { char str1[STR_SIZE]; char str2[STR_SIZE]; @@ -457,7 +459,10 @@ process_cmd(char *cmd, int s, int s6 __u optval = (void *)&mr.mr; optlen = sizeof(mr.mr); } - if (setsockopt(s, level, optname, optval, + if (s < 0) { + warnc(EPROTONOSUPPORT, "setsockopt %s", + toptname); + } else if (setsockopt(s, level, optname, optval, optlen) == 0) { printf("ok\n"); break; @@ -496,7 +501,10 @@ process_cmd(char *cmd, int s, int s6 __u optval = (void *)&mr.mr6; optlen = sizeof(mr.mr6); } - if (setsockopt(s6, level, optname, optval, + if (s6 < 0) { + warnc(EPROTONOSUPPORT, "setsockopt %s", + toptname); + } else if (setsockopt(s6, level, optname, optval, optlen) == 0) { printf("ok\n"); break; @@ -534,6 +542,10 @@ process_cmd(char *cmd, int s, int s6 __u break; } af = su.sa.sa_family; + if (af2sock(af, s, s6) == -1) { + warnc(EPROTONOSUPPORT, "setsourcefilter"); + break; + } memset(&hints, 0, sizeof(struct addrinfo)); hints.ai_flags = AI_NUMERICHOST; @@ -593,6 +605,10 @@ process_cmd(char *cmd, int s, int s6 __u break; } af = su.sa.sa_family; + if (af2sock(af, s, s6) == -1) { + warnc(EPROTONOSUPPORT, "getsourcefilter"); + break; + } /* First determine our current filter mode. */ n = 0; @@ -700,6 +716,10 @@ process_cmd(char *cmd, int s, int s6 __u } af = su.sa.sa_family; + if (af2sock(af, s, s6) == -1) { + warnc(EPROTONOSUPPORT, "getsourcefilter"); + break; + } nsrc = nreqsrc; if (getsourcefilter(af2sock(af, s, s6), ifindex, &su.sa, su.sa.sa_len, &fmode, &nsrc, &sources[0].ss) != 0) {
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201107141905.p6EJ5mEl042027>