{
tcpip_state *sp = (tcpip_state *)h->cprivate;
const char *port = "210";
+ struct addrinfo *ai;
if (h->protocol == PROTO_HTTP)
port = "80";
if (!tcpip_init())
if (sp->ai && h->state == CS_ST_UNBND)
{
int s = -1;
- 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)
- {
- sp->ai = ai;
break;
- }
}
}
if (s == -1)
{
s = socket(ai->ai_family, ai->ai_socktype, ai->ai_protocol);
if (s != -1)
- {
- sp->ai = ai;
break;
- }
}
}
if (s == -1)
return 0;
+ assert(ai);
h->iofile = s;
if (!tcpip_set_blocking(h, h->flags))
return 0;
}
- return sp->ai;
+ return ai;
}
#else
void *tcpip_straddr(COMSTACK h, const char *str)
int tcpip_connect(COMSTACK h, void *address)
{
#if HAVE_GETADDRINFO
+ struct addrinfo *ai = (struct addrinfo *) address;
tcpip_state *sp = (tcpip_state *)h->cprivate;
#else
struct sockaddr_in *add = (struct sockaddr_in *) address;
h->cerrno = CSOUTSTATE;
return -1;
}
-#if HAVE_GETADDRINFO
- if (sp->ai != (struct addrinfo *) address)
- {
- h->cerrno = CSOUTSTATE;
- return -1;
- }
-#endif
#ifdef __sun__
/* On Suns, you must set a bigger Receive Buffer BEFORE a call to connect
* This gives the connect a chance to negotiate with the other side
#endif
#if HAVE_GETADDRINFO
- r = connect(h->iofile, sp->ai->ai_addr, sp->ai->ai_addrlen);
+ r = connect(h->iofile, ai->ai_addr, ai->ai_addrlen);
freeaddrinfo(sp->ai);
sp->ai = 0;
#else
{
int r;
tcpip_state *sp = (tcpip_state *)h->cprivate;
-#if HAVE_GETADDRINFO
+#if HAVE_GETADDRINFO
+ struct addrinfo *ai = (struct addrinfo *) address;
#else
struct sockaddr *addr = (struct sockaddr *)address;
#endif
int one = 1;
#endif
-#if HAVE_GETADDRINFO
- if (sp->ai != (struct addrinfo *) address)
- {
- h->cerrno = CSOUTSTATE;
- return -1;
- }
-#endif
-
#if HAVE_GNUTLS_H
if (h->type == ssl_type && !sp->session)
{
#endif
tcpip_setsockopt(h->iofile);
#if HAVE_GETADDRINFO
- r = bind(h->iofile, sp->ai->ai_addr, sp->ai->ai_addrlen);
+ r = bind(h->iofile, ai->ai_addr, ai->ai_addrlen);
freeaddrinfo(sp->ai);
sp->ai = 0;
#else