From b9602dae34d92edee464230618658e3b11a8af61 Mon Sep 17 00:00:00 2001 From: ume Date: Wed, 25 Mar 2009 16:23:43 +0000 Subject: [PATCH] Add support for SCTP to getaddrinfo(3). Now, getaddrinfo(3) returns two SOCK_STREAMs, IPPROTO_TCP and IPPROTO_SCTP. It confuses some programs. If getaddrinfo(3) returns IPPROTO_SCTP when SOCK_STREAM is specified by hints.ai_socktype, at least Apache doesn't work. So, I made getaddrinfo(3) to return IPPROTO_SCTP with SOCK_STREAM only when IPPROTO_SCTP is specified explicitly by hints.ai_protocol. PR: bin/128167 Submitted by: Bruce Cran (partly) MFC after: 2 week --- lib/libc/net/getaddrinfo.c | 27 ++++++++++++++++++++------- 1 file changed, 20 insertions(+), 7 deletions(-) diff --git a/lib/libc/net/getaddrinfo.c b/lib/libc/net/getaddrinfo.c index 21ba70e370ad..121b8612ac27 100644 --- a/lib/libc/net/getaddrinfo.c +++ b/lib/libc/net/getaddrinfo.c @@ -165,18 +165,24 @@ struct explore { static const struct explore explore[] = { #if 0 - { PF_LOCAL, 0, ANY, ANY, NULL, 0x01 }, + { PF_LOCAL, ANY, ANY, NULL, 0x01 }, #endif #ifdef INET6 { PF_INET6, SOCK_DGRAM, IPPROTO_UDP, "udp", 0x07 }, { PF_INET6, SOCK_STREAM, IPPROTO_TCP, "tcp", 0x07 }, + { PF_INET6, SOCK_STREAM, IPPROTO_SCTP, "sctp", 0x03 }, + { PF_INET6, SOCK_SEQPACKET, IPPROTO_SCTP, "sctp", 0x07 }, { PF_INET6, SOCK_RAW, ANY, NULL, 0x05 }, #endif { PF_INET, SOCK_DGRAM, IPPROTO_UDP, "udp", 0x07 }, { PF_INET, SOCK_STREAM, IPPROTO_TCP, "tcp", 0x07 }, + { PF_INET, SOCK_STREAM, IPPROTO_SCTP, "sctp", 0x03 }, + { PF_INET, SOCK_SEQPACKET, IPPROTO_SCTP, "sctp", 0x07 }, { PF_INET, SOCK_RAW, ANY, NULL, 0x05 }, { PF_UNSPEC, SOCK_DGRAM, IPPROTO_UDP, "udp", 0x07 }, { PF_UNSPEC, SOCK_STREAM, IPPROTO_TCP, "tcp", 0x07 }, + { PF_UNSPEC, SOCK_STREAM, IPPROTO_SCTP, "sctp", 0x03 }, + { PF_UNSPEC, SOCK_SEQPACKET, IPPROTO_SCTP, "sctp", 0x07 }, { PF_UNSPEC, SOCK_RAW, ANY, NULL, 0x05 }, { -1, 0, 0, NULL, 0 }, }; @@ -417,10 +423,12 @@ getaddrinfo(const char *hostname, const char *servname, if (ex->e_protocol == ANY) continue; if (pai->ai_socktype == ex->e_socktype && - pai->ai_protocol != ex->e_protocol) { - ERR(EAI_BADHINTS); - } + pai->ai_protocol == ex->e_protocol) + break; } + + if (ex->e_af < 0) + ERR(EAI_BADHINTS); } } @@ -1344,6 +1352,7 @@ get_port(struct addrinfo *ai, const char *servname, int matchonly) return EAI_SERVICE; case SOCK_DGRAM: case SOCK_STREAM: + case SOCK_SEQPACKET: allownumeric = 1; break; case ANY: @@ -1373,13 +1382,17 @@ get_port(struct addrinfo *ai, const char *servname, int matchonly) } else { if (ai->ai_flags & AI_NUMERICSERV) return EAI_NONAME; - switch (ai->ai_socktype) { - case SOCK_DGRAM: + + switch (ai->ai_protocol) { + case IPPROTO_UDP: proto = "udp"; break; - case SOCK_STREAM: + case IPPROTO_TCP: proto = "tcp"; break; + case IPPROTO_SCTP: + proto = "sctp"; + break; default: proto = NULL; break;