diff options
-rw-r--r-- | lib/connect.c | 12 | ||||
-rw-r--r-- | lib/ftp.c | 2 | ||||
-rw-r--r-- | lib/hostip4.c | 8 | ||||
-rw-r--r-- | lib/hostip6.c | 5 | ||||
-rw-r--r-- | lib/hostthre.c | 10 | ||||
-rw-r--r-- | lib/url.c | 5 | ||||
-rw-r--r-- | lib/urldata.h | 1 |
7 files changed, 22 insertions, 21 deletions
diff --git a/lib/connect.c b/lib/connect.c index 5d9cf65ef..23c192c7d 100644 --- a/lib/connect.c +++ b/lib/connect.c @@ -631,8 +631,9 @@ singleipconnect(struct connectdata *conn, int error; bool conected; struct SessionHandle *data = conn->data; - curl_socket_t sockfd = socket(ai->ai_family, ai->ai_socktype, - ai->ai_protocol); + curl_socket_t sockfd; + + sockfd = socket(ai->ai_family, conn->socktype, ai->ai_protocol); if (sockfd == CURL_SOCKET_BAD) return CURL_SOCKET_BAD; @@ -661,12 +662,11 @@ singleipconnect(struct connectdata *conn, Curl_nonblock(sockfd, TRUE); /* Connect TCP sockets, bind UDP */ - if(ai->ai_socktype==SOCK_STREAM) { + if(conn->socktype == SOCK_STREAM) rc = connect(sockfd, ai->ai_addr, (socklen_t)ai->ai_addrlen); - } else { + else rc = 0; - } - + if(-1 == rc) { error = Curl_ourerrno(); @@ -858,7 +858,7 @@ static CURLcode ftp_state_use_port(struct connectdata *conn, * Workaround for AIX5 getaddrinfo() problem (it doesn't set ai_socktype): */ if (ai->ai_socktype == 0) - ai->ai_socktype = SOCK_STREAM; + ai->ai_socktype = conn->socktype; portsock = socket(ai->ai_family, ai->ai_socktype, ai->ai_protocol); if (portsock == CURL_SOCKET_BAD) { diff --git a/lib/hostip4.c b/lib/hostip4.c index d9277b960..c7bdb6dc9 100644 --- a/lib/hostip4.c +++ b/lib/hostip4.c @@ -423,10 +423,10 @@ Curl_addrinfo *Curl_he2ai(struct hostent *he, int port) prevai->ai_next = ai; ai->ai_family = AF_INET; /* we only support this */ - if(port == PORT_TFTP) - ai->ai_socktype = SOCK_DGRAM; - else - ai->ai_socktype = SOCK_STREAM; + + /* we return all names as STREAM, so when using this address for TFTP + the type must be ignored and conn->socktype be used instead! */ + ai->ai_socktype = SOCK_STREAM; ai->ai_addrlen = sizeof(struct sockaddr_in); /* make the ai_addr point to the address immediately following this struct diff --git a/lib/hostip6.c b/lib/hostip6.c index 4624e00b8..be86a5136 100644 --- a/lib/hostip6.c +++ b/lib/hostip6.c @@ -252,10 +252,7 @@ Curl_addrinfo *Curl_getaddrinfo(struct connectdata *conn, memset(&hints, 0, sizeof(hints)); hints.ai_family = pf; - if(conn->protocol & PROT_TFTP) - hints.ai_socktype = SOCK_DGRAM; - else - hints.ai_socktype = SOCK_STREAM; + hints.ai_socktype = conn->socktype; hints.ai_flags = ai_flags; snprintf(sbuf, sizeof(sbuf), "%d", port); diff --git a/lib/hostthre.c b/lib/hostthre.c index 6b358882f..a1204cf9c 100644 --- a/lib/hostthre.c +++ b/lib/hostthre.c @@ -559,7 +559,10 @@ static bool init_resolve_thread (struct connectdata *conn, */ thread_and_event[0] = td->thread_hnd; thread_and_event[1] = td->event_thread_started; - if (WaitForMultipleObjects(sizeof(thread_and_event) / sizeof(thread_and_event[0]), thread_and_event, FALSE, INFINITE) == WAIT_FAILED) { + if (WaitForMultipleObjects(sizeof(thread_and_event) / + sizeof(thread_and_event[0]), + thread_and_event, FALSE, + INFINITE) == WAIT_FAILED) { /* The resolver thread has been created, * most probably it works now - ignoring this "minor" error */ @@ -804,10 +807,7 @@ Curl_addrinfo *Curl_getaddrinfo(struct connectdata *conn, memset(&hints, 0, sizeof(hints)); hints.ai_family = pf; - if(conn->protocol & PROT_TFTP) - hints.ai_socktype = SOCK_DGRAM; - else - hints.ai_socktype = SOCK_STREAM; + hints.ai_socktype = conn->socktype; hints.ai_flags = AI_CANONNAME; itoa(port, sbuf, 10); @@ -2729,6 +2729,8 @@ static CURLcode CreateConnection(struct SessionHandle *data, * Setup internals depending on protocol *************************************************************/ + conn->socktype = SOCK_STREAM; /* most of them are TCP streams */ + if (strequal(conn->protostr, "HTTP")) { #ifndef CURL_DISABLE_HTTP conn->port = PORT_HTTP; @@ -2927,12 +2929,13 @@ static CURLcode CreateConnection(struct SessionHandle *data, else if (strequal(conn->protostr, "TFTP")) { #ifndef CURL_DISABLE_TFTP char *type; + conn->socktype = SOCK_DGRAM; /* UDP datagram based */ conn->protocol |= PROT_TFTP; conn->port = PORT_TFTP; conn->remote_port = PORT_TFTP; conn->curl_connect = Curl_tftp_connect; conn->curl_do = Curl_tftp; - conn->curl_done = Curl_tftp_done; + conn->curl_done = Curl_tftp_done; /* TFTP URLs support an extension like ";mode=<typecode>" that * we'll try to get now! */ type=strstr(conn->path, ";mode="); diff --git a/lib/urldata.h b/lib/urldata.h index ff0b23a54..87a751f6f 100644 --- a/lib/urldata.h +++ b/lib/urldata.h @@ -562,6 +562,7 @@ struct connectdata { char *ip_addr_str; char protostr[16]; /* store the protocol string in this buffer */ + int socktype; /* SOCK_STREAM or SOCK_DGRAM */ struct hostname host; struct hostname proxy; |