On 2014-01-12, Riccardo Mottola <[email protected]> wrote:
> Hi,
>
> I am having essentially the same problem as here:
> http://openbsd.7691.n7.nabble.com/res-init-and-0-0-0-0-td234246.html
>
> Specifically it is GNUMail and Pantomime which do not resolve correctly.
>
> I reduced myself to almost the same test program:
> main()
> {
> int i;
>
> if (res_init() == -1)
> return;
>
> if ((_res.options & RES_INIT) == 0)
> return;
>
> printf("Successfully inited, we have %d servers\n", _res.nscount);
>
> for (i = 0; i < _res.nscount; i++)
> {
> printf("%d-th server is in int: %d\n", i,
> _res.nsaddr_list[i].sin_addr.s_addr);
> }
> }
>
>
> I get this output:
> Successfully inited, we have 1 servers
> 0-th server is in int: 0
>
> Thus... I get something empty back.
>
> As the thread suggests, I installed libbind and linked against it.
> gcc restest.o -lbind -Wl,-L/usr/local/lib/libbind
> -Wl,-R/usr/local/lib/libbind
>
>
> ldd confirms linking was successful:
> Start End Type Open Ref GrpRef Name
> 1c000000 3c004000 exe 1 0 0 a.out
> 0b4c8000 2b4d0000 rlib 0 1 0
> /usr/local/lib/libbind/libbind.so.3.0
> 06881000 268b1000 rlib 0 1 0 /usr/lib/libc.so.69.0
> 051b6000 051b6000 rtld 0 1 0 /usr/libexec/ld.so
>
> However, I still get an empty server back.
>
>
> Further suggestions?
>
> Riccardo
>
>
You must use libbind's headers, too: -I/usr/local/include/libbind
It would probably make sense to apply the diff suggested in that thread
though, as it fixes this case and I don't see a downside (it isn't enough
for some programs which grovel deeper in struct _res, e.g. mtr, but it
seems it fixes enough common cases to be useful).
Here's a complete diff including tedu's suggestion.
Eric, what do you think?
Index: asr/res_init.c
===================================================================
RCS file: /cvs/src/lib/libc/asr/res_init.c,v
retrieving revision 1.2
diff -u -p -r1.2 res_init.c
--- asr/res_init.c 27 May 2013 17:31:01 -0000 1.2
+++ asr/res_init.c 13 Jan 2014 09:18:57 -0000
@@ -37,6 +37,7 @@ res_init(void)
{
_THREAD_PRIVATE_MUTEX(init);
struct asr_ctx *ac;
+ int i;
ac = asr_use_resolver(NULL);
@@ -55,6 +56,10 @@ res_init(void)
strlcpy(_res.lookups, ac->ac_db, sizeof(_res.lookups));
_res.nscount = ac->ac_nscount;
+ for (i = 0; i < ac->ac_nscount; i++) {
+ memcpy(&_res.nsaddr_list[i], ac->ac_ns[i],
+ ac->ac_ns[i]->sa_len);
+ }
_res.options |= RES_INIT;
}
_THREAD_PRIVATE_MUTEX_UNLOCK(init);