]> git.ipfire.org Git - thirdparty/curl.git/commitdiff
keep 'socktype' in the connectdata struct and make sure we use that for all
authorDaniel Stenberg <daniel@haxx.se>
Fri, 16 Sep 2005 21:30:08 +0000 (21:30 +0000)
committerDaniel Stenberg <daniel@haxx.se>
Fri, 16 Sep 2005 21:30:08 +0000 (21:30 +0000)
protocol sockets even if the resolved address may say otherwise

lib/connect.c
lib/ftp.c
lib/hostip4.c
lib/hostip6.c
lib/hostthre.c
lib/url.c
lib/urldata.h

index 5d9cf65ef9b834fb42e856c0f90b63c20f86295e..23c192c7db762db77f5900f5bed431c3ac1e50f6 100644 (file)
@@ -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();
 
index 4dc72a49690f1175177abfe14edc22f2089947bf..5c797b938d9910689b10ae01c29894489aa3ecd5 100644 (file)
--- a/lib/ftp.c
+++ b/lib/ftp.c
@@ -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) {
index d9277b96035ef4f708f14608b5238006acd8215a..c7bdb6dc9346fb917909075319c4b7d17c2d7428 100644 (file)
@@ -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
index 4624e00b851773c03941aabf755184a668c5e396..be86a513682668840ea1beed81d399d1ec22d6d9 100644 (file)
@@ -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);
index 6b358882f8d80d35715e37aff3c451cc25e47667..a1204cf9cbea295b4157275edd3f5b25604cbc83 100644 (file)
@@ -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);
 
index c256cf23f4904519186300084aca5cac438b0262..f84ee37345d328d622c9eec0a8feb9f80ae1a8bd 100644 (file)
--- a/lib/url.c
+++ b/lib/url.c
@@ -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=");
index ff0b23a54a7d82aab91bc70347067360d2348805..87a751f6fd299c2403005238780b9ee43a7ce699 100644 (file)
@@ -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;