[Patch] gethostbyname2 again
Pierre A. Humblet
pierre@phumblet.no-ip.org
Tue Mar 3 01:37:00 GMT 2009
Corinna,
OK, here we go again.
This version calls res_query and all the work is done in net.cc.
As discussed before that means a lot of work is wasted when using the
Windows resolver.
That will be improved later.
There is no progress on the issue of resolving local names (NetBIOS
over TCP) for now,
so it's not a perfect replacement for the native gethostbyname yet.
Misc nits and notes:
- Including resolv.h in net.cc causes havoc because it pulls in
cygwin/in.h which conflicts
with winsock2.h. I worked around that by
defining _CYGWIN_IN_H before including resolv.h
- Because of the above, asm/byteorder.h doesn't get pulled in either,
and I couldn't use
some ntoh macros (see memcpy4to6).
- I could have included asm/byteorder separately but that causes
conflicts with the local ntoh
definitions in net.cc.
- Because arpa/nameser.h is now pulled in, IN6ADDRSZ etc are now
defined, but in a way different
from done in the snippet of code cut & pasted from bind. I didn't
want to change that piece (in
case you want to keep in intact for some reason) and I ended up
undefining IN6ADDRSZ etc .
- There is a new helper function dn_length1 which logically belongs
in minires.c, although it shouldn't
be exported by the dll. However if I place it in minires.c, then
the linker doesn't find it.
Fixing that probably involves some Makefile magic.
- I structured the code with a helper function gethostby_helper. That
will make it very easy to support
a gethostbyaddress some day, if needed.
- The helper function avoids using dup_ent (there is enough copying
already). I created a new
realloc_ent function, and call it from both dup_ent and the
helper. That caused minor
changes in the 4 versions of dup_ent, and I don't know exactly
what format to use in the ChangeLog
- This is much more complex than the first way of doing things. Needs testing!
- The patch is long, see the attachment. There is also a test program attached.
Pierre
2009-03-02 Pierre Humblet <Pierre.Humblet@ieee.org>
* net.cc: define _CYGWIN_IN_H and include resolv.h.
(realloc_ent): New function.
(dup_ent): Remove dst argument and call realloc_ent.
(memcpy4to6): New function.
(dn_length1): New function.
(gethostby_helper): New function.
(gethostbyname2): New function.
* cygwin.din: Export gethostbyname2.
* libc/minires.c (get_options): Look for "inet6" and apply bounds
to "retry" and "retrans".
(res_ninit): Set the default options at the beginning.
(dn_expand): Fix "off by one".
-------------- next part --------------
A non-text attachment was scrubbed...
Name: gethostbyname2_b.diff
Type: application/octet-stream
Size: 16763 bytes
Desc: not available
URL: <http://cygwin.com/pipermail/cygwin-patches/attachments/20090303/ad5f7f84/attachment.obj>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: try_gethostbyname.c
Type: application/octet-stream
Size: 1088 bytes
Desc: not available
URL: <http://cygwin.com/pipermail/cygwin-patches/attachments/20090303/ad5f7f84/attachment-0001.obj>
More information about the Cygwin-patches
mailing list