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 <bruce__at__cran.org.uk> (partly)
MFC after:	2 week
This commit is contained in:
ume 2009-03-25 16:23:43 +00:00
parent 6cd843f315
commit b9602dae34

View File

@ -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;