diff --git a/CHANGES b/CHANGES index 7ddfcbe..df5107e 100644 --- a/CHANGES +++ b/CHANGES @@ -104,6 +104,9 @@ Features: of the resolver. For Socat addresses requiring IPv6 addresses, this resolves IPv4 addresses to the approriate IPv6 address [::ffff:*:*]. + DNS resolver Options (res-*) are now set for the complete open phase of + the address, not per getaddrinfo() invocation. + Corrections: When a sub process (EXEC, SYSTEM) terminated with exit code other than 0, its last sent data might have been lost depending on timing of read/ diff --git a/doc/socat.yo b/doc/socat.yo index cae5c97..808e161 100644 --- a/doc/socat.yo +++ b/doc/socat.yo @@ -2270,7 +2270,7 @@ label(OPTION_RES_DNSRCH)dit(bf(tt(res-dnsrch))) option flags. Append "=0" to clear a default option. See man NOEXPAND(resolver(5)) for more information on these options. These flags are per process, however socat() restores the old values after name resolution. - Please note that these flags only affects DNS resolution, but not hosts or + Please note that these flags only affect DNS resolution, but not hosts or NIS based name resolution, and they have no effect when (g)libc retrieves the results from code(nscd). enddit() diff --git a/test.sh b/test.sh index f459065..ecd1b22 100755 --- a/test.sh +++ b/test.sh @@ -10827,13 +10827,17 @@ rc1=$? kill $pid0 2>/dev/null; wait if echo "$da" |diff - ${tf}1 >"$tdiff"; then $PRINTF "$OK\n" + if [ "$VERBOSE" ]; then echo "$CMD0 &"; fi + if [ "$DEBUG" ]; then cat "${te}0" >&2; fi + if [ "$VERBOSE" ]; then echo "$CMD1"; fi + if [ "$DEBUG" ]; then cat "${te}1" >&2; fi numOK=$((numOK+1)) else $PRINTF "$FAILED\n" echo "$CMD0 &" - echo "$CMD1" cat "${te}0" -# cat "${te}1" + echo "$CMD1" + cat "${te}1" cat "$tdiff" numFAIL=$((numFAIL+1)) listFAIL="$listFAIL $N" @@ -10888,13 +10892,17 @@ rc1=$? kill $pid0 2>/dev/null; wait if echo "$da" |diff - ${tf}1 >"$tdiff"; then $PRINTF "$OK\n" + if [ "$VERBOSE" ]; then echo "$CMD0 &"; fi + if [ "$DEBUG" ]; then cat "${te}0" >&2; fi + if [ "$VERBOSE" ]; then echo "$CMD1"; fi + if [ "$DEBUG" ]; then cat "${te}1" >&2; fi numOK=$((numOK+1)) else $PRINTF "$FAILED\n" echo "$CMD0 &" - echo "$CMD1" cat "${te}0" -# cat "${te}1" + echo "$CMD1" + cat "${te}1" cat "$tdiff" numFAIL=$((numFAIL+1)) listFAIL="$listFAIL $N" diff --git a/xio-fd.c b/xio-fd.c index a37af61..6f50629 100644 --- a/xio-fd.c +++ b/xio-fd.c @@ -74,11 +74,11 @@ const struct optdesc opt_flock_ex_nb = { "flock-ex-nb", "flock-nb", OPT_FLOCK_E const struct optdesc opt_cool_write = { "cool-write", "coolwrite", OPT_COOL_WRITE, GROUP_FD, PH_INIT, TYPE_BOOL, OFUNC_OFFSET, XIO_OFFSETOF(cool_write) }; /* control closing of connections */ -const struct optdesc opt_end_close = { "end-close", "close", OPT_END_CLOSE, GROUP_FD, PH_INIT, TYPE_CONST, OFUNC_OFFSET, XIO_OFFSETOF(howtoend), END_CLOSE }; -const struct optdesc opt_shut_none = { "shut-none", NULL, OPT_SHUT_NONE, GROUP_FD, PH_INIT, TYPE_CONST, OFUNC_OFFSET, XIO_OFFSETOF(howtoshut), XIOSHUT_NONE }; -const struct optdesc opt_shut_down = { "shut-down", NULL, OPT_SHUT_DOWN, GROUP_FD, PH_INIT, TYPE_CONST, OFUNC_OFFSET, XIO_OFFSETOF(howtoshut), XIOSHUT_DOWN }; -const struct optdesc opt_shut_close= { "shut-close", NULL, OPT_SHUT_CLOSE, GROUP_FD, PH_INIT, TYPE_CONST, OFUNC_OFFSET, XIO_OFFSETOF(howtoshut), XIOSHUT_CLOSE }; -const struct optdesc opt_shut_null = { "shut-null", NULL, OPT_SHUT_NULL, GROUP_FD, PH_INIT, TYPE_CONST, OFUNC_OFFSET, XIO_OFFSETOF(howtoshut), XIOSHUT_NULL }; +const struct optdesc opt_end_close = { "end-close", "close", OPT_END_CLOSE, GROUP_FD, PH_OFFSET, TYPE_CONST, OFUNC_OFFSET, XIO_OFFSETOF(howtoend), END_CLOSE }; +const struct optdesc opt_shut_none = { "shut-none", NULL, OPT_SHUT_NONE, GROUP_FD, PH_OFFSET, TYPE_CONST, OFUNC_OFFSET, XIO_OFFSETOF(howtoshut), XIOSHUT_NONE }; +const struct optdesc opt_shut_down = { "shut-down", NULL, OPT_SHUT_DOWN, GROUP_FD, PH_OFFSET, TYPE_CONST, OFUNC_OFFSET, XIO_OFFSETOF(howtoshut), XIOSHUT_DOWN }; +const struct optdesc opt_shut_close= { "shut-close", NULL, OPT_SHUT_CLOSE, GROUP_FD, PH_OFFSET, TYPE_CONST, OFUNC_OFFSET, XIO_OFFSETOF(howtoshut), XIOSHUT_CLOSE }; +const struct optdesc opt_shut_null = { "shut-null", NULL, OPT_SHUT_NULL, GROUP_FD, PH_OFFSET, TYPE_CONST, OFUNC_OFFSET, XIO_OFFSETOF(howtoshut), XIOSHUT_NULL }; /****** generic ioctl() options ******/ const struct optdesc opt_ioctl_void = { "ioctl-void", "ioctl", OPT_IOCTL_VOID, GROUP_FD, PH_FD, TYPE_INT, OFUNC_IOCTL_GENERIC, 0, 0, 0 }; diff --git a/xio-interface.c b/xio-interface.c index d9d2e1c..ba03f52 100644 --- a/xio-interface.c +++ b/xio-interface.c @@ -22,30 +22,30 @@ int xioopen_interface(int argc, const char *argv[], struct opt *opts, /*0 const struct optdesc opt_interface_addr = { "interface-addr", "address", OPT_INTERFACE_ADDR, GROUP_INTERFACE, PH_FD, TYPE_STRING, OFUNC_SPEC };*/ /*0 const struct optdesc opt_interface_netmask = { "interface-netmask", "netmask", OPT_INTERFACE_NETMASK, GROUP_INTERFACE, PH_FD, TYPE_STRING, OFUNC_SPEC };*/ -const struct optdesc opt_iff_up = { "iff-up", "up", OPT_IFF_UP, GROUP_INTERFACE, PH_INIT, TYPE_BOOL, OFUNC_OFFSET_MASKS, XIO_OFFSETOF(para.interface.iff_opts), XIO_SIZEOF(para.interface.iff_opts), IFF_UP }; -const struct optdesc opt_iff_broadcast = { "iff-broadcast", NULL, OPT_IFF_BROADCAST, GROUP_INTERFACE, PH_FD, TYPE_BOOL, OFUNC_OFFSET_MASKS, XIO_OFFSETOF(para.interface.iff_opts), XIO_SIZEOF(para.interface.iff_opts), IFF_BROADCAST }; -const struct optdesc opt_iff_debug = { "iff-debug" , NULL, OPT_IFF_DEBUG, GROUP_INTERFACE, PH_FD, TYPE_BOOL, OFUNC_OFFSET_MASKS, XIO_OFFSETOF(para.interface.iff_opts), XIO_SIZEOF(para.interface.iff_opts), IFF_DEBUG }; -const struct optdesc opt_iff_loopback = { "iff-loopback" , "loopback", OPT_IFF_LOOPBACK, GROUP_INTERFACE, PH_FD, TYPE_BOOL, OFUNC_OFFSET_MASKS, XIO_OFFSETOF(para.interface.iff_opts), XIO_SIZEOF(para.interface.iff_opts), IFF_LOOPBACK }; -const struct optdesc opt_iff_pointopoint = { "iff-pointopoint", "pointopoint",OPT_IFF_POINTOPOINT, GROUP_INTERFACE, PH_FD, TYPE_BOOL, OFUNC_OFFSET_MASKS, XIO_OFFSETOF(para.interface.iff_opts), XIO_SIZEOF(para.interface.iff_opts), IFF_POINTOPOINT }; -const struct optdesc opt_iff_notrailers = { "iff-notrailers", "notrailers", OPT_IFF_NOTRAILERS, GROUP_INTERFACE, PH_FD, TYPE_BOOL, OFUNC_OFFSET_MASKS, XIO_OFFSETOF(para.interface.iff_opts), XIO_SIZEOF(para.interface.iff_opts), IFF_NOTRAILERS }; -const struct optdesc opt_iff_running = { "iff-running", "running", OPT_IFF_RUNNING, GROUP_INTERFACE, PH_FD, TYPE_BOOL, OFUNC_OFFSET_MASKS, XIO_OFFSETOF(para.interface.iff_opts), XIO_SIZEOF(para.interface.iff_opts), IFF_RUNNING }; -const struct optdesc opt_iff_noarp = { "iff-noarp", "noarp", OPT_IFF_NOARP, GROUP_INTERFACE, PH_FD, TYPE_BOOL, OFUNC_OFFSET_MASKS, XIO_OFFSETOF(para.interface.iff_opts), XIO_SIZEOF(para.interface.iff_opts), IFF_NOARP }; -const struct optdesc opt_iff_promisc = { "iff-promisc", "promisc", OPT_IFF_PROMISC, GROUP_INTERFACE, PH_FD, TYPE_BOOL, OFUNC_OFFSET_MASKS, XIO_OFFSETOF(para.interface.iff_opts), XIO_SIZEOF(para.interface.iff_opts), IFF_PROMISC }; -const struct optdesc opt_iff_allmulti = { "iff-allmulti", "allmulti", OPT_IFF_ALLMULTI, GROUP_INTERFACE, PH_FD, TYPE_BOOL, OFUNC_OFFSET_MASKS, XIO_OFFSETOF(para.interface.iff_opts), XIO_SIZEOF(para.interface.iff_opts), IFF_ALLMULTI }; +const struct optdesc opt_iff_up = { "iff-up", "up", OPT_IFF_UP, GROUP_INTERFACE, PH_OFFSET, TYPE_BOOL, OFUNC_OFFSET_MASKS, XIO_OFFSETOF(para.interface.iff_opts), XIO_SIZEOF(para.interface.iff_opts), IFF_UP }; +const struct optdesc opt_iff_broadcast = { "iff-broadcast", NULL, OPT_IFF_BROADCAST, GROUP_INTERFACE, PH_OFFSET, TYPE_BOOL, OFUNC_OFFSET_MASKS, XIO_OFFSETOF(para.interface.iff_opts), XIO_SIZEOF(para.interface.iff_opts), IFF_BROADCAST }; +const struct optdesc opt_iff_debug = { "iff-debug" , NULL, OPT_IFF_DEBUG, GROUP_INTERFACE, PH_OFFSET, TYPE_BOOL, OFUNC_OFFSET_MASKS, XIO_OFFSETOF(para.interface.iff_opts), XIO_SIZEOF(para.interface.iff_opts), IFF_DEBUG }; +const struct optdesc opt_iff_loopback = { "iff-loopback" , "loopback", OPT_IFF_LOOPBACK, GROUP_INTERFACE, PH_OFFSET, TYPE_BOOL, OFUNC_OFFSET_MASKS, XIO_OFFSETOF(para.interface.iff_opts), XIO_SIZEOF(para.interface.iff_opts), IFF_LOOPBACK }; +const struct optdesc opt_iff_pointopoint = { "iff-pointopoint", "pointopoint",OPT_IFF_POINTOPOINT, GROUP_INTERFACE, PH_OFFSET, TYPE_BOOL, OFUNC_OFFSET_MASKS, XIO_OFFSETOF(para.interface.iff_opts), XIO_SIZEOF(para.interface.iff_opts), IFF_POINTOPOINT }; +const struct optdesc opt_iff_notrailers = { "iff-notrailers", "notrailers", OPT_IFF_NOTRAILERS, GROUP_INTERFACE, PH_OFFSET, TYPE_BOOL, OFUNC_OFFSET_MASKS, XIO_OFFSETOF(para.interface.iff_opts), XIO_SIZEOF(para.interface.iff_opts), IFF_NOTRAILERS }; +const struct optdesc opt_iff_running = { "iff-running", "running", OPT_IFF_RUNNING, GROUP_INTERFACE, PH_OFFSET, TYPE_BOOL, OFUNC_OFFSET_MASKS, XIO_OFFSETOF(para.interface.iff_opts), XIO_SIZEOF(para.interface.iff_opts), IFF_RUNNING }; +const struct optdesc opt_iff_noarp = { "iff-noarp", "noarp", OPT_IFF_NOARP, GROUP_INTERFACE, PH_OFFSET, TYPE_BOOL, OFUNC_OFFSET_MASKS, XIO_OFFSETOF(para.interface.iff_opts), XIO_SIZEOF(para.interface.iff_opts), IFF_NOARP }; +const struct optdesc opt_iff_promisc = { "iff-promisc", "promisc", OPT_IFF_PROMISC, GROUP_INTERFACE, PH_OFFSET, TYPE_BOOL, OFUNC_OFFSET_MASKS, XIO_OFFSETOF(para.interface.iff_opts), XIO_SIZEOF(para.interface.iff_opts), IFF_PROMISC }; +const struct optdesc opt_iff_allmulti = { "iff-allmulti", "allmulti", OPT_IFF_ALLMULTI, GROUP_INTERFACE, PH_OFFSET, TYPE_BOOL, OFUNC_OFFSET_MASKS, XIO_OFFSETOF(para.interface.iff_opts), XIO_SIZEOF(para.interface.iff_opts), IFF_ALLMULTI }; #ifdef IFF_MASTER -const struct optdesc opt_iff_master = { "iff-master", "master", OPT_IFF_MASTER, GROUP_INTERFACE, PH_FD, TYPE_BOOL, OFUNC_OFFSET_MASKS, XIO_OFFSETOF(para.interface.iff_opts), XIO_SIZEOF(para.interface.iff_opts), IFF_MASTER }; +const struct optdesc opt_iff_master = { "iff-master", "master", OPT_IFF_MASTER, GROUP_INTERFACE, PH_OFFSET, TYPE_BOOL, OFUNC_OFFSET_MASKS, XIO_OFFSETOF(para.interface.iff_opts), XIO_SIZEOF(para.interface.iff_opts), IFF_MASTER }; #endif #ifdef IFF_SLAVE -const struct optdesc opt_iff_slave = { "iff-slave", "slave", OPT_IFF_SLAVE, GROUP_INTERFACE, PH_FD, TYPE_BOOL, OFUNC_OFFSET_MASKS, XIO_OFFSETOF(para.interface.iff_opts), XIO_SIZEOF(para.interface.iff_opts), IFF_SLAVE }; +const struct optdesc opt_iff_slave = { "iff-slave", "slave", OPT_IFF_SLAVE, GROUP_INTERFACE, PH_OFFSET, TYPE_BOOL, OFUNC_OFFSET_MASKS, XIO_OFFSETOF(para.interface.iff_opts), XIO_SIZEOF(para.interface.iff_opts), IFF_SLAVE }; #endif -const struct optdesc opt_iff_multicast = { "iff-multicast", NULL, OPT_IFF_MULTICAST, GROUP_INTERFACE, PH_FD, TYPE_BOOL, OFUNC_OFFSET_MASKS, XIO_OFFSETOF(para.interface.iff_opts), XIO_SIZEOF(para.interface.iff_opts), IFF_MULTICAST }; +const struct optdesc opt_iff_multicast = { "iff-multicast", NULL, OPT_IFF_MULTICAST, GROUP_INTERFACE, PH_OFFSET, TYPE_BOOL, OFUNC_OFFSET_MASKS, XIO_OFFSETOF(para.interface.iff_opts), XIO_SIZEOF(para.interface.iff_opts), IFF_MULTICAST }; #ifdef IFF_PORTSEL -const struct optdesc opt_iff_portsel = { "iff-portsel", "portsel", OPT_IFF_PORTSEL, GROUP_INTERFACE, PH_FD, TYPE_BOOL, OFUNC_OFFSET_MASKS, XIO_OFFSETOF(para.interface.iff_opts), XIO_SIZEOF(para.interface.iff_opts), IFF_PORTSEL }; +const struct optdesc opt_iff_portsel = { "iff-portsel", "portsel", OPT_IFF_PORTSEL, GROUP_INTERFACE, PH_OFFSET, TYPE_BOOL, OFUNC_OFFSET_MASKS, XIO_OFFSETOF(para.interface.iff_opts), XIO_SIZEOF(para.interface.iff_opts), IFF_PORTSEL }; #endif #ifdef IFF_AUTOMEDIA -const struct optdesc opt_iff_automedia = { "iff-automedia", "automedia", OPT_IFF_AUTOMEDIA, GROUP_INTERFACE, PH_FD, TYPE_BOOL, OFUNC_OFFSET_MASKS, XIO_OFFSETOF(para.interface.iff_opts), XIO_SIZEOF(para.interface.iff_opts), IFF_AUTOMEDIA }; +const struct optdesc opt_iff_automedia = { "iff-automedia", "automedia", OPT_IFF_AUTOMEDIA, GROUP_INTERFACE, PH_OFFSET, TYPE_BOOL, OFUNC_OFFSET_MASKS, XIO_OFFSETOF(para.interface.iff_opts), XIO_SIZEOF(para.interface.iff_opts), IFF_AUTOMEDIA }; #endif -/*const struct optdesc opt_iff_dynamic = { "iff-dynamic", "dynamic", OPT_IFF_DYNAMIC, GROUP_INTERFACE, PH_FD, TYPE_BOOL, OFUNC_OFFSET_MASKS, XIO_OFFSETOF(para.interface.iff_opts), XIO_SIZEOF(short), IFF_DYNAMIC };*/ +/*const struct optdesc opt_iff_dynamic = { "iff-dynamic", "dynamic", OPT_IFF_DYNAMIC, GROUP_INTERFACE, PH_OFFSET, TYPE_BOOL, OFUNC_OFFSET_MASKS, XIO_OFFSETOF(para.interface.iff_opts), XIO_SIZEOF(short), IFF_DYNAMIC };*/ #ifdef PACKET_AUXDATA const struct optdesc opt_retrieve_vlan = { "retrieve-vlan", NULL, OPT_RETRIEVE_VLAN, GROUP_INTERFACE, PH_LATE, TYPE_INT, OFUNC_SPEC }; #endif diff --git a/xio-ip.c b/xio-ip.c index b42ee56..471b658 100644 --- a/xio-ip.c +++ b/xio-ip.c @@ -82,11 +82,13 @@ const struct optdesc opt_ip_recvif = { "ip-recvif", "recvdstaddrif",OPT_IP_RECVI #endif #ifdef AI_ADDRCONFIG -const struct optdesc opt_ai_addrconfig = { "ai-addrconfig", "addrconfig", OPT_AI_ADDRCONFIG, GROUP_SOCK_IP, PH_INIT, TYPE_BOOL, OFUNC_OFFSET_MASKS, XIO_OFFSETOF(para.socket.ip.ai_flags), XIO_SIZEOF(para.socket.ip.ai_flags), AI_ADDRCONFIG }; -const struct optdesc opt_ai_v4mapped = { "ai-v4mapped", "v4mapped", OPT_AI_V4MAPPED, GROUP_SOCK_IP, PH_INIT, TYPE_BOOL, OFUNC_OFFSET_MASKS, XIO_OFFSETOF(para.socket.ip.ai_flags), XIO_SIZEOF(para.socket.ip.ai_flags), AI_V4MAPPED }; +const struct optdesc opt_ai_addrconfig = { "ai-addrconfig", "addrconfig", OPT_AI_ADDRCONFIG, GROUP_SOCK_IP, PH_OFFSET, TYPE_BOOL, OFUNC_OFFSET_MASKS, XIO_OFFSETOF(para.socket.ip.ai_flags), XIO_SIZEOF(para.socket.ip.ai_flags), AI_ADDRCONFIG }; +#endif +#ifdef AI_V4MAPPED +const struct optdesc opt_ai_v4mapped = { "ai-v4mapped", "v4mapped", OPT_AI_V4MAPPED, GROUP_SOCK_IP, PH_OFFSET, TYPE_BOOL, OFUNC_OFFSET_MASKS, XIO_OFFSETOF(para.socket.ip.ai_flags), XIO_SIZEOF(para.socket.ip.ai_flags), AI_V4MAPPED }; #endif #ifdef AI_PASSIVE -const struct optdesc opt_ai_passive = { "ai-passive", "passive", OPT_AI_PASSIVE, GROUP_SOCK_IP, PH_INIT, TYPE_BOOL, OFUNC_OFFSET_MASKS, XIO_OFFSETOF(para.socket.ip.ai_flags), XIO_SIZEOF(para.socket.ip.ai_flags), AI_PASSIVE }; +const struct optdesc opt_ai_passive = { "ai-passive", "passive", OPT_AI_PASSIVE, GROUP_SOCK_IP, PH_OFFSET, TYPE_BOOL, OFUNC_OFFSET_MASKS, XIO_OFFSETOF(para.socket.ip.ai_flags), XIO_SIZEOF(para.socket.ip.ai_flags), AI_PASSIVE }; #endif #if WITH_RES_DEPRECATED @@ -94,19 +96,19 @@ const struct optdesc opt_ai_passive = { "ai-passive", "passive", OPT_AI # define WITH_RES_PRIMARY 1 #endif /* WITH_RES_DEPRECATED */ #if HAVE_RESOLV_H -const struct optdesc opt_res_debug = { "res-debug", NULL, OPT_RES_DEBUG, GROUP_SOCK_IP, PH_INIT, TYPE_BOOL, OFUNC_OFFSET_MASKS, XIO_OFFSETOF(para.socket.ip.res_opts), XIO_SIZEOF(para.socket.ip.res_opts), RES_DEBUG }; +const struct optdesc opt_res_debug = { "res-debug", NULL, OPT_RES_DEBUG, GROUP_SOCK_IP, PH_OFFSET, TYPE_BOOL, OFUNC_OFFSET_MASKS, XIO_OFFSETOF(para.socket.ip.res_opts), XIO_SIZEOF(para.socket.ip.res_opts), RES_DEBUG }; #if WITH_RES_AAONLY -const struct optdesc opt_res_aaonly = { "res-aaonly", "aaonly", OPT_RES_AAONLY, GROUP_SOCK_IP, PH_INIT, TYPE_BOOL, OFUNC_OFFSET_MASKS, XIO_OFFSETOF(para.socket.ip.res_opts), XIO_SIZEOF(para.socket.ip.res_opts), RES_AAONLY }; +const struct optdesc opt_res_aaonly = { "res-aaonly", "aaonly", OPT_RES_AAONLY, GROUP_SOCK_IP, PH_OFFSET, TYPE_BOOL, OFUNC_OFFSET_MASKS, XIO_OFFSETOF(para.socket.ip.res_opts), XIO_SIZEOF(para.socket.ip.res_opts), RES_AAONLY }; #endif -const struct optdesc opt_res_usevc = { "res-usevc", "usevc", OPT_RES_USEVC, GROUP_SOCK_IP, PH_INIT, TYPE_BOOL, OFUNC_OFFSET_MASKS, XIO_OFFSETOF(para.socket.ip.res_opts), XIO_SIZEOF(para.socket.ip.res_opts), RES_USEVC }; +const struct optdesc opt_res_usevc = { "res-usevc", "usevc", OPT_RES_USEVC, GROUP_SOCK_IP, PH_OFFSET, TYPE_BOOL, OFUNC_OFFSET_MASKS, XIO_OFFSETOF(para.socket.ip.res_opts), XIO_SIZEOF(para.socket.ip.res_opts), RES_USEVC }; #if WITH_RES_PRIMARY -const struct optdesc opt_res_primary = { "res-primary", "primary", OPT_RES_PRIMARY, GROUP_SOCK_IP, PH_INIT, TYPE_BOOL, OFUNC_OFFSET_MASKS, XIO_OFFSETOF(para.socket.ip.res_opts), XIO_SIZEOF(para.socket.ip.res_opts), RES_PRIMARY }; +const struct optdesc opt_res_primary = { "res-primary", "primary", OPT_RES_PRIMARY, GROUP_SOCK_IP, PH_OFFSET, TYPE_BOOL, OFUNC_OFFSET_MASKS, XIO_OFFSETOF(para.socket.ip.res_opts), XIO_SIZEOF(para.socket.ip.res_opts), RES_PRIMARY }; #endif -const struct optdesc opt_res_igntc = { "res-igntc", "igntc", OPT_RES_IGNTC, GROUP_SOCK_IP, PH_INIT, TYPE_BOOL, OFUNC_OFFSET_MASKS, XIO_OFFSETOF(para.socket.ip.res_opts), XIO_SIZEOF(para.socket.ip.res_opts), RES_IGNTC }; -const struct optdesc opt_res_recurse = { "res-recurse", "recurse", OPT_RES_RECURSE, GROUP_SOCK_IP, PH_INIT, TYPE_BOOL, OFUNC_OFFSET_MASKS, XIO_OFFSETOF(para.socket.ip.res_opts), XIO_SIZEOF(para.socket.ip.res_opts), RES_RECURSE }; -const struct optdesc opt_res_defnames = { "res-defnames", "defnames", OPT_RES_DEFNAMES, GROUP_SOCK_IP, PH_INIT, TYPE_BOOL, OFUNC_OFFSET_MASKS, XIO_OFFSETOF(para.socket.ip.res_opts), XIO_SIZEOF(para.socket.ip.res_opts), RES_DEFNAMES }; -const struct optdesc opt_res_stayopen = { "res-stayopen", "stayopen", OPT_RES_STAYOPEN, GROUP_SOCK_IP, PH_INIT, TYPE_BOOL, OFUNC_OFFSET_MASKS, XIO_OFFSETOF(para.socket.ip.res_opts), XIO_SIZEOF(para.socket.ip.res_opts), RES_STAYOPEN }; -const struct optdesc opt_res_dnsrch = { "res-dnsrch", "dnsrch", OPT_RES_DNSRCH, GROUP_SOCK_IP, PH_INIT, TYPE_BOOL, OFUNC_OFFSET_MASKS, XIO_OFFSETOF(para.socket.ip.res_opts), XIO_SIZEOF(para.socket.ip.res_opts), RES_DNSRCH }; +const struct optdesc opt_res_igntc = { "res-igntc", "igntc", OPT_RES_IGNTC, GROUP_SOCK_IP, PH_OFFSET, TYPE_BOOL, OFUNC_OFFSET_MASKS, XIO_OFFSETOF(para.socket.ip.res_opts), XIO_SIZEOF(para.socket.ip.res_opts), RES_IGNTC }; +const struct optdesc opt_res_recurse = { "res-recurse", "recurse", OPT_RES_RECURSE, GROUP_SOCK_IP, PH_OFFSET, TYPE_BOOL, OFUNC_OFFSET_MASKS, XIO_OFFSETOF(para.socket.ip.res_opts), XIO_SIZEOF(para.socket.ip.res_opts), RES_RECURSE }; +const struct optdesc opt_res_defnames = { "res-defnames", "defnames", OPT_RES_DEFNAMES, GROUP_SOCK_IP, PH_OFFSET, TYPE_BOOL, OFUNC_OFFSET_MASKS, XIO_OFFSETOF(para.socket.ip.res_opts), XIO_SIZEOF(para.socket.ip.res_opts), RES_DEFNAMES }; +const struct optdesc opt_res_stayopen = { "res-stayopen", "stayopen", OPT_RES_STAYOPEN, GROUP_SOCK_IP, PH_OFFSET, TYPE_BOOL, OFUNC_OFFSET_MASKS, XIO_OFFSETOF(para.socket.ip.res_opts), XIO_SIZEOF(para.socket.ip.res_opts), RES_STAYOPEN }; +const struct optdesc opt_res_dnsrch = { "res-dnsrch", "dnsrch", OPT_RES_DNSRCH, GROUP_SOCK_IP, PH_OFFSET, TYPE_BOOL, OFUNC_OFFSET_MASKS, XIO_OFFSETOF(para.socket.ip.res_opts), XIO_SIZEOF(para.socket.ip.res_opts), RES_DNSRCH }; #endif /* HAVE_RESOLV_H */ #endif /* WITH_IP4 || WITH_IP6 */ @@ -161,11 +163,9 @@ unsigned long res_opts() { */ int xiogetaddrinfo(const char *node, const char *service, int family, int socktype, int protocol, - struct addrinfo **res, const int ai_flags[2], - const unsigned long res_opts[2]) { + struct addrinfo **res, const int ai_flags[2]) { char *numnode = NULL; size_t nodelen; - unsigned long save_res_opts = 0; #if HAVE_GETADDRINFO struct addrinfo hints = {0}; #else /* HAVE_PROTOTYPE_LIB_getipnodebyname || nothing */ @@ -173,19 +173,6 @@ int xiogetaddrinfo(const char *node, const char *service, #endif int error_num; -#if HAVE_RESOLV_H - if (res_opts[0] | res_opts[1]) { - if (!(_res.options & RES_INIT)) { - Res_init(); /*!!! returns -1 on error */ - } - save_res_opts = _res.options; - _res.options |= res_opts[0]; - _res.options &= ~res_opts[1]; - Debug2("changed _res.options from 0x%lx to 0x%lx", - save_res_opts, _res.options); - } -#endif /* HAVE_RESOLV_H */ - if (service && service[0]=='\0') { Error("empty port/service"); } @@ -209,14 +196,9 @@ int xiogetaddrinfo(const char *node, const char *service, ; #if WITH_IP6 } else if (node && node[0] == '[' && node[(nodelen=strlen(node))-1]==']') { - if ((numnode = Malloc(nodelen-1)) == NULL) { -#if HAVE_RESOLV_H - if (res_opts[0] | res_opts[1]) { - _res.options = save_res_opts; - } -#endif + if ((numnode = Malloc(nodelen-1)) == NULL) return STAT_NORETRY; - } + strncpy(numnode, node+1, nodelen-2); /* ok */ numnode[nodelen-2] = '\0'; node = numnode; @@ -273,13 +255,8 @@ int xiogetaddrinfo(const char *node, const char *service, hints.ai_socktype, hints.ai_protocol, (error_num == EAI_SYSTEM)? strerror(errno):gai_strerror(error_num)); - if (numnode) free(numnode); - -#if HAVE_RESOLV_H - if (res_opts[0] | res_opts[1]) { - _res.options = save_res_opts; - } -#endif + if (numnode) + free(numnode); return STAT_RETRYLATER; } } while (1); @@ -373,11 +350,6 @@ int xiogetaddrinfo(const char *node, const char *service, Error2("gethostbyname(\"%s\"): %s", node, h_errno == NETDB_INTERNAL ? strerror(errno) : hstrerror(h_errno)); -#if HAVE_RESOLV_H - if (res_opts[0] | res_opts[1]) { - _res.options = save_res_opts; - } -#endif return STAT_RETRYLATER; } if (host->h_addrtype != family) { @@ -407,11 +379,6 @@ int xiogetaddrinfo(const char *node, const char *service, if (numnode) free(numnode); -#if HAVE_RESOLV_H - if (res_opts[0] | res_opts[1]) { - _res.options = save_res_opts; - } -#endif /* HAVE_RESOLV_H */ return STAT_OK; } @@ -431,14 +398,14 @@ void xiofreeaddrinfo(struct addrinfo *res) { int xioresolve(const char *node, const char *service, int family, int socktype, int protocol, union sockaddr_union *addr, socklen_t *addrlen, - const int ai_flags[2], const unsigned long res_opts[2]) + const int ai_flags[2]) { struct addrinfo *res = NULL; struct addrinfo *aip; int rc; rc = xiogetaddrinfo(node, service, family, socktype, protocol, - &res, ai_flags, res_opts); + &res, ai_flags); if (rc != 0) { xiofreeaddrinfo(res); return -1; @@ -789,7 +756,7 @@ mc:addr xioresolve(opt->value.u_string/*multiaddr*/, NULL, xfd->para.socket.la.soa.sa_family, SOCK_DGRAM, IPPROTO_IP, &sockaddr1, &socklen1, - xfd->para.socket.ip.ai_flags, xfd->para.socket.ip.res_opts); + xfd->para.socket.ip.ai_flags); ip4_mreqn.mreq.imr_multiaddr = sockaddr1.ip4.sin_addr; if (0) { ; /* for canonical reasons */ @@ -800,8 +767,7 @@ mc:addr xioresolve(opt->value2.u_string/*param2*/, NULL, xfd->para.socket.la.soa.sa_family, SOCK_DGRAM, IPPROTO_IP, &sockaddr2, &socklen2, - xfd->para.socket.ip.ai_flags, - xfd->para.socket.ip.res_opts); + xfd->para.socket.ip.ai_flags); ip4_mreqn.mreq.imr_interface = sockaddr2.ip4.sin_addr; /* third parameter is interface */ if (ifindex(opt->value3.u_string/*ifindex*/, @@ -830,8 +796,7 @@ mc:addr xfd->para.socket.la.soa.sa_family, SOCK_DGRAM, IPPROTO_IP, &sockaddr2, &socklen2, - xfd->para.socket.ip.ai_flags, - xfd->para.socket.ip.res_opts); + xfd->para.socket.ip.ai_flags); ip4_mreqn.mreq.imr_interface = sockaddr2.ip4.sin_addr; } } @@ -982,8 +947,7 @@ int xioapply_ip_add_source_membership(struct single *xfd, struct opt *opt) { rc = xioresolve(opt->value.u_string/*mcaddr*/, NULL, xfd->para.socket.la.soa.sa_family, SOCK_DGRAM, IPPROTO_IP, - &sockaddr1, &socklen1, xfd->para.socket.ip.ai_flags, - xfd->para.socket.ip.res_opts); + &sockaddr1, &socklen1, xfd->para.socket.ip.ai_flags); if (rc < 0) { return -1; } @@ -992,8 +956,7 @@ int xioapply_ip_add_source_membership(struct single *xfd, struct opt *opt) { rc = xioresolve(opt->value.u_string/*ifaddr*/, NULL, xfd->para.socket.la.soa.sa_family, SOCK_DGRAM, IPPROTO_IP, - &sockaddr2, &socklen2, xfd->para.socket.ip.ai_flags, - xfd->para.socket.ip.res_opts); + &sockaddr2, &socklen2, xfd->para.socket.ip.ai_flags); if (rc < 0) { return -1; } @@ -1002,8 +965,7 @@ int xioapply_ip_add_source_membership(struct single *xfd, struct opt *opt) { rc = xioresolve(opt->value.u_string/*srcaddr*/, NULL, xfd->para.socket.la.soa.sa_family, SOCK_DGRAM, IPPROTO_IP, - &sockaddr3, &socklen3, xfd->para.socket.ip.ai_flags, - xfd->para.socket.ip.res_opts); + &sockaddr3, &socklen3, xfd->para.socket.ip.ai_flags); if (rc < 0) { return -1; } @@ -1022,6 +984,47 @@ int xioapply_ip_add_source_membership(struct single *xfd, struct opt *opt) { } return 0; } + #endif /* HAVE_STRUCT_IP_MREQ_SOURCE */ + +#if HAVE_RESOLV_H + +/* When there are options for resolver then this function saves the current + resolver settings to save_res and applies the options to resolver libs state + in _res. + Returns 1 when there were options (state needs to be restored later, see + xio_res_restore()); + Returns 0 when there were no options; + Returns -1 on error. */ +int xio_res_init( + struct single *sfd, + struct __res_state *save_res) +{ + if (sfd->para.socket.ip.res_opts[0] || + sfd->para.socket.ip.res_opts[1]) { + if (!(_res.options & RES_INIT)) { + if (Res_init() < 0) { + Error("res_init() failed"); + return -1; + } + } + *save_res = _res; + _res.options |= sfd->para.socket.ip.res_opts[0]; + _res.options &= ~sfd->para.socket.ip.res_opts[1]; + Debug2("changed _res.options from 0x%lx to 0x%lx", + save_res->options, _res.options); + return 1; + } + return 0; +} + +int xio_res_restore( + struct __res_state *save_res) +{ + _res = *save_res; + return 0; +} +#endif /* HAVE_RESOLV_H */ + #endif /* _WITH_IP4 || _WITH_IP6 */ diff --git a/xio-ip.h b/xio-ip.h index 9695ba9..037f36f 100644 --- a/xio-ip.h +++ b/xio-ip.h @@ -45,13 +45,18 @@ extern const struct optdesc opt_res_dnsrch; extern int xioinit_ip(int *pf, char ipv); -extern int xiogetaddrinfo(const char *node, const char *service, int family, int socktype, int protocol, struct addrinfo **res, const int ai_flags[2], const unsigned long res_opts[2]); +extern int xiogetaddrinfo(const char *node, const char *service, int family, int socktype, int protocol, struct addrinfo **res, const int ai_flags[2]); extern void xiofreeaddrinfo(struct addrinfo *res); -extern int xioresolve(const char *node, const char *service, int family, int socktype, int protocol, union sockaddr_union *addr, socklen_t *addrlen, const int ai_flags[2], const unsigned long res_opts[2]); +extern int xioresolve(const char *node, const char *service, int family, int socktype, int protocol, union sockaddr_union *addr, socklen_t *addrlen, const int ai_flags[2]); extern int xiolog_ancillary_ip(struct single *sfd, struct cmsghdr *cmsg, int *num, char *typbuff, int typlen, char *nambuff, int namlen, char *envbuff, int envlen, char *valbuff, int vallen); extern int xiotype_ip_add_membership(char *token, const struct optname *ent, struct opt *opt); extern int xioapply_ip_add_membership(xiosingle_t *xfd, struct opt *opt); extern int xiotype_ip_add_source_membership(char* token, const struct optname *ent, struct opt *opt); extern int xioapply_ip_add_source_membership(struct single *xfd, struct opt *opt); +#if HAVE_RESOLV_H +extern int xio_res_init(struct single *sfd, struct __res_state *save_res); +extern int xio_res_restore(struct __res_state *save_red); +#endif /* HAVE_RESOLV_H */ + #endif /* !defined(__xio_ip_h_included) */ diff --git a/xio-ip4.c b/xio-ip4.c index d4efbbe..cdd218b 100644 --- a/xio-ip4.c +++ b/xio-ip4.c @@ -17,8 +17,7 @@ int xioparsenetwork_ip4( const char *rangename, struct xiorange *range, - const int ai_flags[2], - const unsigned long res_opts[2]) + const int ai_flags[2]) { struct in_addr *netaddr_in = &range->netaddr.ip4.sin_addr; struct in_addr *netmask_in = &range->netmask.ip4.sin_addr; @@ -51,7 +50,7 @@ int xioparsenetwork_ip4( } } else if (delimpos = strchr(rangename1, ':')) { if ((rc = xioresolve(delimpos+1, NULL, PF_INET, 0, 0, - &sau, &socklen, ai_flags, res_opts)) + &sau, &socklen, ai_flags)) != STAT_OK) { return rc; } @@ -64,7 +63,7 @@ int xioparsenetwork_ip4( { *delimpos = 0; if ((rc = xioresolve(rangename1, NULL, PF_INET, 0, 0, - &sau, &socklen, ai_flags, res_opts)) + &sau, &socklen, ai_flags)) != STAT_OK) { return rc; } diff --git a/xio-ip4.h b/xio-ip4.h index 94d5e86..ed081cb 100644 --- a/xio-ip4.h +++ b/xio-ip4.h @@ -7,7 +7,7 @@ extern const struct optdesc opt_ip4_add_membership; -extern int xioparsenetwork_ip4(const char *rangename, struct xiorange *range, const int ai_flags[2], const unsigned long res_opts[2]); +extern int xioparsenetwork_ip4(const char *rangename, struct xiorange *range, const int ai_flags[2]); extern int xiocheckrange_ip4(struct sockaddr_in *pa, struct xiorange *range); extern int diff --git a/xio-ip6.c b/xio-ip6.c index b5e8073..e24d18f 100644 --- a/xio-ip6.c +++ b/xio-ip6.c @@ -85,8 +85,7 @@ const struct optdesc opt_ipv6_recvpathmtu = { "ipv6-recvpathmtu", "recvpathmtu", int xioip6_pton( const char *src, struct in6_addr *dst, - const int ai_flags[2], - const unsigned long res_opts[2]) + const int ai_flags[2]) { union sockaddr_union sockaddr; socklen_t sockaddrlen = sizeof(sockaddr); @@ -99,10 +98,10 @@ int xioip6_pton( plainaddr[INET6_ADDRSTRLEN-1] = '\0'; if ((clos = strchr(plainaddr, ']')) != NULL) *clos = '\0'; - return xioip6_pton(plainaddr, dst, ai_flags, res_opts); + return xioip6_pton(plainaddr, dst, ai_flags); } if (xioresolve(src, NULL, PF_INET6, 0, 0, &sockaddr, &sockaddrlen, - ai_flags, res_opts) + ai_flags) != STAT_OK) { return STAT_NORETRY; } @@ -113,8 +112,7 @@ int xioip6_pton( int xioparsenetwork_ip6( const char *rangename, struct xiorange *range, - const int ai_flags[2], - const unsigned long res_opts[2]) + const int ai_flags[2]) { char *delimpos; /* absolute address of delimiter */ size_t delimind; /* index of delimiter in string */ @@ -145,7 +143,7 @@ int xioparsenetwork_ip6( } baseaddr[delimind-2] = '\0'; if (xioresolve(baseaddr, NULL, PF_INET6, 0, 0, &sockaddr, &sockaddrlen, - ai_flags, res_opts) + ai_flags) != STAT_OK) { return STAT_NORETRY; } @@ -493,8 +491,7 @@ int xioapply_ipv6_join_group( xfd->para.socket.la.soa.sa_family, SOCK_DGRAM, IPPROTO_IP, &sockaddr1, &socklen1, - xfd->para.socket.ip.ai_flags, - xfd->para.socket.ip.res_opts)) + xfd->para.socket.ip.ai_flags)) != STAT_OK) { return res; } @@ -634,7 +631,7 @@ int xioapply_ip6_join_source_group(struct single *xfd, struct opt *opt) { xioresolve(opt->value.u_string/*mcaddr*/, NULL, xfd->para.socket.la.soa.sa_family, SOCK_DGRAM, IPPROTO_IP, &sockaddr1, &socklen1, - xfd->para.socket.ip.ai_flags, xfd->para.socket.ip.res_opts)) + xfd->para.socket.ip.ai_flags)) != STAT_OK) { return res; } @@ -652,7 +649,7 @@ int xioapply_ip6_join_source_group(struct single *xfd, struct opt *opt) { xioresolve(opt->value3.u_string/*srcaddr*/, NULL, xfd->para.socket.la.soa.sa_family, SOCK_DGRAM, IPPROTO_IP, &sockaddr2, &socklen2, - xfd->para.socket.ip.ai_flags, xfd->para.socket.ip.res_opts)) + xfd->para.socket.ip.ai_flags)) != STAT_OK) { return res; } diff --git a/xio-ip6.h b/xio-ip6.h index 22d9e9b..dea069a 100644 --- a/xio-ip6.h +++ b/xio-ip6.h @@ -32,8 +32,8 @@ extern const struct optdesc opt_ipv6_tclass; extern const struct optdesc opt_ipv6_recvtclass; extern const struct optdesc opt_ipv6_recvpathmtu; -extern int xioip6_pton(const char *src, struct in6_addr *dst, const int ai_flags[2], const unsigned long res_opts[2]); -extern int xioparsenetwork_ip6(const char *rangename, struct xiorange *range, const int ai_flags[2], const unsigned long res_opts[2]); +extern int xioip6_pton(const char *src, struct in6_addr *dst, const int ai_flags[2]); +extern int xioparsenetwork_ip6(const char *rangename, struct xiorange *range, const int ai_flags[2]); extern int xiorange_ip6andmask(struct xiorange *range); extern diff --git a/xio-ipapp.c b/xio-ipapp.c index ac71f2e..68693ed 100644 --- a/xio-ipapp.c +++ b/xio-ipapp.c @@ -53,7 +53,6 @@ int xioopen_ipapp_connect(int argc, const char *argv[], struct opt *opts, if (_xioopen_ipapp_prepare(opts, &opts0, hostname, portname, &pf, ipproto, xfd->para.socket.ip.ai_flags, - xfd->para.socket.ip.res_opts, &themlist, us, &uslen, &needbind, &lowport, socktype) != STAT_OK) { return STAT_NORETRY; @@ -195,7 +194,6 @@ int int *pf, int protocol, const int ai_flags[2], - const unsigned long res_opts[2], struct addrinfo **themlist, union sockaddr_union *us, socklen_t *uslen, @@ -211,7 +209,7 @@ int if ((result = xiogetaddrinfo(hostname, portname, *pf, socktype, protocol, - themlist, ai_flags, res_opts)) + themlist, ai_flags)) != STAT_OK) { return STAT_NORETRY; /*! STAT_RETRYLATER? */ } @@ -222,7 +220,7 @@ int /* 3 means: IP address AND port accepted */ if (retropt_bind(opts, (*pf!=PF_UNSPEC)?*pf:(*themlist)->ai_family, socktype, protocol, (struct sockaddr *)us, uslen, 3, - ai_flags, res_opts) + ai_flags) != STAT_NOACTION) { *needbind = true; } else { @@ -271,7 +269,6 @@ int _xioopen_ipapp_listen_prepare( int *pf, int ipproto, const int ai_flags[2], - const unsigned long res_opts[2], union sockaddr_union *us, socklen_t *uslen, int socktype) @@ -292,7 +289,7 @@ int _xioopen_ipapp_listen_prepare( result = xioresolve(bindname, portname, *pf, socktype, ipproto, - us, uslen, ai_flags2, res_opts); + us, uslen, ai_flags2); if (result != STAT_OK) { /*! STAT_RETRY? */ return result; @@ -340,7 +337,6 @@ int xioopen_ipapp_listen(int argc, const char *argv[], struct opt *opts, if (_xioopen_ipapp_listen_prepare(opts, &opts0, argv[1], &pf, ipproto, xfd->stream.para.socket.ip.ai_flags, - xfd->stream.para.socket.ip.res_opts, us, &uslen, socktype) != STAT_OK) { return STAT_NORETRY; diff --git a/xio-ipapp.h b/xio-ipapp.h index fa25c47..dbd89eb 100644 --- a/xio-ipapp.h +++ b/xio-ipapp.h @@ -17,7 +17,7 @@ extern const struct optdesc opt_lowport; extern int xioopen_ipapp_connect(int argc, const char *argv[], struct opt *opts, int xioflags, xiofile_t *fd, groups_t groups, int socktype, int ipproto, int protname); -extern int _xioopen_ipapp_prepare(struct opt *opts, struct opt **opts0, const char *hostname, const char *portname, int *pf, int protocol, const int ai_flags[2], const unsigned long res_opts[2], struct addrinfo **res, union sockaddr_union *us, socklen_t *uslen, bool *needbind, bool *lowport, +extern int _xioopen_ipapp_prepare(struct opt *opts, struct opt **opts0, const char *hostname, const char *portname, int *pf, int protocol, const int ai_flags[2], struct addrinfo **res, union sockaddr_union *us, socklen_t *uslen, bool *needbind, bool *lowport, int socktype); extern int _xioopen_ip4app_connect(const char *hostname, const char *portname, struct single *xfd, @@ -27,7 +27,7 @@ extern int xioopen_ipapp_listen(int argc, const char *argv[], struct opt *opts, int xioflags, xiofile_t *fd, groups_t groups, int socktype, int ipproto, int protname); -extern int _xioopen_ipapp_listen_prepare(struct opt *opts, struct opt **opts0, const char *portname, int *pf, int ipproto, const int ai_flags[2], const unsigned long res_opts[2], union sockaddr_union *us, socklen_t *uslen, int socktype); +extern int _xioopen_ipapp_listen_prepare(struct opt *opts, struct opt **opts0, const char *portname, int *pf, int ipproto, const int ai_flags[2], union sockaddr_union *us, socklen_t *uslen, int socktype); extern int _xio_sort_ip_addresses(struct addrinfo *themlist, struct addrinfo **ai_sorted); #endif /* !defined(__xio_ipapp_h_included) */ diff --git a/xio-listen.c b/xio-listen.c index 408b348..855d012 100644 --- a/xio-listen.c +++ b/xio-listen.c @@ -200,8 +200,7 @@ int _xioopen_listen(struct single *xfd, int xioflags, struct sockaddr *us, sockl #if WITH_IP4 /*|| WITH_IP6*/ if (retropt_string(opts, OPT_RANGE, &rangename) >= 0) { if (xioparserange(rangename, pf, &xfd->para.socket.range, - xfd->para.socket.ip.ai_flags, - xfd->para.socket.ip.res_opts) + xfd->para.socket.ip.ai_flags) < 0) { free(rangename); return STAT_NORETRY; diff --git a/xio-openssl.c b/xio-openssl.c index bcf8c2e..dcb4d63 100644 --- a/xio-openssl.c +++ b/xio-openssl.c @@ -114,10 +114,10 @@ const struct optdesc opt_openssl_cipherlist = { "openssl-cipherlist", "ciphers", const struct optdesc opt_openssl_method = { "openssl-method", "method", OPT_OPENSSL_METHOD, GROUP_OPENSSL, PH_SPEC, TYPE_STRING, OFUNC_SPEC }; #endif #if HAVE_SSL_CTX_set_min_proto_version || defined(SSL_CTX_set_min_proto_version) -const struct optdesc opt_openssl_min_proto_version = { "openssl-min-proto-version", "min-version", OPT_OPENSSL_MIN_PROTO_VERSION, GROUP_OPENSSL, PH_INIT, TYPE_STRING, OFUNC_OFFSET, XIO_OFFSETOF(para.openssl.min_proto_version) }; +const struct optdesc opt_openssl_min_proto_version = { "openssl-min-proto-version", "min-version", OPT_OPENSSL_MIN_PROTO_VERSION, GROUP_OPENSSL, PH_OFFSET, TYPE_STRING, OFUNC_OFFSET, XIO_OFFSETOF(para.openssl.min_proto_version) }; #endif #if HAVE_SSL_CTX_set_max_proto_version || defined(SSL_CTX_set_max_proto_version) -const struct optdesc opt_openssl_max_proto_version = { "openssl-max-proto-version", "max-version", OPT_OPENSSL_MAX_PROTO_VERSION, GROUP_OPENSSL, PH_INIT, TYPE_STRING, OFUNC_OFFSET, XIO_OFFSETOF(para.openssl.max_proto_version) }; +const struct optdesc opt_openssl_max_proto_version = { "openssl-max-proto-version", "max-version", OPT_OPENSSL_MAX_PROTO_VERSION, GROUP_OPENSSL, PH_OFFSET, TYPE_STRING, OFUNC_OFFSET, XIO_OFFSETOF(para.openssl.max_proto_version) }; #endif const struct optdesc opt_openssl_verify = { "openssl-verify", "verify", OPT_OPENSSL_VERIFY, GROUP_OPENSSL, PH_SPEC, TYPE_BOOL, OFUNC_SPEC }; const struct optdesc opt_openssl_certificate = { "openssl-certificate", "cert", OPT_OPENSSL_CERTIFICATE, GROUP_OPENSSL, PH_SPEC, TYPE_FILENAME, OFUNC_SPEC }; @@ -329,7 +329,6 @@ static int result = _xioopen_ipapp_prepare(opts, &opts0, hostname, portname, &pf, ipproto, xfd->para.socket.ip.ai_flags, - xfd->para.socket.ip.res_opts, &themlist, us, &uslen, &needbind, &lowport, socktype); if (result != STAT_OK) return STAT_NORETRY; @@ -629,7 +628,6 @@ static int if (_xioopen_ipapp_listen_prepare(opts, &opts0, portname, &pf, ipproto, xfd->para.socket.ip.ai_flags, - xfd->para.socket.ip.res_opts, us, &uslen, socktype) != STAT_OK) { return STAT_NORETRY; @@ -1912,8 +1910,7 @@ static int openssl_handle_peer_certificate(struct single *xfd, case 16: /* IPv6 */ inet_ntop(AF_INET6, data, aBuffer, sizeof(aBuffer)); if (peername != NULL) { - xioip6_pton(peername, &ip6bin, xfd->para.socket.ip.ai_flags, - xfd->para.socket.ip.res_opts); + xioip6_pton(peername, &ip6bin, xfd->para.socket.ip.ai_flags); if (memcmp(data, &ip6bin, sizeof(ip6bin)) == 0) { Debug2("subjectAltName \"%s\" matches peername \"%s\"", aBuffer, peername); diff --git a/xio-progcall.c b/xio-progcall.c index 42e407e..eef8be0 100644 --- a/xio-progcall.c +++ b/xio-progcall.c @@ -21,7 +21,7 @@ const struct optdesc opt_openpty = { "openpty", NULL, OPT_OPENPTY, GROUP_P #if HAVE_DEV_PTMX || HAVE_DEV_PTC const struct optdesc opt_ptmx = { "ptmx", NULL, OPT_PTMX, GROUP_PTY, PH_BIGEN, TYPE_BOOL, OFUNC_SPEC }; #endif -const struct optdesc opt_sitout_eio = { "sitout-eio", NULL, OPT_SITOUT_EIO, GROUP_PTY, PH_INIT, TYPE_TIMEVAL, OFUNC_OFFSET, XIO_OFFSETOF(para.exec.sitout_eio), XIO_SIZEOF(para.exec.sitout_eio) }; +const struct optdesc opt_sitout_eio = { "sitout-eio", NULL, OPT_SITOUT_EIO, GROUP_PTY, PH_OFFSET, TYPE_TIMEVAL, OFUNC_OFFSET, XIO_OFFSETOF(para.exec.sitout_eio), XIO_SIZEOF(para.exec.sitout_eio) }; #if WITH_EXEC || WITH_SYSTEM diff --git a/xio-proxy.c b/xio-proxy.c index b6b4c64..a14c70f 100644 --- a/xio-proxy.c +++ b/xio-proxy.c @@ -127,8 +127,7 @@ static int xioopen_proxy_connect(int argc, const char *argv[], struct opt *opts, } result = _xioopen_proxy_prepare(proxyvars, opts, targetname, targetport, - xfd->para.socket.ip.ai_flags, - xfd->para.socket.ip.res_opts); + xfd->para.socket.ip.ai_flags); if (result != STAT_OK) return result; @@ -144,7 +143,6 @@ static int xioopen_proxy_connect(int argc, const char *argv[], struct opt *opts, _xioopen_ipapp_prepare(opts, &opts0, proxyname, proxyport, &pf, ipproto, xfd->para.socket.ip.ai_flags, - xfd->para.socket.ip.res_opts, &themlist, us, &uslen, &needbind, &lowport, socktype); if (result != STAT_OK) @@ -273,8 +271,7 @@ int _xioopen_proxy_prepare( struct opt *opts, const char *targetname, const char *targetport, - const int ai_flags[2], - const unsigned long res_opts[2]) { + const int ai_flags[2]) { union sockaddr_union host; socklen_t socklen = sizeof(host); int rc; @@ -334,7 +331,7 @@ int _xioopen_proxy_prepare( represented in CONNECT commands this code might need to be extended */ rc = xioresolve(targetname, targetport, PF_INET/*!?*/, SOCK_STREAM, IPPROTO_TCP, - &host, &socklen, ai_flags, res_opts); + &host, &socklen, ai_flags); if (rc != STAT_OK) { proxyvars->targetaddr = strdup(targetname); } else { diff --git a/xio-proxy.h b/xio-proxy.h index c8a1d26..fee18b7 100644 --- a/xio-proxy.h +++ b/xio-proxy.h @@ -25,7 +25,7 @@ extern const struct optdesc opt_proxy_authorization_file; extern const struct addrdesc xioaddr_proxy_connect; -extern int _xioopen_proxy_prepare(struct proxyvars *proxyvars, struct opt *opts, const char *targetname, const char *targetport, const int ai_flags[2], const unsigned long res_opts[2]); +extern int _xioopen_proxy_prepare(struct proxyvars *proxyvars, struct opt *opts, const char *targetname, const char *targetport, const int ai_flags[2]); int _xioopen_proxy_connect(struct single *xfd, struct proxyvars *proxyvars, int level); diff --git a/xio-rawip.c b/xio-rawip.c index 2613bfa..9bad320 100644 --- a/xio-rawip.c +++ b/xio-rawip.c @@ -117,7 +117,6 @@ int _xioopen_rawip_sendto(const char *hostname, const char *protname, xfd->howtoend = END_SHUTDOWN; retropt_int(opts, OPT_PROTOCOL_FAMILY, pf); - /* ...res_opts[] */ if (applyopts_single(xfd, opts, PH_INIT) < 0) return -1; applyopts(-1, opts, PH_INIT); @@ -125,8 +124,7 @@ int _xioopen_rawip_sendto(const char *hostname, const char *protname, if ((result = xioresolve(hostname, NULL, *pf, socktype, ipproto, &xfd->peersa, &xfd->salen, - xfd->para.socket.ip.ai_flags, - xfd->para.socket.ip.res_opts)) + xfd->para.socket.ip.ai_flags)) != STAT_OK) { return result; } @@ -139,8 +137,7 @@ int _xioopen_rawip_sendto(const char *hostname, const char *protname, xfd->dtype = XIODATA_RECVFROM_SKIPIP; if (retropt_bind(opts, *pf, socktype, ipproto, &us.soa, &uslen, feats, - xfd->para.socket.ip.ai_flags, - xfd->para.socket.ip.res_opts) + xfd->para.socket.ip.ai_flags) != STAT_NOACTION) { needbind = true; } @@ -182,8 +179,7 @@ int xioopen_rawip_datagram(int argc, const char *argv[], struct opt *opts, /* which reply packets will be accepted - determine by range option */ if (retropt_string(opts, OPT_RANGE, &rangename) >= 0) { if (xioparserange(rangename, pf, &xfd->para.socket.range, - xfd->para.socket.ip.ai_flags, - xfd->para.socket.ip.res_opts) + xfd->para.socket.ip.ai_flags) < 0) { free(rangename); return STAT_NORETRY; @@ -248,8 +244,7 @@ int xioopen_rawip_recvfrom(int argc, const char *argv[], struct opt *opts, } if (retropt_bind(opts, pf, socktype, ipproto, &us.soa, &uslen, 1, - xfd->stream.para.socket.ip.ai_flags, - xfd->stream.para.socket.ip.res_opts) + xfd->stream.para.socket.ip.ai_flags) != STAT_NOACTION) { needbind = true; } @@ -308,8 +303,7 @@ int xioopen_rawip_recv(int argc, const char *argv[], struct opt *opts, if (retropt_bind(opts, pf, socktype, ipproto, &/*us.soa*/xfd->stream.para.socket.la.soa, &uslen, 1, - xfd->stream.para.socket.ip.ai_flags, - xfd->stream.para.socket.ip.res_opts) + xfd->stream.para.socket.ip.ai_flags) == STAT_OK) { needbind = true; } else { diff --git a/xio-socket.c b/xio-socket.c index 749ac0d..a90cc99 100644 --- a/xio-socket.c +++ b/xio-socket.c @@ -211,7 +211,7 @@ const struct optdesc opt_setsockopt_bin = { "setsockopt-bin", "sockopt-bin const struct optdesc opt_setsockopt_string = { "setsockopt-string", "sockopt-string", OPT_SETSOCKOPT_STRING, GROUP_SOCKET,PH_CONNECTED, TYPE_INT_INT_STRING, OFUNC_SOCKOPT_GENERIC, 0, 0 }; const struct optdesc opt_setsockopt_listen = { "setsockopt-listen", "sockopt-listen", OPT_SETSOCKOPT_LISTEN, GROUP_SOCKET,PH_PREBIND, TYPE_INT_INT_BIN, OFUNC_SOCKOPT_GENERIC, 0, 0 }; -const struct optdesc opt_null_eof = { "null-eof", NULL, OPT_NULL_EOF, GROUP_SOCKET, PH_INIT, TYPE_BOOL, OFUNC_OFFSET, XIO_OFFSETOF(para.socket.null_eof) }; +const struct optdesc opt_null_eof = { "null-eof", NULL, OPT_NULL_EOF, GROUP_SOCKET, PH_OFFSET, TYPE_BOOL, OFUNC_OFFSET, XIO_OFFSETOF(para.socket.null_eof) }; #if WITH_GENERICSOCKET @@ -277,7 +277,7 @@ int xioopen_socket_connect(int argc, const char *argv[], struct opt *opts, socket_init(0, &us); if (retropt_bind(opts, 0 /*pf*/, socktype, proto, (struct sockaddr *)&us, &uslen, 3, - xfd->para.socket.ip.ai_flags, xfd->para.socket.ip.res_opts) + xfd->para.socket.ip.ai_flags) != STAT_NOACTION) { needbind = true; us.soa.sa_family = pf; @@ -446,7 +446,6 @@ int _xioopen_socket_sendto(const char *pfname, const char *type, themsize; #endif - /* ...res_opts[] */ if (applyopts_single(xfd, opts, PH_INIT) < 0) return -1; applyopts(-1, opts, PH_INIT); @@ -541,8 +540,7 @@ int xioopen_socket_recvfrom(int argc, const char *argv[], struct opt *opts, if (retropt_string(opts, OPT_RANGE, &rangename) >= 0) { if (xioparserange(rangename, 0, &xfd->para.socket.range, - xfd->para.socket.ip.ai_flags, - xfd->para.socket.ip.res_opts) + xfd->para.socket.ip.ai_flags) < 0) { free(rangename); return STAT_NORETRY; @@ -623,8 +621,7 @@ int xioopen_socket_recv(int argc, const char *argv[], struct opt *opts, if (retropt_string(opts, OPT_RANGE, &rangename) >= 0) { if (xioparserange(rangename, 0, &xfd->para.socket.range, - xfd->para.socket.ip.ai_flags, - xfd->para.socket.ip.res_opts) + xfd->para.socket.ip.ai_flags) < 0) { free(rangename); return STAT_NORETRY; @@ -706,8 +703,7 @@ int xioopen_socket_datagram(int argc, const char *argv[], struct opt *opts, /* which reply sockets will accept - determine by range option */ if (retropt_string(opts, OPT_RANGE, &rangename) >= 0) { if (xioparserange(rangename, 0, &xfd->para.socket.range, - xfd->para.socket.ip.ai_flags, - xfd->para.socket.ip.res_opts) + xfd->para.socket.ip.ai_flags) < 0) { free(rangename); return STAT_NORETRY; @@ -1179,8 +1175,7 @@ int _xioopen_dgram_recvfrom(struct single *xfd, int xioflags, /* for generic sockets, this has already been retrieved */ if (retropt_string(opts, OPT_RANGE, &rangename) >= 0) { if (xioparserange(rangename, pf, &xfd->para.socket.range, - xfd->para.socket.ip.ai_flags, - xfd->para.socket.ip.res_opts) + xfd->para.socket.ip.ai_flags) < 0) { free(rangename); return STAT_NORETRY; @@ -1384,8 +1379,7 @@ int _xioopen_dgram_recv(struct single *xfd, int xioflags, #if WITH_IP4 /*|| WITH_IP6*/ if (retropt_string(opts, OPT_RANGE, &rangename) >= 0) { if (xioparserange(rangename, pf, &xfd->para.socket.range, - xfd->para.socket.ip.ai_flags, - xfd->para.socket.ip.res_opts) + xfd->para.socket.ip.ai_flags) < 0) { free(rangename); return STAT_NORETRY; @@ -1833,8 +1827,7 @@ int xioparsenetwork( const char *rangename, int pf, struct xiorange *range, - const int ai_flags[2], - const unsigned long res_opts[2]) + const int ai_flags[2]) { size_t addrlen = 0, masklen = 0; int result; @@ -1842,12 +1835,12 @@ int xioparsenetwork( switch (pf) { #if WITH_IP4 case PF_INET: - return xioparsenetwork_ip4(rangename, range, ai_flags, res_opts); + return xioparsenetwork_ip4(rangename, range, ai_flags); break; #endif /* WITH_IP4 */ #if WITH_IP6 case PF_INET6: - return xioparsenetwork_ip6(rangename, range, ai_flags, res_opts); + return xioparsenetwork_ip6(rangename, range, ai_flags); break; #endif /* WITH_IP6 */ case PF_UNSPEC: @@ -1912,11 +1905,10 @@ int xioparserange( const char *rangename, int pf, struct xiorange *range, - const int ai_flags[2], - const unsigned long res_opts[2]) + const int ai_flags[2]) { int i; - if (xioparsenetwork(rangename, pf, range, ai_flags, res_opts) < 0) { + if (xioparsenetwork(rangename, pf, range, ai_flags) < 0) { Error2("failed to parse or resolve range \"%s\" (pf=%d)", rangename, pf); return -1; } diff --git a/xio-socket.h b/xio-socket.h index cea2749..c4ce864 100644 --- a/xio-socket.h +++ b/xio-socket.h @@ -125,8 +125,8 @@ int xiocheckpeer(xiosingle_t *xfd, extern int xiosetsockaddrenv(const char *lr, union sockaddr_union *sau, socklen_t salen, int proto); -extern int xioparsenetwork(const char *rangename, int pf, struct xiorange *range, const int ai_flags[2], const unsigned long res_opts[2]); -extern int xioparserange(const char *rangename, int pf, struct xiorange *range, const int ai_flags[2], const unsigned long res_opts[2]); +extern int xioparsenetwork(const char *rangename, int pf, struct xiorange *range, const int ai_flags[2]); +extern int xioparserange(const char *rangename, int pf, struct xiorange *range, const int ai_flags[2]); extern int xiosocket(struct opt *opts, int pf, int socktype, int proto, int level); diff --git a/xio-socks.c b/xio-socks.c index 26d49ec..9795617 100644 --- a/xio-socks.c +++ b/xio-socks.c @@ -100,7 +100,6 @@ static int xioopen_socks4_connect(int argc, const char *argv[], struct opt *opts _xioopen_ipapp_prepare(opts, &opts0, sockdname, socksport, &pf, ipproto, xfd->para.socket.ip.ai_flags, - xfd->para.socket.ip.res_opts, &themlist, us, &uslen, &needbind, &lowport, socktype); @@ -297,8 +296,7 @@ int if ((result = xioresolve(hostname, NULL, PF_INET, SOCK_STREAM, IPPROTO_TCP, &sau, &saulen, - xfd->para.socket.ip.ai_flags, - xfd->para.socket.ip.res_opts)) + xfd->para.socket.ip.ai_flags)) != STAT_OK) { return result; /*! STAT_RETRY? */ } diff --git a/xio-tun.c b/xio-tun.c index e7eb003..7fd096d 100644 --- a/xio-tun.c +++ b/xio-tun.c @@ -134,8 +134,7 @@ static int xioopen_tun(int argc, const char *argv[], struct opt *opts, int xiofl return STAT_RETRYLATER; } if ((result = xioparsenetwork(ifaddr, pf, &network, - xfd->stream.para.socket.ip.ai_flags, - xfd->stream.para.socket.ip.res_opts)) + xfd->stream.para.socket.ip.ai_flags)) != STAT_OK) { /*! recover */ return result; diff --git a/xio-udp.c b/xio-udp.c index 73f0dc8..5992da2 100644 --- a/xio-udp.c +++ b/xio-udp.c @@ -108,8 +108,7 @@ int _xioopen_ipdgram_listen(struct single *sfd, #if WITH_IP4 /*|| WITH_IP6*/ if (retropt_string(opts, OPT_RANGE, &rangename) >= 0) { if (xioparserange(rangename, pf, &sfd->para.socket.range, - sfd->para.socket.ip.ai_flags, - sfd->para.socket.ip.res_opts) + sfd->para.socket.ip.ai_flags) < 0) { free(rangename); return STAT_NORETRY; @@ -321,8 +320,7 @@ int xioopen_ipdgram_listen(int argc, const char *argv[], struct opt *opts, uslen = socket_init(pf, &us); retropt_bind(opts, pf, socktype, ipproto, (struct sockaddr *)&us, &uslen, 1, - xfd->stream.para.socket.ip.ai_flags, - xfd->stream.para.socket.ip.res_opts); + xfd->stream.para.socket.ip.ai_flags); if (false) { ; @@ -384,7 +382,6 @@ int _xioopen_udp_sendto(const char *hostname, const char *servname, xfd->howtoend = END_SHUTDOWN; - /* ...res_opts[] */ if (applyopts_single(xfd, opts, PH_INIT) < 0) return -1; applyopts(-1, opts, PH_INIT); @@ -392,8 +389,7 @@ int _xioopen_udp_sendto(const char *hostname, const char *servname, if ((result = xioresolve(hostname, servname, pf, socktype, ipproto, &xfd->peersa, &xfd->salen, - xfd->para.socket.ip.ai_flags, - xfd->para.socket.ip.res_opts)) + xfd->para.socket.ip.ai_flags)) != STAT_OK) { return result; } @@ -402,8 +398,7 @@ int _xioopen_udp_sendto(const char *hostname, const char *servname, } uslen = socket_init(pf, &us); if (retropt_bind(opts, pf, socktype, ipproto, &us.soa, &uslen, feats, - xfd->para.socket.ip.ai_flags, - xfd->para.socket.ip.res_opts) + xfd->para.socket.ip.ai_flags) != STAT_NOACTION) { needbind = true; } @@ -479,8 +474,7 @@ int xioopen_udp_datagram(int argc, const char *argv[], struct opt *opts, if (retropt_string(opts, OPT_RANGE, &rangename) >= 0) { if (xioparserange(rangename, pf, &xfd->para.socket.range, - xfd->para.socket.ip.ai_flags, - xfd->para.socket.ip.res_opts) + xfd->para.socket.ip.ai_flags) < 0) { free(rangename); return STAT_NORETRY; @@ -539,7 +533,7 @@ int xioopen_udp_recvfrom(int argc, const char *argv[], struct opt *opts, if ((result = xioresolve(NULL, argv[1], pf, socktype, ipproto, &us, &uslen, - ai_flags2, xfd->stream.para.socket.ip.res_opts)) + ai_flags2)) != STAT_OK) { return result; } @@ -552,8 +546,7 @@ int xioopen_udp_recvfrom(int argc, const char *argv[], struct opt *opts, socklen_t lalen = sizeof(la); if (retropt_bind(opts, pf, socktype, ipproto, &la.soa, &lalen, 1, - xfd->stream.para.socket.ip.ai_flags, - xfd->stream.para.socket.ip.res_opts) + xfd->stream.para.socket.ip.ai_flags) != STAT_NOACTION) { switch (pf) { #if WITH_IP4 @@ -622,7 +615,7 @@ int xioopen_udp_recv(int argc, const char *argv[], struct opt *opts, if ((result = xioresolve(NULL, argv[1], pf, socktype, ipproto, &us, &uslen, - ai_flags2, xfd->stream.para.socket.ip.res_opts)) + ai_flags2)) != STAT_OK) { return result; } @@ -637,8 +630,7 @@ int xioopen_udp_recv(int argc, const char *argv[], struct opt *opts, if (retropt_bind(opts, pf, socktype, ipproto, &xfd->stream.para.socket.la.soa, &lalen, 1, - xfd->stream.para.socket.ip.ai_flags, - xfd->stream.para.socket.ip.res_opts) + ai_flags2) != STAT_NOACTION) { switch (pf) { #if WITH_IP4 @@ -659,8 +651,7 @@ int xioopen_udp_recv(int argc, const char *argv[], struct opt *opts, #if WITH_IP4 /*|| WITH_IP6*/ if (retropt_string(opts, OPT_RANGE, &rangename) >= 0) { if (xioparserange(rangename, pf, &xfd->stream.para.socket.range, - xfd->stream.para.socket.ip.ai_flags, - xfd->stream.para.socket.ip.res_opts) + xfd->stream.para.socket.ip.ai_flags) < 0) { free(rangename); return STAT_NORETRY; diff --git a/xio-unix.c b/xio-unix.c index 5de2bd6..1952c75 100644 --- a/xio-unix.c +++ b/xio-unix.c @@ -240,7 +240,7 @@ static int xioopen_unix_connect(int argc, const char *argv[], struct opt *opts, retropt_bool(opts, OPT_UNLINK_CLOSE, &opt_unlink_close); } if (retropt_bind(opts, pf, socktype, protocol, (struct sockaddr *)&us, &uslen, - (abstract<<1)|xfd->para.socket.un.tight, NULL, NULL) + (abstract<<1)|xfd->para.socket.un.tight, NULL) == STAT_OK) { needbind = true; } @@ -384,7 +384,7 @@ static int xioopen_unix_sendto(int argc, const char *argv[], struct opt *opts, i xfd->dtype = XIODATA_RECVFROM; if (retropt_bind(opts, pf, socktype, protocol, &us.soa, &uslen, - (abstract<<1)| xfd->para.socket.un.tight, NULL, NULL) + (abstract<<1)| xfd->para.socket.un.tight, NULL) == STAT_OK) { needbind = true; } @@ -453,7 +453,7 @@ int xioopen_unix_recvfrom(int argc, const char *argv[], struct opt *opts, #if 0 if (retropt_bind(opts, pf, socktype, protocol, (struct sockaddr *)&us, &uslen, - (abstract<<1)|xfd->para.socket.un.tight, NULL, NULL) + (abstract<<1)|xfd->para.socket.un.tight, NULL) == STAT_OK) { } #endif @@ -534,7 +534,7 @@ int xioopen_unix_recv(int argc, const char *argv[], struct opt *opts, #if 0 if (retropt_bind(opts, pf, socktype, protocol, &us.soa, &uslen, - (abstract<<1)|xfd->para.socket.un.tight, NULL, NULL) + (abstract<<1)|xfd->para.socket.un.tight, NULL) == STAT_OK) { } #endif @@ -619,7 +619,7 @@ _xioopen_unix_client(xiosingle_t *xfd, int xioflags, groups_t groups, retropt_bool(opts, OPT_UNLINK_CLOSE, &opt_unlink_close); } if (retropt_bind(opts, pf, socktype, protocol, &us.soa, &uslen, - (abstract<<1)|xfd->para.socket.un.tight, NULL, NULL) + (abstract<<1)|xfd->para.socket.un.tight, NULL) != STAT_NOACTION) { needbind = true; } diff --git a/xio-vsock.c b/xio-vsock.c index fca97f0..ae86d6b 100644 --- a/xio-vsock.c +++ b/xio-vsock.c @@ -96,8 +96,7 @@ static int xioopen_vsock_connect(int argc, const char *argv[], struct opt *opts, xiolog_vsock_cid(); ret = retropt_bind(opts, pf, socktype, protocol, - (struct sockaddr *)&sa_local, &sa_len, 3, - NULL, NULL); + (struct sockaddr *)&sa_local, &sa_len, 3, NULL); if (ret == STAT_NORETRY) return ret; if (ret == STAT_OK) @@ -154,7 +153,7 @@ static int xioopen_vsock_listen(int argc, const char *argv[], struct opt *opts, opts0 = copyopts(opts, GROUP_ALL); ret = retropt_bind(opts, pf, socktype, protocol, (struct sockaddr *)&sa_bind, - &sa_len, 1, NULL, NULL); + &sa_len, 1, NULL); if (ret == STAT_NORETRY) return ret; if (ret == STAT_OK) diff --git a/xioopen.c b/xioopen.c index e55baec..855dd90 100644 --- a/xioopen.c +++ b/xioopen.c @@ -588,8 +588,22 @@ static xiosingle_t *xioparse_single(const char **addr) { } int xioopen_single(xiofile_t *xfd, int xioflags) { + struct single *sfd = &xfd->stream; const struct addrdesc *addrdesc; int result; + /* Values to be saved until xioopen() is finished */ + int do_res; +#if HAVE_RESOLV_H + struct __res_state save_res; +#endif /* HAVE_RESOLV_H */ + + if (applyopts_single(sfd, sfd->opts, PH_OFFSET) < 0) + return -1; + +#if HAVE_RESOLV_H + if ((do_res = xio_res_init(sfd, &save_res)) < 0) + return STAT_NORETRY; +#endif /* HAVE_RESOLV_H */ if ((xioflags&XIO_ACCMODE) == XIO_RDONLY) { xfd->tag = XIO_TAG_RDONLY; @@ -607,6 +621,12 @@ int xioopen_single(xiofile_t *xfd, int xioflags) { xfd->stream.opts, xioflags, xfd, addrdesc->groups, addrdesc->arg1, addrdesc->arg2, addrdesc->arg3); + +#if HAVE_RESOLV_H + if (do_res) + xio_res_init(sfd, &save_res); +#endif /* HAVE_RESOLV_H */ + return result; } diff --git a/xioopts.c b/xioopts.c index 3d1cc34..68eb5b5 100644 --- a/xioopts.c +++ b/xioopts.c @@ -2615,8 +2615,8 @@ int parseopts_table(const char **a, groups_t groups, struct opt **opts, } *buffp = '\0'; if (xioresolve(buff, NULL, AF_INET, SOCK_DGRAM, IPPROTO_IP, - (union sockaddr_union *)&sa, &salen, NULL, - NULL/*!! !*/) != STAT_OK) { + (union sockaddr_union *)&sa, &salen, NULL) + != STAT_OK) { opt->desc = ODESC_ERROR; continue; } opt->value.u_ip4addr = sa.sin_addr; @@ -3127,7 +3127,7 @@ int retropt_bind(struct opt *opts, UNIX (or'd): 1..tight 2..abstract */ - const int ai_flags[2], const unsigned long res_opts[2]) + const int ai_flags[2]) { const char portsep[] = ":"; const char *ends[] = { portsep, NULL }; @@ -3203,8 +3203,7 @@ int retropt_bind(struct opt *opts, if ((result = xioresolve(hostname[0]!='\0'?hostname:NULL, portp, af, socktype, ipproto, - (union sockaddr_union *)sa, salen, - ai_flags2, res_opts)) + (union sockaddr_union *)sa, salen, ai_flags2)) != STAT_OK) { Error("error resolving bind option"); return STAT_NORETRY; diff --git a/xioopts.h b/xioopts.h index b253ac5..96d323c 100644 --- a/xioopts.h +++ b/xioopts.h @@ -891,6 +891,7 @@ enum e_optcode { enum e_phase { PH_ALL, /* not for option definitions; use in apply funcs to say "all phases" */ + PH_OFFSET, /* automatically applied to xio-fd */ PH_INIT, /* retrieving info from original state */ PH_EARLY, /* before any other processing */ PH_PREOPEN, /* before file descriptor is created/opened */ @@ -958,7 +959,7 @@ extern int retropt_ulong(struct opt *opts, int optcode, unsigned long *result); extern int retropt_flag(struct opt *opts, int optcode, flags_t *result); extern int retropt_string(struct opt *opts, int optcode, char **result); extern int retropt_timespec(struct opt *opts, int optcode, struct timespec *result); -extern int retropt_bind(struct opt *opts, int af, int socktype, int ipproto, struct sockaddr *sa, socklen_t *salen, int feats, const int ai_flags[2], const unsigned long res_opts[2]); +extern int retropt_bind(struct opt *opts, int af, int socktype, int ipproto, struct sockaddr *sa, socklen_t *salen, int feats, const int ai_flags[2]); extern int applyopts(int fd, struct opt *opts, enum e_phase phase); extern int applyopts2(int fd, struct opt *opts, unsigned int from, unsigned int to);