mirror of git://sourceware.org/git/glibc.git
(gaih_inet): Avoid some code duplication.
This commit is contained in:
parent
9d88758aab
commit
29546dd9b4
|
|
@ -393,6 +393,7 @@ gaih_inet (const char *name, const struct gaih_service *service,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int port = 0;
|
||||||
if (service != NULL)
|
if (service != NULL)
|
||||||
{
|
{
|
||||||
if ((tp->protoflag & GAI_PROTO_NOSERVICE) != 0)
|
if ((tp->protoflag & GAI_PROTO_NOSERVICE) != 0)
|
||||||
|
|
@ -445,63 +446,41 @@ gaih_inet (const char *name, const struct gaih_service *service,
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (req->ai_socktype || req->ai_protocol)
|
port = htons (service->num);
|
||||||
{
|
goto got_port;
|
||||||
st = __alloca (sizeof (struct gaih_servtuple));
|
|
||||||
st->next = NULL;
|
|
||||||
st->socktype = tp->socktype;
|
|
||||||
st->protocol = ((tp->protoflag & GAI_PROTO_PROTOANY)
|
|
||||||
? req->ai_protocol : tp->protocol);
|
|
||||||
st->port = htons (service->num);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
/* Neither socket type nor protocol is set. Return all
|
|
||||||
socket types we know about. */
|
|
||||||
struct gaih_servtuple **lastp = &st;
|
|
||||||
for (tp = gaih_inet_typeproto + 1; tp->name[0]; ++tp)
|
|
||||||
if ((tp->protoflag & GAI_PROTO_NOSERVICE) == 0)
|
|
||||||
{
|
|
||||||
struct gaih_servtuple *newp;
|
|
||||||
|
|
||||||
newp = __alloca (sizeof (struct gaih_servtuple));
|
|
||||||
newp->next = NULL;
|
|
||||||
newp->socktype = tp->socktype;
|
|
||||||
newp->protocol = tp->protocol;
|
|
||||||
newp->port = htons (service->num);
|
|
||||||
|
|
||||||
*lastp = newp;
|
|
||||||
lastp = &newp->next;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (req->ai_socktype || req->ai_protocol)
|
|
||||||
{
|
|
||||||
st = __alloca (sizeof (struct gaih_servtuple));
|
|
||||||
st->next = NULL;
|
|
||||||
st->socktype = tp->socktype;
|
|
||||||
st->protocol = ((tp->protoflag & GAI_PROTO_PROTOANY)
|
|
||||||
? req->ai_protocol : tp->protocol);
|
|
||||||
st->port = 0;
|
|
||||||
}
|
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
/* Neither socket type nor protocol is set. Return all socket types
|
got_port:
|
||||||
we know about. */
|
|
||||||
struct gaih_servtuple **lastp = &st;
|
if (req->ai_socktype || req->ai_protocol)
|
||||||
for (++tp; tp->name[0]; ++tp)
|
|
||||||
{
|
{
|
||||||
struct gaih_servtuple *newp;
|
st = __alloca (sizeof (struct gaih_servtuple));
|
||||||
|
st->next = NULL;
|
||||||
|
st->socktype = tp->socktype;
|
||||||
|
st->protocol = ((tp->protoflag & GAI_PROTO_PROTOANY)
|
||||||
|
? req->ai_protocol : tp->protocol);
|
||||||
|
st->port = port;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
/* Neither socket type nor protocol is set. Return all socket types
|
||||||
|
we know about. */
|
||||||
|
struct gaih_servtuple **lastp = &st;
|
||||||
|
for (++tp; tp->name[0]; ++tp)
|
||||||
|
{
|
||||||
|
struct gaih_servtuple *newp;
|
||||||
|
|
||||||
newp = __alloca (sizeof (struct gaih_servtuple));
|
newp = __alloca (sizeof (struct gaih_servtuple));
|
||||||
newp->next = NULL;
|
newp->next = NULL;
|
||||||
newp->socktype = tp->socktype;
|
newp->socktype = tp->socktype;
|
||||||
newp->protocol = tp->protocol;
|
newp->protocol = tp->protocol;
|
||||||
newp->port = 0;
|
newp->port = port;
|
||||||
|
|
||||||
*lastp = newp;
|
*lastp = newp;
|
||||||
lastp = &newp->next;
|
lastp = &newp->next;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue