From 9922641b603ce7d7ec6e1c8dfe7489f5b14f694b Mon Sep 17 00:00:00 2001 From: Gerhard Rieger Date: Fri, 26 Sep 2008 08:12:32 +0200 Subject: [PATCH 1/3] MacOSX port: made defines IPV6_* conditional --- xio-ip6.c | 16 ++++++++++++++++ xioopts.c | 24 ++++++++++++++++++++++++ 2 files changed, 40 insertions(+) diff --git a/xio-ip6.c b/xio-ip6.c index d8ee9bc..9a729f6 100644 --- a/xio-ip6.c +++ b/xio-ip6.c @@ -26,27 +26,41 @@ const struct optdesc opt_ipv6_v6only = { "ipv6-v6only", "ipv6only", OPT_IPV6_V6O const struct optdesc opt_ipv6_join_group = { "ipv6-join-group", "join-group", OPT_IPV6_JOIN_GROUP, GROUP_SOCK_IP6, PH_PASTBIND, TYPE_IP_MREQN, OFUNC_SOCKOPT, SOL_IPV6, IPV6_JOIN_GROUP }; #endif const struct optdesc opt_ipv6_pktinfo = { "ipv6-pktinfo", "pktinfo", OPT_IPV6_PKTINFO, GROUP_SOCK_IP6, PH_PASTSOCKET, TYPE_BOOL, OFUNC_SOCKOPT, SOL_IPV6, IPV6_PKTINFO }; +#ifdef IPV6_RECVPKTINFO const struct optdesc opt_ipv6_recvpktinfo = { "ipv6-recvpktinfo", "recvpktinfo", OPT_IPV6_RECVPKTINFO, GROUP_SOCK_IP6, PH_PASTSOCKET, TYPE_BOOL, OFUNC_SOCKOPT, SOL_IPV6, IPV6_RECVPKTINFO }; +#endif const struct optdesc opt_ipv6_rthdr = { "ipv6-rthdr", "rthdr", OPT_IPV6_RTHDR, GROUP_SOCK_IP6, PH_PASTSOCKET, TYPE_BOOL, OFUNC_SOCKOPT, SOL_IPV6, IPV6_RTHDR }; +#ifdef IPV6_RECVRTHDR const struct optdesc opt_ipv6_recvrthdr = { "ipv6-recvrthdr", "recvrthdr", OPT_IPV6_RECVRTHDR, GROUP_SOCK_IP6, PH_PASTSOCKET, TYPE_BOOL, OFUNC_SOCKOPT, SOL_IPV6, IPV6_RECVRTHDR }; +#endif #ifdef IPV6_AUTHHDR const struct optdesc opt_ipv6_authhdr = { "ipv6-authhdr", "authhdr", OPT_IPV6_AUTHHDR, GROUP_SOCK_IP6, PH_PASTSOCKET, TYPE_BOOL, OFUNC_SOCKOPT, SOL_IPV6, IPV6_AUTHHDR }; #endif const struct optdesc opt_ipv6_dstopts = { "ipv6-dstopts", "dstopts", OPT_IPV6_DSTOPTS, GROUP_SOCK_IP6, PH_PASTSOCKET, TYPE_BOOL, OFUNC_SOCKOPT, SOL_IPV6, IPV6_DSTOPTS }; +#ifdef IPV6_RECVDSTOPTS const struct optdesc opt_ipv6_recvdstopts = { "ipv6-recvdstopts", "recvdstopts", OPT_IPV6_RECVDSTOPTS, GROUP_SOCK_IP6, PH_PASTSOCKET, TYPE_BOOL, OFUNC_SOCKOPT, SOL_IPV6, IPV6_RECVDSTOPTS }; +#endif const struct optdesc opt_ipv6_hopopts = { "ipv6-hopopts", "hopopts", OPT_IPV6_HOPOPTS, GROUP_SOCK_IP6, PH_PASTSOCKET, TYPE_BOOL, OFUNC_SOCKOPT, SOL_IPV6, IPV6_HOPOPTS }; +#ifdef IPV6_RECVHOPOPTS const struct optdesc opt_ipv6_recvhopopts = { "ipv6-recvhopopts", "recvhopopts", OPT_IPV6_RECVHOPOPTS, GROUP_SOCK_IP6, PH_PASTSOCKET, TYPE_BOOL, OFUNC_SOCKOPT, SOL_IPV6, IPV6_RECVHOPOPTS }; +#endif #ifdef IPV6_FLOWINFO /* is in linux/in6.h */ const struct optdesc opt_ipv6_flowinfo= { "ipv6-flowinfo","flowinfo",OPT_IPV6_FLOWINFO,GROUP_SOCK_IP6, PH_PASTSOCKET, TYPE_BOOL, OFUNC_SOCKOPT, SOL_IPV6, IPV6_FLOWINFO }; #endif const struct optdesc opt_ipv6_hoplimit= { "ipv6-hoplimit","hoplimit",OPT_IPV6_HOPLIMIT,GROUP_SOCK_IP6, PH_PASTSOCKET, TYPE_BOOL, OFUNC_SOCKOPT, SOL_IPV6, IPV6_HOPLIMIT }; const struct optdesc opt_ipv6_unicast_hops= { "ipv6-unicast-hops","unicast-hops",OPT_IPV6_UNICAST_HOPS,GROUP_SOCK_IP6, PH_PASTSOCKET, TYPE_INT, OFUNC_SOCKOPT, SOL_IPV6, IPV6_UNICAST_HOPS }; +#ifdef IPV6_RECVHOPLIMIT const struct optdesc opt_ipv6_recvhoplimit= { "ipv6-recvhoplimit","recvhoplimit",OPT_IPV6_RECVHOPLIMIT,GROUP_SOCK_IP6, PH_PASTSOCKET, TYPE_BOOL, OFUNC_SOCKOPT, SOL_IPV6, IPV6_RECVHOPLIMIT }; +#endif #ifdef IPV6_RECVERR const struct optdesc opt_ipv6_recverr = { "ipv6-recverr", "recverr", OPT_IPV6_RECVERR, GROUP_SOCK_IP6, PH_PASTSOCKET, TYPE_BOOL, OFUNC_SOCKOPT, SOL_IPV6, IPV6_RECVERR }; #endif +#ifdef IPV6_TCLASS const struct optdesc opt_ipv6_tclass = { "ipv6-tclass", "tclass", OPT_IPV6_TCLASS, GROUP_SOCK_IP6, PH_PASTSOCKET, TYPE_INT, OFUNC_SOCKOPT, SOL_IPV6, IPV6_TCLASS }; +#endif +#ifdef IPV6_RECVTCLASS const struct optdesc opt_ipv6_recvtclass = { "ipv6-recvtclass", "recvtclass", OPT_IPV6_RECVTCLASS, GROUP_SOCK_IP6, PH_PASTSOCKET, TYPE_BOOL, OFUNC_SOCKOPT, SOL_IPV6, IPV6_RECVTCLASS }; +#endif #ifdef IPV6_RECVPATHMTU const struct optdesc opt_ipv6_recvpathmtu = { "ipv6-recvpathmtu", "recvpathmtu", OPT_IPV6_RECVPATHMTU, GROUP_SOCK_IP6, PH_PASTSOCKET, TYPE_BOOL, OFUNC_SOCKOPT, SOL_IPV6, IPV6_RECVPATHMTU }; #endif @@ -234,11 +248,13 @@ int xiolog_ancillary_ip6(struct cmsghdr *cmsg, int *num, xiodump(CMSG_DATA(cmsg), msglen, valbuff, vallen, 0); return STAT_OK; #endif +#ifdef IPV6_TCLASS case IPV6_TCLASS: strncpy(typbuff, "IPV6_TCLASS", typlen); strncpy(nambuff, "tclass", namlen); xiodump(CMSG_DATA(cmsg), msglen, valbuff, vallen, 0); return STAT_OK; +#endif default: snprintf(typbuff, typlen, "IPV6.%u", cmsg->cmsg_type); strncpy(nambuff, "data", namlen); diff --git a/xioopts.c b/xioopts.c index 9d9e88d..cc69d65 100644 --- a/xioopts.c +++ b/xioopts.c @@ -719,20 +719,34 @@ const struct optname optionnames[] = { IF_IP6 ("ipv6-hopopts", &opt_ipv6_hopopts) IF_IP6 ("ipv6-join-group", &opt_ipv6_join_group) IF_IP6 ("ipv6-pktinfo", &opt_ipv6_pktinfo) +#ifdef IPV6_RECVDSTOPTS IF_IP6 ("ipv6-recvdstopts", &opt_ipv6_recvdstopts) +#endif #ifdef IPV6_RECVERR IF_IP6 ("ipv6-recverr", &opt_ipv6_recverr) #endif +#ifdef IPV6_RECVHOPLIMIT IF_IP6 ("ipv6-recvhoplimit", &opt_ipv6_recvhoplimit) +#endif +#ifdef IPV6_RECVHOPOPTS IF_IP6 ("ipv6-recvhopopts", &opt_ipv6_recvhopopts) +#endif #ifdef IPV6_PATHMTU IF_IP6 ("ipv6-recvpathmtu", &opt_ipv6_recvpathmtu) #endif +#ifdef IPV6_RECVPKTINFO IF_IP6 ("ipv6-recvpktinfo", &opt_ipv6_recvpktinfo) +#endif +#ifdef IPV6_RECVRTHDR IF_IP6 ("ipv6-recvrthdr", &opt_ipv6_recvrthdr) +#endif +#ifdef IPV6_RECVTCLASS IF_IP6 ("ipv6-recvtclass", &opt_ipv6_recvtclass) +#endif IF_IP6 ("ipv6-rthdr", &opt_ipv6_rthdr) +#ifdef IPV6_TCLASS IF_IP6 ("ipv6-tclass", &opt_ipv6_tclass) +#endif IF_IP6 ("ipv6-unicast-hops", &opt_ipv6_unicast_hops) #ifdef IPV6_V6ONLY IF_IP6 ("ipv6-v6only", &opt_ipv6_v6only) @@ -1145,20 +1159,30 @@ const struct optname optionnames[] = { #ifdef IP_RECVDSTADDR IF_IP ("recvdstaddr", &opt_ip_recvdstaddr) #endif +#ifdef IPV6_RECVDSTOPTS IF_IP6 ("recvdstopts", &opt_ipv6_recvdstopts) +#endif #ifdef IP_RECVERR IF_IP ("recverr", &opt_ip_recverr) #endif +#ifdef IPV6_RECVHOPLIMIT IF_IP6 ("recvhoplimit", &opt_ipv6_recvhoplimit) +#endif +#ifdef IPV6_RECVHOPOPTS IF_IP6 ("recvhopopts", &opt_ipv6_recvhopopts) +#endif #ifdef IP_RECVIF IF_IP ("recvif", &opt_ip_recvif) #endif #ifdef IP_RECVOPTS IF_IP ("recvopts", &opt_ip_recvopts) #endif +#ifdef IPV6_RECVPKTINFO IF_IP6 ("recvpktinfo", &opt_ipv6_recvpktinfo) +#endif +#ifdef IPV6_RECVRTHDR IF_IP6 ("recvrthdr", &opt_ipv6_recvrthdr) +#endif #ifdef IP_RECVTOS IF_IP ("recvtos", &opt_ip_recvtos) #endif From 8287a65d1a3785412cf8af44451340a95f3a9cba Mon Sep 17 00:00:00 2001 From: Gerhard Rieger Date: Fri, 26 Sep 2008 08:13:19 +0200 Subject: [PATCH 2/3] MacOSX port: issue error when poll gives POLLNVAL --- socat.c | 27 +++++++++++++++++++++++---- 1 file changed, 23 insertions(+), 4 deletions(-) diff --git a/socat.c b/socat.c index 470ad23..c674a3c 100644 --- a/socat.c +++ b/socat.c @@ -929,17 +929,36 @@ int _socat(void) { } if (XIO_READABLE(sock1) && XIO_GETRDFD(sock1) >= 0 && - (fd1in->revents&(POLLIN|POLLHUP|POLLERR))) { + (fd1in->revents /*&(POLLIN|POLLHUP|POLLERR)*/)) { + if (fd1in->revents & POLLNVAL) { + /* this is what we find on Mac OS X when poll()'ing on a device or + named pipe. a read() might imm. return with 0 bytes, resulting + in a loop? */ + Error1("poll(...[%d]: invalid request", fd1in->fd); + return -1; + } mayrd1 = true; } if (XIO_READABLE(sock2) && XIO_GETRDFD(sock2) >= 0 && - (fd2in->revents&(POLLIN|POLLHUP|POLLERR))) { + (fd2in->revents)) { + if (fd2in->revents & POLLNVAL) { + Error1("poll(...[%d]: invalid request", fd2in->fd); + return -1; + } mayrd2 = true; } - if (XIO_GETWRFD(sock1) >= 0 && (fd1out->revents&(POLLOUT|POLLHUP|POLLERR))) { + if (XIO_GETWRFD(sock1) >= 0 && (fd1out->revents)) { + if (fd1out->revents & POLLNVAL) { + Error1("poll(...[%d]: invalid request", fd1out->fd); + return -1; + } maywr1 = true; } - if (XIO_GETWRFD(sock2) >= 0 && (fd2out->revents&(POLLOUT|POLLHUP|POLLERR))) { + if (XIO_GETWRFD(sock2) >= 0 && (fd2out->revents)) { + if (fd2out->revents & POLLNVAL) { + Error1("poll(...[%d]: invalid request", fd2out->fd); + return -1; + } maywr2 = true; } From 097608e8a98b5d3d8acc13e19501802a0efc3530 Mon Sep 17 00:00:00 2001 From: Gerhard Rieger Date: Fri, 26 Sep 2008 13:19:49 +0200 Subject: [PATCH 3/3] MacOSX port: detect TABDLY shift problem with autoconf --- configure.in | 6 +++++- xio-termios.c | 10 ++++++++-- xioinitialize.c | 6 ++++-- xioopts.c | 6 ++++++ 4 files changed, 23 insertions(+), 5 deletions(-) diff --git a/configure.in b/configure.in index 6488ee8..69ce67c 100644 --- a/configure.in +++ b/configure.in @@ -1227,7 +1227,11 @@ AC_CACHE_CHECK(shift offset of $1, $2, if (n==0) {fprintf(stderr,"$1 is 0 (impossible!)\n"); exit(1);} i=0; while (!(n&1)) { n>>=1; ++i; } - fprintf(f, "%u", i); + if (3<= 0 const struct optdesc opt_crdly = { "crdly", NULL, OPT_CRDLY, GROUP_TERMIOS, PH_FD, TYPE_UINT, OFUNC_TERMIOS_VALUE, 1, CRDLY, CRDLY_SHIFT }; +# endif #endif /* defined(CRDLY) */ #ifdef NLDLY # ifdef NL0 @@ -91,8 +93,10 @@ const struct optdesc opt_tab3 = { "tab3", NULL, OPT_TAB3, GROUP_TERMIOS # ifdef XTABS const struct optdesc opt_xtabs = { "xtabs", NULL, OPT_XTABS, GROUP_TERMIOS, PH_FD, TYPE_CONST, OFUNC_TERMIOS_FLAG, 1, XTABS, TABDLY }; # endif +# if TABDLY_SHIFT >= 0 const struct optdesc opt_tabdly = { "tabdly", NULL, OPT_TABDLY, GROUP_TERMIOS, PH_FD, TYPE_UINT, OFUNC_TERMIOS_VALUE, 1, TABDLY, TABDLY_SHIFT }; -#endif +# endif +#endif /* defined(TABDLY) */ #ifdef BSDLY # ifdef BS0 const struct optdesc opt_bs0 = { "bs0", NULL, OPT_BS0, GROUP_TERMIOS, PH_FD, TYPE_CONST, OFUNC_TERMIOS_PATTERN, 1, BS0, BSDLY }; @@ -197,7 +201,9 @@ const struct optdesc opt_cs5 = { "cs5", NULL, OPT_CS5, GROUP_TERMIOS const struct optdesc opt_cs6 = { "cs6", NULL, OPT_CS6, GROUP_TERMIOS, PH_FD, TYPE_CONST, OFUNC_TERMIOS_PATTERN, 2, CS6, CSIZE }; const struct optdesc opt_cs7 = { "cs7", NULL, OPT_CS7, GROUP_TERMIOS, PH_FD, TYPE_CONST, OFUNC_TERMIOS_PATTERN, 2, CS7, CSIZE }; const struct optdesc opt_cs8 = { "cs8", NULL, OPT_CS8, GROUP_TERMIOS, PH_FD, TYPE_CONST, OFUNC_TERMIOS_PATTERN, 2, CS8, CSIZE }; +#if CSIZE_SHIFT >= 0 const struct optdesc opt_csize = { "csize", NULL, OPT_CSIZE, GROUP_TERMIOS, PH_FD, TYPE_UINT, OFUNC_TERMIOS_VALUE, 2, CSIZE, CSIZE_SHIFT }; +#endif const struct optdesc opt_cstopb = { "cstopb", NULL, OPT_CSTOPB, GROUP_TERMIOS, PH_FD, TYPE_BOOL, OFUNC_TERMIOS_FLAG, 2, CSTOPB }; const struct optdesc opt_cread = { "cread", NULL, OPT_CREAD, GROUP_TERMIOS, PH_FD, TYPE_BOOL, OFUNC_TERMIOS_FLAG, 2, CREAD }; const struct optdesc opt_parenb = { "parenb", NULL, OPT_PARENB, GROUP_TERMIOS, PH_FD, TYPE_BOOL, OFUNC_TERMIOS_FLAG, 2, PARENB }; diff --git a/xioinitialize.c b/xioinitialize.c index d04ad71..15d7d64 100644 --- a/xioinitialize.c +++ b/xioinitialize.c @@ -37,13 +37,15 @@ int xioinitialize(void) { /* some assertions about termios */ #if WITH_TERMIOS -#ifdef CRDLY +#if defined(CRDLY) && CRDLY_SHIFT >= 0 assert(3 << opt_crdly.arg3 == CRDLY); #endif -#ifdef TABDLY +#if defined(TABDLY) && TABDLY_SHIFT >= 0 assert(3 << opt_tabdly.arg3 == TABDLY); #endif +#if CSIZE_SHIFT >= 0 assert(3 << opt_csize.arg3 == CSIZE); +#endif { union { struct termios termarg; diff --git a/xioopts.c b/xioopts.c index cc69d65..259bb45 100644 --- a/xioopts.c +++ b/xioopts.c @@ -316,7 +316,9 @@ const struct optname optionnames[] = { # ifdef CR3 IF_TERMIOS("cr3", &opt_cr3) # endif +# if CRDLY_SHIFT >= 0 IF_TERMIOS("crdly", &opt_crdly) +# endif #endif /* defined(CRDLY) */ IF_TERMIOS("cread", &opt_cread) IF_OPEN ("creat", &opt_o_create) @@ -332,7 +334,9 @@ const struct optname optionnames[] = { IF_TERMIOS("cs6", &opt_cs6) IF_TERMIOS("cs7", &opt_cs7) IF_TERMIOS("cs8", &opt_cs8) +#if CSIZE_SHIFT >= 0 IF_TERMIOS("csize", &opt_csize) +#endif IF_TERMIOS("cstopb", &opt_cstopb) IF_TERMIOS("ctlecho", &opt_echoctl) IF_TERMIOS("ctty", &opt_tiocsctty) @@ -1456,7 +1460,9 @@ const struct optname optionnames[] = { # ifdef TAB3 IF_TERMIOS("tab3", &opt_tab3) # endif +# if TABDLY_SHIFT >= 0 IF_TERMIOS("tabdly", &opt_tabdly) +# endif #endif IF_TERMIOS("tandem", &opt_ixoff) #ifdef TCP_ABORT_THRESHOLD /* HP_UX */