mirror of
https://github.com/cuberite/libevent.git
synced 2025-09-18 16:54:42 -04:00
Fix getaddrinfo under solaris (for multiprotocol case)
During testing on solaris 11.3, util/getaddrinfo failed at: memset(&hints, 0, sizeof(hints)); hints.ai_flags = EVUTIL_AI_NUMERICHOST; r = evutil_getaddrinfo("1.2.3.4", NULL, &hints, &ai); tt_assert(ai_find_by_protocol(ai, IPPROTO_TCP)); And this is because solaris's getaddrinfo() returns: $6 = { ai_flags = 32, ai_family = 2, ai_socktype = 0, ai_protocol = 0, <-- no proto ai_addrlen = 16, ai_canonname = 0x0, ai_addr = 0x815d658, ai_next = 0x0 <-- nothing else } So we should emulate this too. Plus introduce helper that will search through all results, not only first one. Fixes: util/getaddrinfo Fixes: #354
This commit is contained in:
parent
dc95823cd7
commit
40730ae333
16
evutil.c
16
evutil.c
@ -1238,11 +1238,20 @@ static int tested_for_getaddrinfo_hacks=0;
|
|||||||
field set to 0. We test for this so we can apply an appropriate
|
field set to 0. We test for this so we can apply an appropriate
|
||||||
workaround.
|
workaround.
|
||||||
*/
|
*/
|
||||||
|
struct evutil_addrinfo *ai_find_protocol(struct evutil_addrinfo *ai)
|
||||||
|
{
|
||||||
|
while (ai) {
|
||||||
|
if (ai->ai_protocol)
|
||||||
|
return ai;
|
||||||
|
ai = ai->ai_next;
|
||||||
|
}
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
static void
|
static void
|
||||||
test_for_getaddrinfo_hacks(void)
|
test_for_getaddrinfo_hacks(void)
|
||||||
{
|
{
|
||||||
int r, r2;
|
int r, r2;
|
||||||
struct evutil_addrinfo *ai=NULL, *ai2=NULL;
|
struct evutil_addrinfo *ai=NULL, *ai2=NULL, *ai3=NULL;
|
||||||
struct evutil_addrinfo hints;
|
struct evutil_addrinfo hints;
|
||||||
|
|
||||||
memset(&hints,0,sizeof(hints));
|
memset(&hints,0,sizeof(hints));
|
||||||
@ -1256,12 +1265,13 @@ test_for_getaddrinfo_hacks(void)
|
|||||||
#endif
|
#endif
|
||||||
0;
|
0;
|
||||||
r = getaddrinfo("1.2.3.4", "80", &hints, &ai);
|
r = getaddrinfo("1.2.3.4", "80", &hints, &ai);
|
||||||
|
getaddrinfo("1.2.3.4", NULL, &hints, &ai3);
|
||||||
hints.ai_socktype = SOCK_STREAM;
|
hints.ai_socktype = SOCK_STREAM;
|
||||||
r2 = getaddrinfo("1.2.3.4", "80", &hints, &ai2);
|
r2 = getaddrinfo("1.2.3.4", "80", &hints, &ai2);
|
||||||
if (r2 == 0 && r != 0) {
|
if (r2 == 0 && r != 0) {
|
||||||
need_numeric_port_hack_=1;
|
need_numeric_port_hack_=1;
|
||||||
}
|
}
|
||||||
if (ai2 && ai2->ai_protocol == 0) {
|
if (!ai_find_protocol(ai2) || !ai_find_protocol(ai3)) {
|
||||||
need_socktype_protocol_hack_=1;
|
need_socktype_protocol_hack_=1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1269,6 +1279,8 @@ test_for_getaddrinfo_hacks(void)
|
|||||||
freeaddrinfo(ai);
|
freeaddrinfo(ai);
|
||||||
if (ai2)
|
if (ai2)
|
||||||
freeaddrinfo(ai2);
|
freeaddrinfo(ai2);
|
||||||
|
if (ai3)
|
||||||
|
freeaddrinfo(ai3);
|
||||||
tested_for_getaddrinfo_hacks=1;
|
tested_for_getaddrinfo_hacks=1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user