/* * (C) 2001 Uwe Ohse, . * Placed in the public domain. */ #include "stralloc.h" #include "scan.h" #include "ip6.h" #include "ip4.h" #include "socket.h" #include "error.h" #include "host_connect.h" #include "timeoutconn.h" #include "str.h" #include "dns.h" #include "byte.h" #include "bailout.h" #include "close.h" #include "socket_if.h" #define ER(ec,en,s1,s2,s3,s4) \ do { \ if (x) xbailout(ec,en,s1,s2,s3,s4); \ else warning(en,s1,s2,s3,s4); \ return -1; \ } while(0) #define OOM() ER(111,0,"out of memory",0,0,0) /* * this is much more complicated than i'd like it, mainly due to the * fact that ipv4-in-v6 mapped addresses don't work under KAME / *BSD. * I fail to see a reason this this. */ static int doit(const char *host, unsigned int defaultport, unsigned long timeout, stralloc *remoteaddresses, int x) { unsigned int l; char ip6[16]; char ip4[4]; unsigned long port; stralloc addresses=STRALLOC_INIT; static int ipv6_error=0; static int ipv6_supported=-1; uint32 scope=0; if (-1==ipv6_supported) { if (socket_flag_noipv6) ipv6_supported=0; } if (-1==ipv6_supported) { int sock; sock=socket_tcp6(); if (-1==sock) { ipv6_supported=0; ipv6_error=errno; } else { ipv6_supported=1; close(sock); } } l=ip6_scan(host,ip6); if (l) { if (host[l]=='%') { l++; scope=socket_getifidx(host+l); if (!scope) ER(100,errno, "cannot find interface ",host+l,0,0); l+=str_len(host+l); } if (!stralloc_copyb(&addresses,ip6,16)) OOM(); } else { l=ip4_scan(host,ip4); if (l) { if (!stralloc_copyb(&addresses,V4mappedprefix,12)) OOM(); if (!stralloc_catb(&addresses,ip4,4)) OOM(); } else { stralloc fqdn=STRALLOC_INIT; stralloc tmp=STRALLOC_INIT; unsigned int m; m=str_chr(host,'%'); l=str_chr(host,':'); if (m