X-Git-Url: http://git.indexdata.com/?a=blobdiff_plain;f=src%2Ftcpip.c;h=416b707cb6b529375d782297174b7b83199768eb;hb=c6b8edd2312a4606cc014738266059a20e3b6e61;hp=97461da343bdc8c7d0e029e02584a92601b6fb27;hpb=5fedb171148c114f2488f5bff941942226b31eef;p=yaz-moved-to-github.git diff --git a/src/tcpip.c b/src/tcpip.c index 97461da..416b707 100644 --- a/src/tcpip.c +++ b/src/tcpip.c @@ -434,14 +434,31 @@ void *tcpip_straddr(COMSTACK h, const char *str) if (sp->ai && h->state == CS_ST_UNBND) { int s = -1; - struct addrinfo *ai = sp->ai; - for (; ai; ai = ai->ai_next) + struct addrinfo *ai; + /* try to make IPV6 socket first */ + for (ai = sp->ai; ai; ai = ai->ai_next) { - s = socket(ai->ai_family, ai->ai_socktype, ai->ai_protocol); - if (s != -1) + if (ai->ai_family == AF_INET6) { - sp->ai = ai; - break; + s = socket(ai->ai_family, ai->ai_socktype, ai->ai_protocol); + if (s != -1) + { + sp->ai = ai; + break; + } + } + } + if (s == -1) + { + /* no IPV6 could be made.. Try them all */ + for (ai = sp->ai; ai; ai = ai->ai_next) + { + s = socket(ai->ai_family, ai->ai_socktype, ai->ai_protocol); + if (s != -1) + { + sp->ai = ai; + break; + } } } if (s == -1) @@ -610,8 +627,10 @@ int tcpip_rcvconnect(COMSTACK h) gnutls_credentials_set (sp->session, GNUTLS_CRD_CERTIFICATE, sp->cred_ptr->xcred); - gnutls_transport_set_ptr(sp->session, (gnutls_transport_ptr_t) h->iofile); - + /* cast to intermediate size_t to avoid GCC warning. */ + gnutls_transport_set_ptr(sp->session, + (gnutls_transport_ptr_t) + (size_t) h->iofile); res = gnutls_handshake(sp->session); if (res < 0) { @@ -965,8 +984,10 @@ COMSTACK tcpip_accept(COMSTACK h) xfree(state); return 0; } + /* cast to intermediate size_t to avoid GCC warning. */ gnutls_transport_set_ptr(state->session, - (gnutls_transport_ptr_t) cnew->iofile); + (gnutls_transport_ptr_t) + (size_t) cnew->iofile); } #elif HAVE_OPENSSL_SSL_H state->ctx = st->ctx; @@ -1050,8 +1071,8 @@ int tcpip_get(COMSTACK h, char **buf, int *bufsize) TRC(fprintf(stderr, "tcpip_get: bufsize=%d\n", *bufsize)); if (sp->altlen) /* switch buffers */ { - TRC(fprintf(stderr, " %d bytes in altbuf (0x%x)\n", sp->altlen, - (unsigned) sp->altbuf)); + TRC(fprintf(stderr, " %d bytes in altbuf (%p)\n", sp->altlen, + sp->altbuf)); tmpc = *buf; tmpi = *bufsize; *buf = sp->altbuf; @@ -1156,8 +1177,8 @@ int tcpip_get(COMSTACK h, char **buf, int *bufsize) h->cerrno = CSYSERR; return -1; } - TRC(fprintf(stderr, " Moving %d bytes to altbuf(0x%x)\n", tomove, - (unsigned) sp->altbuf)); + TRC(fprintf(stderr, " Moving %d bytes to altbuf(%p)\n", tomove, + sp->altbuf)); memcpy(sp->altbuf, *buf + berlen, sp->altlen = tomove); } if (berlen < CS_TCPIP_BUFCHUNK - 1) @@ -1181,8 +1202,8 @@ int ssl_get(COMSTACK h, char **buf, int *bufsize) TRC(fprintf(stderr, "ssl_get: bufsize=%d\n", *bufsize)); if (sp->altlen) /* switch buffers */ { - TRC(fprintf(stderr, " %d bytes in altbuf (0x%x)\n", sp->altlen, - (unsigned) sp->altbuf)); + TRC(fprintf(stderr, " %d bytes in altbuf (%p)\n", sp->altlen, + sp->altbuf)); tmpc = *buf; tmpi = *bufsize; *buf = sp->altbuf; @@ -1240,8 +1261,8 @@ int ssl_get(COMSTACK h, char **buf, int *bufsize) } else if (sp->altsize < req) if (!(sp->altbuf =(char *)xrealloc(sp->altbuf, sp->altsize = req))) return -1; - TRC(fprintf(stderr, " Moving %d bytes to altbuf(0x%x)\n", tomove, - (unsigned) sp->altbuf)); + TRC(fprintf(stderr, " Moving %d bytes to altbuf(%p)\n", tomove, + sp->altbuf)); memcpy(sp->altbuf, *buf + berlen, sp->altlen = tomove); } if (berlen < CS_TCPIP_BUFCHUNK - 1)