Skip to content

Commit 26a18d8

Browse files
committed
Simplify Address#getInfo() native implementation
Don't apply tricks and rely on OS behavior to resolve addresses. It is the caller's responsibility to properly process socket addresses if more than one exists. This mimics the behavior of HTTPd's listen.c for apr_sockaddr_info_get().
1 parent 73c347b commit 26a18d8

File tree

2 files changed

+6
-41
lines changed

2 files changed

+6
-41
lines changed

native/src/address.c

Lines changed: 1 addition & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -23,59 +23,19 @@ TCN_IMPLEMENT_CALL(jlong, Address, info)(TCN_STDARGS,
2323
{
2424
apr_pool_t *p = J2P(pool, apr_pool_t *);
2525
TCN_ALLOC_CSTRING(hostname);
26-
char *sp = NULL;
27-
int scope_id = 0;
2826
apr_sockaddr_t *sa = NULL;
29-
apr_sockaddr_t *sl = NULL;
3027
apr_int32_t f;
3128

3229

3330
UNREFERENCED(o);
3431
GET_S_FAMILY(f, family);
35-
#if APR_HAVE_IPV6
36-
if (hostname) {
37-
/* XXX: This only works for real scope_id's
38-
*/
39-
if ((sp = strchr(J2S(hostname), '%'))) {
40-
*sp++ = '\0';
41-
scope_id = atoi(sp);
42-
}
43-
}
44-
#endif
4532
TCN_THROW_IF_ERR(apr_sockaddr_info_get(&sa,
4633
J2S(hostname), f, (apr_port_t)port,
4734
(apr_int32_t)flags, p), sa);
48-
sl = sa;
49-
/*
50-
* apr_sockaddr_info_get may return several address so this is not
51-
* go to work in some cases (but as least it works for Linux)
52-
* XXX: with AP_ENABLE_V4_MAPPED it is going to work otherwise it won't.
53-
*/
54-
#if APR_HAVE_IPV6
55-
if (hostname == NULL) {
56-
/* Try all address using IPV6 one */
57-
while (sl) {
58-
if (sl->family == APR_INET6)
59-
break; /* Done */
60-
sl = sl->next;
61-
}
62-
/* If we don't find an IPv6 address, use the original one */
63-
if (sl == NULL) {
64-
sl = sa;
65-
}
66-
}
67-
if (sp) {
68-
/* Set the provided scope id
69-
* APR lack the api for setting this directly so lets presume
70-
* the sin6_scope_id is present everywhere
71-
*/
72-
sl->sa.sin6.sin6_scope_id = scope_id;
73-
}
74-
#endif
7535

7636
cleanup:
7737
TCN_FREE_CSTRING(hostname);
78-
return P2J(sl);
38+
return P2J(sa);
7939
}
8040

8141
TCN_IMPLEMENT_CALL(jstring, Address, getnameinfo)(TCN_STDARGS,

xdocs/miscellaneous/changelog.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,11 @@
3535
</p>
3636
</section>
3737
<section name="Changes in 1.2.29">
38+
<changelog>
39+
<update>
40+
Simplify <code>Address.getInfo()<code> native implementation. (michaelo)
41+
</update>
42+
</changelog>
3843
</section>
3944
<section name="Changes in 1.2.28">
4045
<changelog>

0 commit comments

Comments
 (0)