From 1f61e7f8f4df121ca2695870d800f726db4dbb31 Mon Sep 17 00:00:00 2001
From: Daniel Stenberg <daniel@haxx.se>
Date: Tue, 23 Mar 2004 14:43:42 +0000
Subject: [PATCH] If localbind fails, provide a more portable error message.

---
 lib/connect.c | 23 ++++++++++++-----------
 1 file changed, 12 insertions(+), 11 deletions(-)

diff --git a/lib/connect.c b/lib/connect.c
index 1b57e3fec4..adeadb59f4 100644
--- a/lib/connect.c
+++ b/lib/connect.c
@@ -295,10 +295,10 @@ static CURLcode bindlocal(struct connectdata *conn,
       if (setsockopt(sockfd, SOL_SOCKET, SO_BINDTODEVICE,
                      data->set.device, strlen(data->set.device)+1) != 0) {
         /* printf("Failed to BINDTODEVICE, socket: %d  device: %s error: %s\n",
-           sockfd, data->set.device, strerror(errno)); */
+           sockfd, data->set.device, strerror(Curl_ourerrno())); */
         infof(data, "SO_BINDTODEVICE %s failed\n",
               data->set.device);
-        /* This is typiclally "errno 1, error: Operation not permitted" if
+        /* This is typically "errno 1, error: Operation not permitted" if
            you're not running as root or another suitable privileged user */
       }
     }
@@ -353,34 +353,35 @@ static CURLcode bindlocal(struct connectdata *conn,
         }
 #endif
         if(!bindworked) {
+          int err = Curl_ourerrno();
           switch(errno) {
           case EBADF:
-            failf(data, "Invalid descriptor: %d", errno);
+            failf(data, "Invalid descriptor: %d", err);
             break;
           case EINVAL:
-            failf(data, "Invalid request: %d", errno);
+            failf(data, "Invalid request: %d", err);
             break;
           case EACCES:
-            failf(data, "Address is protected, user not superuser: %d", errno);
+            failf(data, "Address is protected, user not superuser: %d", err);
             break;
           case ENOTSOCK:
             failf(data,
                   "Argument is a descriptor for a file, not a socket: %d",
-                  errno);
+                  err);
             break;
           case EFAULT:
-            failf(data, "Inaccessable memory error: %d", errno);
+            failf(data, "Inaccessable memory error: %d", err);
             break;
           case ENAMETOOLONG:
-            failf(data, "Address too long: %d", errno);
+            failf(data, "Address too long: %d", err);
             break;
           case ENOMEM:
-            failf(data, "Insufficient kernel memory was available: %d", errno);
+            failf(data, "Insufficient kernel memory was available: %d", err);
             break;
           default:
-            failf(data, "errno %d", errno);
+            failf(data, "errno %d", err);
             break;
-          } /* end of switch(errno) */
+          } /* end of switch(err) */
 	
           return CURLE_HTTP_PORT_FAILED;
         } /* end of else */
-- 
GitLab