From 7a90caade535b12efcb0a74d4f0a0bd716d7a0b2 Mon Sep 17 00:00:00 2001
From: Gerhard Rieger <gerhard@dest-unreach.org>
Date: Wed, 29 Jan 2025 21:49:16 +0100
Subject: [PATCH] Fixed build issues on disabled features

---
 CHANGES          |  3 ++
 fdname.c         |  4 +--
 sysutils.c       | 16 +++++-----
 xio-ip.c         |  7 ++++-
 xio-ip6.c        |  2 +-
 xio-ipapp.c      | 10 +++----
 xio-progcall.c   |  5 ++--
 xio-socket.c     | 77 ++++++++++++++++++++++++++++++------------------
 xio-socket.h     |  2 --
 xio-socketpair.c | 23 +++++++++++++++
 xio-socketpair.h |  2 ++
 xio-socks.c      | 11 +++++--
 xio-udp.c        |  4 +--
 xio-unix.c       | 21 +++++++++++--
 xio-vsock.c      |  2 +-
 xioconfig.h      | 18 ++++++-----
 xioopen.c        | 16 +++++-----
 xioopts.c        | 47 +++++++++++++++++------------
 xioopts.h        |  2 +-
 xioshutdown.c    |  3 +-
 xiowrite.c       |  2 ++
 21 files changed, 182 insertions(+), 95 deletions(-)

diff --git a/CHANGES b/CHANGES
index 691e417..5a94938 100644
--- a/CHANGES
+++ b/CHANGES
@@ -7,6 +7,9 @@ Security:
 Corrections:
 	Fixed display of option phases in help output.
 
+Building:
+	Disabling certain features during configure could break build process.
+
 Testing:
 	test.sh produces file results.txt with columns of test numbers, names,
 	and results.
diff --git a/fdname.c b/fdname.c
index e226bda..58aa509 100644
--- a/fdname.c
+++ b/fdname.c
@@ -226,7 +226,7 @@ int sockname(int fd, FILE *outfile, char style) {
 #define FDNAME_OPTLEN 256
 #define FDNAME_NAMELEN 256
    socklen_t optlen;
-#if HAVE_GETPROTOBYNUMBER || HAVE_GETPROTOBYNUMBER_R
+#if WITH_IP && ( HAVE_GETPROTOBYNUMBER || HAVE_GETPROTOBYNUMBER_R )
    struct protoent protoent, *protoentp;
 #endif
 #define PROTONAMEMAX 1024
@@ -278,7 +278,7 @@ int sockname(int fd, FILE *outfile, char style) {
    Getsockopt(fd, SOL_SOCKET, SO_ACCEPTCONN, &optacceptconn, &optlen);
 #endif
 
-#if defined(SO_PROTOCOL) || defined(SO_PROTOTYPE)
+#if WITH_IP && ( defined(SO_PROTOCOL) || defined(SO_PROTOTYPE) )
 #if HAVE_GETPROTOBYNUMBER_R==1 /* Linux */
    rc = getprotobynumber_r(proto, &protoent, protoname, sizeof(protoname), &protoentp);
    if (protoentp == NULL) {
diff --git a/sysutils.c b/sysutils.c
index ee24454..082e845 100644
--- a/sysutils.c
+++ b/sysutils.c
@@ -677,7 +677,7 @@ int xiopoll(struct pollfd fds[], unsigned long nfds, struct timeval *timeout) {
 }
 
 
-#if WITH_TCP || WITH_UDP
+#if WITH_TCP || WITH_UDP || WITH_SCTP || WITH_DCCP || WITH_UDPLITE
 /* returns port in network byte order;
    ipproto==IPPROTO_UDP resolves as UDP service, every other value resolves as
    TCP */
@@ -702,10 +702,10 @@ int parseport(const char *portname, int ipproto) {
 
    return se->s_port;
 }
-#endif /* WITH_TCP || WITH_UDP */
+#endif /* WITH_TCP || WITH_UDP || WITH_SCTP || WITH_DCCP || WITH_UDPLITE */
 
 
-#if WITH_IP4 || WITH_IP6 || WITH_INTERFACE
+#if WITH_IP4 || WITH_IP6 || _WITH_INTERFACE
 /* check the systems interfaces for ifname and return its index
    or -1 if no interface with this name was found
    The system calls require an arbitrary socket; the calling program may
@@ -729,8 +729,8 @@ int ifindexbyname(const char *ifname, int anysock) {
    }
    if (anysock >= 0) {
       s = anysock;
-   } else  if ((s = Socket(PF_INET, SOCK_DGRAM, IPPROTO_IP)) < 0) {
-      Error1("socket(PF_INET, SOCK_DGRAM, IPPROTO_IP): %s", strerror(errno));
+   } else  if ((s = Socket(PF_INET, SOCK_DGRAM, 0)) < 0) {
+      Error1("socket(PF_INET, SOCK_DGRAM, 0): %s", strerror(errno));
       return -1;
    }
 
@@ -756,10 +756,10 @@ int ifindexbyname(const char *ifname, int anysock) {
    return -1;
 #endif /* !defined(HAVE_ STRUCT_IFREQ) && defined(SIOCGIFCONF) && defined(SIOCGIFINDEX) */
 }
-#endif /* WITH_IP4 || WITH_IP6 || WITH_INTERFACE */
+#endif /* WITH_IP4 || WITH_IP6 || _WITH_INTERFACE */
 
 
-#if WITH_IP4 || WITH_IP6 || WITH_INTERFACE
+#if WITH_IP4 || WITH_IP6 || _WITH_INTERFACE
 /* like ifindexbyname(), but also allows the index number as input - in this
    case it does not lookup the index.
    writes the resulting index to *ifindex and returns 0,
@@ -783,7 +783,7 @@ int ifindex(const char *ifname, unsigned int *ifindex, int anysock) {
    *ifindex = val;
    return 0;
 }
-#endif /* WITH_IP4 || WITH_IP6 || WITH_INTERFACE */
+#endif /* WITH_IP4 || WITH_IP6 || _WITH_INTERFACE */
 
 
 int _xiosetenv(const char *envname, const char *value, int overwrite, const char *sep) {
diff --git a/xio-ip.c b/xio-ip.c
index 6821571..3a136d0 100644
--- a/xio-ip.c
+++ b/xio-ip.c
@@ -68,7 +68,7 @@ const struct optdesc opt_ip_multicast_if  ={"ip-multicast-if",  "multicast-if",
 #ifdef IP_PKTOPTIONS
 const struct optdesc opt_ip_pktoptions = { "ip-pktoptions", "pktopts", OPT_IP_PKTOPTIONS, GROUP_SOCK_IP, PH_PASTSOCKET, TYPE_INT, OFUNC_SOCKOPT, SOL_IP, IP_PKTOPTIONS };
 #endif
-#ifdef IP_ADD_MEMBERSHIP
+#if defined(HAVE_STRUCT_IP_MREQ) || defined(HAVE_STRUCT_IP_MREQN)
 const struct optdesc opt_ip_add_membership = { "ip-add-membership", "membership",OPT_IP_ADD_MEMBERSHIP, GROUP_SOCK_IP, PH_PASTSOCKET, TYPE_IP_MREQN, OFUNC_SPEC, SOL_IP, IP_ADD_MEMBERSHIP };
 #endif
 #if defined(HAVE_STRUCT_IP_MREQ_SOURCE) && defined(IP_ADD_SOURCE_MEMBERSHIP)
@@ -1128,6 +1128,9 @@ int xiotype_ip_add_membership(
 }
 #endif /* defined(HAVE_STRUCT_IP_MREQ) || defined (HAVE_STRUCT_IP_MREQN) */
 
+
+#if _WITH_IP4
+
 #if defined(HAVE_STRUCT_IP_MREQ) || defined (HAVE_STRUCT_IP_MREQN)
 int xioapply_ip_add_membership(
 	struct single *sfd,
@@ -1386,6 +1389,8 @@ int xioapply_ip_add_source_membership(struct single *sfd, struct opt *opt) {
 
 #endif /* HAVE_STRUCT_IP_MREQ_SOURCE */
 
+#endif /* _WITH_IP4 */
+
 
 #if WITH_RESOLVE
 #if HAVE_RESOLV_H
diff --git a/xio-ip6.c b/xio-ip6.c
index 04eff08..8bd4a53 100644
--- a/xio-ip6.c
+++ b/xio-ip6.c
@@ -23,7 +23,7 @@ static char *inet6addr_info(const struct in6_addr *sa, char *buff, size_t blen);
 #ifdef IPV6_V6ONLY
 const struct optdesc opt_ipv6_v6only = { "ipv6-v6only", "ipv6only", OPT_IPV6_V6ONLY, GROUP_SOCK_IP6, PH_PREBIND, TYPE_INT, OFUNC_SOCKOPT, SOL_IPV6, IPV6_V6ONLY };
 #endif
-#ifdef IPV6_JOIN_GROUP
+#if defined(HAVE_STRUCT_IP_MREQ) || defined(HAVE_STRUCT_IP_MREQN)
 const struct optdesc opt_ipv6_join_group = { "ipv6-join-group", "join-group", OPT_IPV6_JOIN_GROUP, GROUP_SOCK_IP6, PH_PASTSOCKET, TYPE_IP_MREQN, OFUNC_SPEC, SOL_IPV6, IPV6_JOIN_GROUP };
 #endif
 #ifdef MCAST_JOIN_SOURCE_GROUP
diff --git a/xio-ipapp.c b/xio-ipapp.c
index 1cb1b64..fcc0d33 100644
--- a/xio-ipapp.c
+++ b/xio-ipapp.c
@@ -6,7 +6,7 @@
 
 #include "xiosysincludes.h"
 
-#if WITH_TCP || WITH_UDP
+#if WITH_TCP || WITH_UDP || WITH_SCTP || WITH_DCCP || WITH_UDPLITE
 
 #include "xioopen.h"
 #include "xio-socket.h"
@@ -19,7 +19,7 @@ const struct optdesc opt_sourceport = { "sourceport", "sp",       OPT_SOURCEPORT
 /*const struct optdesc opt_port = { "port",  NULL,    OPT_PORT,        GROUP_IPAPP, PH_BIND,    TYPE_USHORT,	OFUNC_SPEC };*/
 const struct optdesc opt_lowport = { "lowport", NULL, OPT_LOWPORT, GROUP_IPAPP, PH_LATE, TYPE_BOOL, OFUNC_SPEC };
 
-#if WITH_IP4
+#if _WITH_IP4 || _WITH_IP6
 /* we expect the form "host:port" */
 int xioopen_ipapp_connect(
 	int argc,
@@ -276,7 +276,7 @@ int
 
    return STAT_OK;
 }
-#endif /* WITH_IP4 */
+#endif /* _WITH_IP4 || _WITH_IP6 */
 
 
 #if WITH_TCP && WITH_LISTEN
@@ -382,6 +382,6 @@ int xioopen_ipapp_listen(
       return result;
    return 0;
 }
-#endif /* WITH_IP4 && WITH_TCP && WITH_LISTEN */
+#endif /* WITH_TCP && WITH_LISTEN */
 
-#endif /* WITH_TCP || WITH_UDP */
+#endif /* WITH_TCP || WITH_UDP || WITH_SCTP || WITH_DCCP || WITH_UDPLITE */
diff --git a/xio-progcall.c b/xio-progcall.c
index f980ef9..d0b8c1c 100644
--- a/xio-progcall.c
+++ b/xio-progcall.c
@@ -12,6 +12,7 @@
 #include "xio-progcall.h"
 
 #include "xio-socket.h"
+#include "xio-socketpair.h"
 
 
 /* these options are used by address pty too */
@@ -23,7 +24,7 @@ const struct optdesc opt_ptmx    = { "ptmx",      NULL, OPT_PTMX,        GROUP_P
 #endif
 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
+#if WITH_EXEC || WITH_SYSTEM || WITH_SHELL
 
 #define MAXPTYNAMELEN 64
 
@@ -623,7 +624,7 @@ int _xioopen_foxec(int xioflags,	/* XIO_RDONLY etc. */
    *optsp = popts;
    return pid;	/* indicate parent (main) process */
 }
-#endif /* WITH_EXEC || WITH_SYSTEM */
+#endif /* WITH_EXEC || WITH_SYSTEM || WITH_SHELL */
 
 
 int setopt_path(struct opt *opts, char **path) {
diff --git a/xio-socket.c b/xio-socket.c
index 5a7782f..c2fb717 100644
--- a/xio-socket.c
+++ b/xio-socket.c
@@ -7,8 +7,6 @@
 
 #include "xiosysincludes.h"
 
-#if _WITH_SOCKET
-
 #include "xioopen.h"
 #include "xio-ascii.h"
 #include "xio-socket.h"
@@ -30,6 +28,8 @@
 #include "xio-tcpwrap.h"
 
 
+#if _WITH_SOCKET
+
 static int xioopen_socket_connect(int argc, const char *argv[], struct opt *opts, int xioflags, xiofile_t *xfd, const struct addrdesc *addrdesc);
 static int xioopen_socket_listen(int argc, const char *argv[], struct opt *opts, int xioflags, xiofile_t *xfd, const struct addrdesc *addrdesc);
 static int xioopen_socket_sendto(int argc, const char *argv[], struct opt *opts, int xioflags, xiofile_t *xfd, const struct addrdesc *addrdesc);
@@ -263,7 +263,12 @@ static int xioopen_socket_connect(
 
    socket_init(0, &us);
    if (retropt_bind(opts, 0 /*pf*/, socktype, proto, (struct sockaddr *)&us, &uslen, 3,
-		    sfd->para.socket.ip.ai_flags)
+#if _WITH_IP4 || _WITH_IP6
+		    sfd->para.socket.ip.ai_flags
+#else
+		    NULL
+#endif /* _WITH_IP4 || _WITH_IP6 */
+		    )
        != STAT_NOACTION) {
       needbind = true;
       us.soa.sa_family = pf;
@@ -540,7 +545,12 @@ int xioopen_socket_recvfrom(
 
    if (retropt_string(opts, OPT_RANGE, &rangename) >= 0) {
       if (xioparserange(rangename, 0, &sfd->para.socket.range,
-			sfd->para.socket.ip.ai_flags)
+#if _WITH_IP4 || _WITH_IP6
+			sfd->para.socket.ip.ai_flags
+#else
+			NULL
+#endif /* _WITH_IP4 */
+			)
 	  < 0) {
 	 free(rangename);
 	 return STAT_NORETRY;
@@ -626,7 +636,12 @@ int xioopen_socket_recv(
 
    if (retropt_string(opts, OPT_RANGE, &rangename) >= 0) {
       if (xioparserange(rangename, 0, &sfd->para.socket.range,
-			sfd->para.socket.ip.ai_flags)
+#if _WITH_IP4 || _WITH_IP6
+			sfd->para.socket.ip.ai_flags
+#else
+			NULL
+#endif /* _WITH_IP4 */
+			)
 	  < 0) {
 	 free(rangename);
 	 return STAT_NORETRY;
@@ -712,7 +727,12 @@ static int xioopen_socket_datagram(
    /* which reply sockets will accept - determine by range option */
    if (retropt_string(opts, OPT_RANGE, &rangename) >= 0) {
       if (xioparserange(rangename, 0, &sfd->para.socket.range,
-			sfd->para.socket.ip.ai_flags)
+#if _WITH_IP4 || _WITH_IP6
+			sfd->para.socket.ip.ai_flags
+#else
+			NULL
+#endif /* _WITH_IP4 */
+			)
 	  < 0) {
 	 free(rangename);
 	 return STAT_NORETRY;
@@ -1202,6 +1222,7 @@ int _xioopen_dgram_recvfrom(struct single *sfd, int xioflags,
    }
 #endif
 
+#if WITH_IP4
    /* for generic sockets, this has already been retrieved */
    if (retropt_string(opts, OPT_RANGE, &rangename) >= 0) {
       if (xioparserange(rangename, pf, &sfd->para.socket.range,
@@ -1213,6 +1234,7 @@ int _xioopen_dgram_recvfrom(struct single *sfd, int xioflags,
       free(rangename);
       sfd->para.socket.dorange = true;
    }
+#endif /* WITH_IP4 */
 
 #if (WITH_TCP || WITH_UDP) && WITH_LIBWRAP
    xio_retropt_tcpwrap(sfd, opts);
@@ -1424,6 +1446,7 @@ int _xioopen_dgram_recv(struct single *sfd, int xioflags,
    }
 #endif
 
+#if WITH_IP4
    if (retropt_string(opts, OPT_RANGE, &rangename) >= 0) {
       if (xioparserange(rangename, pf, &sfd->para.socket.range,
 			sfd->para.socket.ip.ai_flags)
@@ -1434,6 +1457,7 @@ int _xioopen_dgram_recv(struct single *sfd, int xioflags,
       free(rangename);
       sfd->para.socket.dorange = true;
    }
+#endif /* WITH_IP4 */
 
 #if (WITH_TCP || WITH_UDP) && WITH_LIBWRAP
    xio_retropt_tcpwrap(sfd, opts);
@@ -1449,7 +1473,10 @@ int _xioopen_dgram_recv(struct single *sfd, int xioflags,
    return STAT_OK;
 }
 
+#endif /* _WITH_SOCKET */
 
+
+#if _WITH_SOCKET || _WITH_SOCKETPAIR
 int retropt_socket_pf(struct opt *opts, int *pf) {
    char *pfname;
 
@@ -1478,8 +1505,11 @@ int retropt_socket_pf(struct opt *opts, int *pf) {
    }
    return -1;
 }
+#endif /* _WITH_SOCKET || _WITH_SOCKETPAIR */
 
 
+#if _WITH_SOCKET
+
 /* This function calls recvmsg(..., MSG_PEEK, ...) to obtain information about
    the arriving packet, thus it does not "consume" the packet.
    In msgh the msg_name pointer must refer to an (empty) sockaddr storage.
@@ -1651,7 +1681,7 @@ int xiocheckpeer(xiosingle_t *sfd,
    char infobuff[256];
    int result;
 
-#if WITH_IP4
+#if WITH_IP4 || WITH_IP6
    if (sfd->para.socket.dorange) {
       if (pa == NULL)  { return -1; }
       if (xiocheckrange(pa, &sfd->para.socket.range) < 0) {
@@ -2055,9 +2085,7 @@ int xiosetsockaddrenv(const char *lr,
 #  undef XIOSOCKADDRENVLEN
 }
 
-#endif /* _WITH_SOCKET */
-
-/* these do sockets internally */
+/* These do sockets internally */
 
 /* retrieves options so-type and so-prototype from opts, calls socket, and
    ev. generates an appropriate error message.
@@ -2080,24 +2108,6 @@ xiosocket(struct opt *opts, int pf, int socktype, int proto, int msglevel) {
    return result;
 }
 
-/* retrieves options so-type and so-prototype from opts, calls socketpair, and
-   ev. generates an appropriate error message.
-   returns 0 on success or -1 if an error occurred. */
-int
-xiosocketpair(struct opt *opts, int pf, int socktype, int proto, int sv[2]) {
-   int result;
-
-   retropt_int(opts, OPT_SO_TYPE, &socktype);
-   retropt_int(opts, OPT_SO_PROTOTYPE, &proto);
-   result = Socketpair(pf, socktype, proto, sv);
-   if (result < 0) {
-      Error5("socketpair(%d, %d, %d, %p): %s",
-	     pf, socktype, proto, sv, strerror(errno));
-      return -1;
-   }
-   return result;
-}
-
 /* Binds a socket to a socket address. Handles IP (internet protocol), UNIX
    domain, Linux abstract UNIX domain.
    The bind address us may be NULL in which case no bind() happens, except with
@@ -2206,8 +2216,12 @@ int xiobind(
       if (us) {
 	 sinp = us;
       } else {
-	 if (pf == AF_INET) {
+	 if (0) {
+	    ;
+#if WITH_IP4
+	 } else if (pf == AF_INET) {
 	    socket_in_init(&sin.ip4);
+#endif
 #if WITH_IP6
 	 } else {
 	    socket_in6_init(&sin.ip6);
@@ -2307,10 +2321,12 @@ int xiosock_reuseaddr(int fd, int ipproto, struct opt *opts)
 
 	val.u_int = 0;
 	notnull.u_bool = false;
+#if WITH_TCP
 	if (ipproto == IPPROTO_TCP) {
 		val.u_int = 1;
 		notnull.u_bool = true;
 	}
+#endif /* WITH_TCP */
 	retropt_2integrals(opts, OPT_SO_REUSEADDR, &val, &notnull);
 	if (notnull.u_bool) {
 		if (Setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &val.u_int, sizeof(int))
@@ -2324,3 +2340,6 @@ int xiosock_reuseaddr(int fd, int ipproto, struct opt *opts)
 	}
 	return 0;
 }
+
+#endif /* _WITH_SOCKET */
+
diff --git a/xio-socket.h b/xio-socket.h
index 2064ed3..2af3367 100644
--- a/xio-socket.h
+++ b/xio-socket.h
@@ -135,8 +135,6 @@ extern int xioparserange(const char *rangename, int pf, struct xiorange *range,
 
 extern int
 xiosocket(struct opt *opts, int pf, int socktype, int proto, int level);
-extern int
-xiosocketpair(struct opt *opts, int pf, int socktype, int proto, int sv[2]);
 extern int xiosock_reuseaddr(int fd, int ipproto, struct opt *opts);
 
 #endif /* !defined(__xio_socket_h_included) */
diff --git a/xio-socketpair.c b/xio-socketpair.c
index 0da0c99..e062a44 100644
--- a/xio-socketpair.c
+++ b/xio-socketpair.c
@@ -95,3 +95,26 @@ static int xioopen_socketpair(
 }
 
 #endif /* WITH_SOCKETPAIR */
+
+
+#if _WITH_SOCKETPAIR
+
+/* retrieves options so-type and so-prototype from opts, calls socketpair, and
+   ev. generates an appropriate error message.
+   returns 0 on success or -1 if an error occurred. */
+int
+xiosocketpair(struct opt *opts, int pf, int socktype, int proto, int sv[2]) {
+   int result;
+
+   retropt_int(opts, OPT_SO_TYPE, &socktype);
+   retropt_int(opts, OPT_SO_PROTOTYPE, &proto);
+   result = Socketpair(pf, socktype, proto, sv);
+   if (result < 0) {
+      Error5("socketpair(%d, %d, %d, %p): %s",
+	     pf, socktype, proto, sv, strerror(errno));
+      return -1;
+   }
+   return result;
+}
+
+#endif /* _WITH_SOCKETPAIR */
diff --git a/xio-socketpair.h b/xio-socketpair.h
index 2f92f70..5822798 100644
--- a/xio-socketpair.h
+++ b/xio-socketpair.h
@@ -7,4 +7,6 @@
 
 const extern struct addrdesc xioaddr_socketpair;
 
+extern int xiosocketpair(struct opt *opts, int pf, int socktype, int proto, int sv[2]);
+
 #endif /* !defined(__xio_socketpair_h_included) */
diff --git a/xio-socks.c b/xio-socks.c
index d5234cb..2e9c224 100644
--- a/xio-socks.c
+++ b/xio-socks.c
@@ -6,14 +6,16 @@
 
 #include "xiosysincludes.h"
 
-#if WITH_SOCKS4 || WITH_SOCKS4A
-
 #include "xioopen.h"
 #include "xio-ascii.h"
 #include "xio-socket.h"
 #include "xio-ip.h"
 #include "xio-ipapp.h"
 
+#define SOCKSPORT "1080"
+
+#if WITH_SOCKS4 || WITH_SOCKS4A
+
 #include "xio-socks.h"
 
 
@@ -24,7 +26,6 @@ enum {
    SOCKS_CD_IDENTFAILED
 } ;
 
-#define SOCKSPORT "1080"
 #define BUFF_LEN (SIZEOF_STRUCT_SOCKS4+512)
 
 static int xioopen_socks4_connect(int argc, const char *argv[], struct opt *opts, int xioflags, xiofile_t *fd, const struct addrdesc *addrdesc);
@@ -229,6 +230,8 @@ static int xioopen_socks4_connect(
    return 0;
 }
 
+#endif /* WITH_SOCKS4 || WITH_SOCKS4A */
+#if WITH_SOCKS4 || WITH_SOCKS4A || WITH_SOCKS5
 
 int _xioopen_opt_socksport(
 	struct opt *opts,
@@ -253,6 +256,8 @@ int _xioopen_opt_socksport(
    return 0;
 }
 
+#endif /* WITH_SOCKS4 || WITH_SOCKS4A || WITH_SOCKS5 */
+#if WITH_SOCKS4 || WITH_SOCKS4A
 
 int _xioopen_socks4_prepare(const char *targetport, struct opt *opts, char **socksport, struct socks4 *sockhead, size_t *headlen) {
    char *userid;
diff --git a/xio-udp.c b/xio-udp.c
index 10704e3..98c2ced 100644
--- a/xio-udp.c
+++ b/xio-udp.c
@@ -85,7 +85,7 @@ int _xioopen_ipdgram_listen(struct single *sfd,
        return STAT_NORETRY;
    }
 
-#if WITH_IP4 /*|| WITH_IP6*/
+#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)
@@ -646,7 +646,7 @@ int xioopen_udp_recv(
    }
 #endif
 
-#if WITH_IP4 /*|| WITH_IP6*/
+#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)
diff --git a/xio-unix.c b/xio-unix.c
index 42bb2a3..8468fa2 100644
--- a/xio-unix.c
+++ b/xio-unix.c
@@ -257,7 +257,12 @@ static int xioopen_unix_connect(
 
    if (retropt_bind(opts, pf, socktype, protocol, (struct sockaddr *)&us, &uslen,
 		    (addrdesc->arg1/*abstract*/<<1)|sfd->para.socket.un.tight,
-		    sfd->para.socket.ip.ai_flags)
+#if WITH_TCP
+		    sfd->para.socket.ip.ai_flags
+#else
+		    0
+#endif /* WITH_TCP */
+)
       == STAT_OK) {
       needbind = true;
    }
@@ -426,7 +431,12 @@ static int xioopen_unix_sendto(
 
    if (retropt_bind(opts, pf, socktype, protocol, (struct sockaddr *)&us, &uslen,
 		    (addrdesc->arg1/*abstract*/<<1)| sfd->para.socket.un.tight,
-		    sfd->para.socket.ip.ai_flags)
+#if WITH_TCP
+		    sfd->para.socket.ip.ai_flags
+#else
+		    0
+#endif /* WITH_TCP */
+		    )
        == STAT_OK) {
       needbind = true;
    }
@@ -709,7 +719,12 @@ _xioopen_unix_client(
 
    if (retropt_bind(opts, pf, socktype, protocol, &us.soa, &uslen,
 		    (abstract<<1)|sfd->para.socket.un.tight,
-		    sfd->para.socket.ip.ai_flags)
+#if WITH_TCP
+		    sfd->para.socket.ip.ai_flags
+#else
+		    0
+#endif /* WITH_TCP */
+		    )
        != STAT_NOACTION) {
       needbind = true;
    }
diff --git a/xio-vsock.c b/xio-vsock.c
index fcd09bc..0531994 100644
--- a/xio-vsock.c
+++ b/xio-vsock.c
@@ -98,7 +98,7 @@ static int xioopen_vsock_connect(
 
    ret = retropt_bind(opts, pf, socktype, protocol,
                       (struct sockaddr *)&sa_local, &sa_len, 3,
-		      sfd->para.socket.ip.ai_flags);
+		      NULL);
    if (ret == STAT_NORETRY)
       return ret;
    if (ret == STAT_OK)
diff --git a/xioconfig.h b/xioconfig.h
index 1c12c1a..ab3d115 100644
--- a/xioconfig.h
+++ b/xioconfig.h
@@ -16,7 +16,13 @@
 #  define WITH_OPEN 1
 #endif
 
-#if WITH_OPEN || WITH_PIPE || WITH_UNIX || WITH_PTY
+#if WITH_INTERFACE || WITH_TUN
+#  define _WITH_INTERFACE 1
+#else
+#  define _WITH_INTERFACE 0
+#endif
+
+#if WITH_OPEN || WITH_PIPE || WITH_UNIX || WITH_PTY || _WITH_INTERFACE
 #  define WITH_NAMED 1
 #endif
 
@@ -34,7 +40,7 @@
 			   with IP6 */
 #endif
 
-#if WITH_OPENSSL
+#if WITH_OPENSSL || WITH_SOCKS5
 #  define WITH_TCP 1
 #  define WITH_IP4 1
 #endif
@@ -57,7 +63,7 @@
 #  define _WITH_UDP 1
 #endif
 
-#if WITH_UNIX || WITH_IP4 || WITH_IP6 || WITH_SOCKS4 || WITH_RAWIP || WITH_GENERICSOCKET
+#if WITH_UNIX || WITH_IP4 || WITH_IP6 || WITH_SOCKS4 || WITH_SOCKS5 || WITH_RAWIP || WITH_GENERICSOCKET || WITH_SOCKETPAIR || WITH_VSOCK
 #  define _WITH_SOCKET 1
 #else
 #  undef _WITH_SOCKET
@@ -71,10 +77,8 @@
 #  undef WITH_LIBWRAP
 #endif
 
-#if WITH_INTERFACE || WITH_TUN
-#  define _WITH_INTERFACE 1
-#else
-#  define _WITH_INTERFACE 0
+#if WITH_SOCKETPAIR || WITH_EXEC || WITH_SYSTEM || WITH_SHELL
+#  define _WITH_SOCKETPAIR 1
 #endif
 
 #if WITH_GENERICSOCKET || _WITH_INTERFACE
diff --git a/xioopen.c b/xioopen.c
index be17e3b..8a29f21 100644
--- a/xioopen.c
+++ b/xioopen.c
@@ -471,14 +471,14 @@ static xiofile_t *xioallocfd(void) {
    fd->stream.escape	= -1;
 /* fd->stream.para.exec.pid = 0; */
    fd->stream.lineterm  = LINETERM_RAW;
-#if WITH_RESOLVE
+#if ( _WITH_IP4 || _WITH_IP6 ) && WITH_RESOLVE
 #if HAVE_RES_RETRANS
    fd->stream.para.socket.ip.res.retrans = -1;
 #endif
 #if HAVE_RES_RETRY
    fd->stream.para.socket.ip.res.retry   = -1;
 #endif
-#endif /* WITH_RESOLVE */
+#endif /* ( _WITH_IP4 || _WITH_IP6 ) && WITH_RESOLVE */
    return fd;
 }
 
@@ -701,10 +701,10 @@ int xioopen_single(xiofile_t *xfd, int xioflags) {
    mode_t orig_umask, tmp_umask;
    int result;
    /* Values to be saved until xioopen() is finished */
-#if WITH_RESOLVE && HAVE_RESOLV_H
+#if ( _WITH_IP4 || _WITH_IP6 ) && WITH_RESOLVE && HAVE_RESOLV_H
    int do_res;
    struct __res_state save_res;
-#endif /* WITH_RESOLVE && HAVE_RESOLV_H */
+#endif
 #if WITH_NAMESPACES
    int save_netfd = -1;
 #endif
@@ -735,10 +735,10 @@ int xioopen_single(xiofile_t *xfd, int xioflags) {
       return -1;
 #endif /* WITH_NAMESPACES */
 
-#if WITH_RESOLVE && HAVE_RESOLV_H
+#if ( _WITH_IP4 || _WITH_IP6 ) && WITH_RESOLVE && HAVE_RESOLV_H
    if ((do_res = xio_res_init(sfd, &save_res)) < 0)
       return STAT_NORETRY;
-#endif /* WITH_RESOLVE && HAVE_RESOLV_H */
+#endif
 
    if (xio_chdir(sfd->opts, &orig_dir) < 0)
       return STAT_NORETRY;
@@ -769,10 +769,10 @@ int xioopen_single(xiofile_t *xfd, int xioflags) {
       free(orig_dir);
    }
 
-#if WITH_RESOLVE && HAVE_RESOLV_H
+#if ( _WITH_IP4 || _WITH_IP6 ) && WITH_RESOLVE && HAVE_RESOLV_H
    if (do_res)
       xio_res_restore(&save_res);
-#endif /* WITH_RESOLVE && HAVE_RESOLV_H */
+#endif
 
 #if WITH_NAMESPACES
    if (save_netfd > 0) {
diff --git a/xioopts.c b/xioopts.c
index a751fd3..81f1e53 100644
--- a/xioopts.c
+++ b/xioopts.c
@@ -177,7 +177,7 @@ static int applyopt(struct single *sfd,	int fd,	struct opt *opt);
    binary search! */
 /* NULL terminated */
 const struct optname optionnames[] = {
-#if HAVE_RESOLV_H && WITH_RES_AAONLY
+#if (WITH_IP4 || WITH_IP6) && HAVE_RESOLV_H && WITH_RES_AAONLY
 	IF_RESOLVE("aaonly",		&opt_res_aaonly)
 #endif
 #ifdef TCP_ABORT_THRESHOLD  /* HP_UX */
@@ -421,7 +421,7 @@ const struct optname optionnames[] = {
 #ifdef TCP_DEFER_ACCEPT	/* Linux 2.4.0 */
 	IF_TCP    ("defer-accept",	&opt_tcp_defer_accept)
 #endif
-#if HAVE_RESOLV_H
+#if (WITH_IP4 || WITH_IP6) && HAVE_RESOLV_H
 	IF_RESOLVE("defnames",		&opt_res_defnames)
 #endif /* HAVE_RESOLV_H */
 #ifdef O_DELAY
@@ -454,10 +454,10 @@ const struct optname optionnames[] = {
 #ifdef VDISCARD
 	IF_TERMIOS("discard",	&opt_vdiscard)
 #endif
-#if WITH_RESOLVE && HAVE_RESOLV_H && HAVE_RES_NSADDR_LIST
+#if (WITH_IP4 || WITH_IP6) && WITH_RESOLVE && HAVE_RESOLV_H && HAVE_RES_NSADDR_LIST
 	IF_IP     ("dns",		&opt_res_nsaddr)
 #endif
-#if HAVE_RESOLV_H
+#if (WITH_IP4 || WITH_IP6) && HAVE_RESOLV_H
 	IF_RESOLVE("dnsrch",		&opt_res_dnsrch)
 #endif /* HAVE_RESOLV_H */
 #ifdef SO_DONTLINGER
@@ -721,7 +721,7 @@ const struct optname optionnames[] = {
 	IF_ANY    ("ignoreeof",	&opt_ignoreeof)
 	IF_ANY    ("ignoreof",	&opt_ignoreeof)
 	IF_TERMIOS("ignpar",	&opt_ignpar)
-#if HAVE_RESOLV_H
+#if (WITH_IP4 || WITH_IP6) && HAVE_RESOLV_H
 	IF_RESOLVE("igntc",		&opt_res_igntc)
 #endif /* HAVE_RESOLV_H */
 	IF_TERMIOS("imaxbel",	&opt_imaxbel)
@@ -1050,7 +1050,7 @@ const struct optname optionnames[] = {
 	IF_IP     ("multicast-ttl",	&opt_ip_multicast_ttl)
 	IF_IP     ("multicastloop",	&opt_ip_multicast_loop)
 	IF_IP     ("multicastttl",	&opt_ip_multicast_ttl)
-#if WITH_RESOLVE && HAVE_RESOLV_H && HAVE_RES_NSADDR_LIST
+#if (WITH_IP4 || WITH_IP6) && WITH_RESOLVE && HAVE_RESOLV_H && HAVE_RES_NSADDR_LIST
 	IF_IP     ("nameserver",	&opt_res_nsaddr)
 #endif
 #if defined(O_NDELAY) && (!defined(O_NONBLOCK) || O_NDELAY != O_NONBLOCK)
@@ -1118,7 +1118,7 @@ const struct optname optionnames[] = {
 	IF_OPENSSL("nosni",		&opt_openssl_no_sni)
 #endif
 	IF_INTERFACE("notrailers",	&opt_iff_notrailers)
-#if WITH_RESOLVE && HAVE_RESOLV_H && HAVE_RES_NSADDR_LIST
+#if (WITH_IP4 || WITH_IP6) && WITH_RESOLVE && HAVE_RESOLV_H && HAVE_RES_NSADDR_LIST
 	IF_IP     ("nsaddr",		&opt_res_nsaddr)
 #endif
 #ifdef O_NSHARE
@@ -1350,7 +1350,7 @@ const struct optname optionnames[] = {
 #if WITH_POSIXMQ
 	IF_ANY	  ("posixmq-priority",	&opt_posixmq_priority)
 #endif
-#if HAVE_RESOLV_H && WITH_RES_PRIMARY
+#if (WITH_IP4 || WITH_IP6) && HAVE_RESOLV_H && WITH_RES_PRIMARY
 	IF_RESOLVE("primary",		&opt_res_primary)
 #endif
 #ifdef SO_PRIORITY
@@ -1411,7 +1411,7 @@ const struct optname optionnames[] = {
 	IF_OPEN   ("rdonly",	&opt_o_rdonly)
 	IF_OPEN   ("rdwr",	&opt_o_rdwr)
 	IF_ANY    ("readbytes", &opt_readbytes)
-#if HAVE_RESOLV_H
+#if (WITH_IP4 || WITH_IP6) && HAVE_RESOLV_H
 	IF_RESOLVE("recurse",		&opt_res_recurse)
 #endif /* HAVE_RESOLV_H */
 #ifdef IP_RECVDSTADDR
@@ -1451,7 +1451,7 @@ const struct optname optionnames[] = {
 #ifdef VREPRINT
 	IF_TERMIOS("reprint",	&opt_vreprint)
 #endif
-#if HAVE_RESOLV_H
+#if (WITH_IP4 || WITH_IP6) && HAVE_RESOLV_H
 #  if WITH_AA_ONLY
 	IF_RESOLVE("res-aaonly",	&opt_res_aaonly)
 #  endif
@@ -1480,15 +1480,15 @@ const struct optname optionnames[] = {
 #  endif
 	IF_RESOLVE("res-stayopen",	&opt_res_stayopen)
 	IF_RESOLVE("res-usevc",		&opt_res_usevc)
-#endif /* HAVE_RESOLV_H */
+#endif /* (WITH_IP4 || WITH_IP6) && HAVE_RESOLV_H */
 	IF_PROXY  ("resolv",	&opt_proxy_resolve)
 	IF_PROXY  ("resolve",	&opt_proxy_resolve)
 #ifdef IP_RETOPTS
 	IF_IP     ("retopts",	&opt_ip_retopts)
 #endif
-#  if HAVE_RES_RETRANS
+#if (WITH_IP4 || WITH_IP6) && HAVE_RES_RETRANS
 	IF_RESOLVE("retrans",		&opt_res_retrans)
-#  endif
+#endif
 #if WITH_INTERFACE && defined(PACKET_AUXDATA)
 	IF_SOCKET ("retrieve-vlan", 		&opt_retrieve_vlan)
 #endif
@@ -1724,7 +1724,7 @@ const struct optname optionnames[] = {
 	IF_IPAPP  ("sourceport",	&opt_sourceport)
 	IF_IPAPP  ("sp",	&opt_sourceport)
 	IF_TERMIOS("start",	&opt_vstart)
-#if HAVE_RESOLV_H
+#if (WITH_IP4 || WITH_IP6) && HAVE_RESOLV_H
 	IF_RESOLVE("stayopen",		&opt_res_stayopen)
 #endif /* HAVE_RESOLV_H */
 	IF_EXEC   ("stderr",    &opt_stderr)
@@ -1930,7 +1930,7 @@ const struct optname optionnames[] = {
 	IF_ANY    ("user",	&opt_user)
 	IF_NAMED  ("user-early",	&opt_user_early)
 	IF_ANY    ("user-late",	&opt_user_late)
-#if HAVE_RESOLV_H
+#if (WITH_IP4 || WITH_IP6) && HAVE_RESOLV_H
 	IF_RESOLVE("usevc",		&opt_res_usevc)
 #endif /* HAVE_RESOLV_H */
 #if defined(AI_V4MAPPED)
@@ -2654,13 +2654,13 @@ int parseopts_table(const char **a, groups_t groups, struct opt **opts,
 	       (*opts)[i].value3.u_string);
 	 break;
 
-#if defined(HAVE_STRUCT_IP_MREQ) || defined (HAVE_STRUCT_IP_MREQN)
+#if (WITH_IP4 || WITH_IP6) && ( defined(HAVE_STRUCT_IP_MREQ) || defined (HAVE_STRUCT_IP_MREQN) )
       case TYPE_IP_MREQN:
 	 xiotype_ip_add_membership(token, ent, opt);
 	 break;
-#endif /* defined(HAVE_STRUCT_IP_MREQ) || defined (HAVE_STRUCT_IP_MREQN) */
+#endif /* WITH_IP && defined(HAVE_STRUCT_IP_MREQ) || defined (HAVE_STRUCT_IP_MREQN) ) */
 
-#if defined(HAVE_STRUCT_IP_MREQ_SOURCE) && defined(IP_ADD_SOURCE_MEMBERSHIP)
+#if _WITH_IP4 && defined(HAVE_STRUCT_IP_MREQ_SOURCE)
       case TYPE_IP_MREQ_SOURCE:
 	 xiotype_ip_add_source_membership(token, ent, opt);
 	 break;
@@ -3323,6 +3323,7 @@ int retropt_bind(struct opt *opts,
 	 }
       }
 
+#  if WITH_IP4 || WITH_IP6
       /* Set AI_PASSIVE, except when it is explicitely disabled */
       ai_flags2[0] = ai_flags[0];
       ai_flags2[1] = ai_flags[1];
@@ -3337,6 +3338,8 @@ int retropt_bind(struct opt *opts,
 	 Error("error resolving bind option");
 	 return STAT_NORETRY;
       }
+/*#  else */
+#  endif /* WITH_IP4 || WITH_IP6 */
       break;
 #endif /* WITH_IP4 || WITH_IP6 || WITH_VSOCK */
 
@@ -3567,6 +3570,8 @@ int applyopt_ioctl_generic(
 	return 0;
 }
 
+#if _WITH_SOCKET
+
 int applyopt_sockopt(
 	int fd,
 	struct opt *opt)
@@ -3695,7 +3700,7 @@ int applyopt_sockopt(
 	}
 	break;
 #endif /* HAVE_STRUCT_LINGER */
-#if defined(HAVE_STRUCT_IP_MREQ) || defined (HAVE_STRUCT_IP_MREQN)
+#if (WITH_IP4 || WITH_IP6) && ( defined(HAVE_STRUCT_IP_MREQ) || defined (HAVE_STRUCT_IP_MREQN) )
 	case TYPE_IP_MREQN:
 		/* handled in applyopts_single */
 		break;
@@ -3815,6 +3820,8 @@ int applyopt_sockopt_generic(
 	return 0;
 }
 
+#endif /* _WITH_SOCKET */
+
 int applyopt_flock(
 	int fd,
 	struct opt *opt)
@@ -4272,6 +4279,7 @@ static int applyopt_offset(struct single *sfd, struct opt *opt) {
    case TYPE_CONST:
       *(int *)ptr = opt->desc->minor;
       break;
+#if WITH_IP4
    case TYPE_IP4NAME:
       memset(ptr, 0, sizeof(struct sockaddr_in));
       ((struct sockaddr_in *)ptr)->sin_addr   = opt->value.u_ip4addr;
@@ -4281,6 +4289,7 @@ static int applyopt_offset(struct single *sfd, struct opt *opt) {
       memset(ptr, 0, sizeof(struct sockaddr_in));
       *(struct sockaddr_in *)ptr = opt->value.u_ip4sock;
       break;
+#endif /* WITH_IP4 */
    default:
       Error2("applyopt_offset(opt:%s): type %s not implemented",
 	     opt->desc->defname, xiohelp_opttypename(opt->desc->type));
diff --git a/xioopts.h b/xioopts.h
index ef3b31c..37545e1 100644
--- a/xioopts.h
+++ b/xioopts.h
@@ -72,7 +72,7 @@ enum e_types {
 #if HAVE_STRUCT_LINGER
    TYPE_LINGER,		/* struct linger */
 #endif /* HAVE_STRUCT_LINGER */
-#if HAVE_STRUCT_IP_MREQ || HAVE_STRUCT_IP_MREQN
+#if (WITH_IP4 || WITH_IP6) && ( defined(HAVE_STRUCT_IP_MREQ) || defined(HAVE_STRUCT_IP_MREQN) )
    TYPE_IP_MREQN,	/* for  struct ip_mreq  or  struct ip_mreqn */
 #endif
 #if HAVE_STRUCT_IP_MREQ_SOURCE
diff --git a/xioshutdown.c b/xioshutdown.c
index c1ec796..6af190e 100644
--- a/xioshutdown.c
+++ b/xioshutdown.c
@@ -10,6 +10,7 @@
 
 #include "xio-openssl.h"
 
+
 static pid_t socat_kill_pid;	/* here we pass the pid to be killed in sighandler */
 
 static void signal_kill_pid(int dummy) {
@@ -51,6 +52,7 @@ int xioshutdown(xiofile_t *sock, int how) {
 	       sock->stream.fd, strerror(errno));
       }
       return 0;
+#if _WITH_SOCKET
    case XIOSHUT_DOWN:
       result = Shutdown(sock->stream.fd, how);
       if (result < 0) {
@@ -70,7 +72,6 @@ int xioshutdown(xiofile_t *sock, int how) {
 	 return -1;
       }
       return 0;
-#if _WITH_SOCKET
    case XIOSHUT_NULL:
       writenull = '\0'; 	/* assign something to make gcc happy */
       /* send an empty packet; only useful on datagram sockets? */
diff --git a/xiowrite.c b/xiowrite.c
index 5388baf..a3e77ab 100644
--- a/xiowrite.c
+++ b/xiowrite.c
@@ -116,8 +116,10 @@ ssize_t xiowrite(xiofile_t *file, const void *buff, size_t bytes) {
    case XIOWRITE_PIPE:
       if (pipe->para.bipipe.socktype == SOCK_STREAM) {
 	 writt = Write(pipe->para.bipipe.fdout, buff, bytes);
+#if _WITH_SOCKET
       } else {
 	 writt = Send(pipe->para.bipipe.fdout, buff, bytes, 0);
+#endif /* _WITH_SOCKET */
       }
       _errno = errno;
       if (writt < 0) {