bug: --interface does not consume argument #2104

ciofeca opened this Issue Nov 21, 2017 · 3 comments


None yet
4 participants

ciofeca commented Nov 21, 2017

If the argument of --interface is not a valid interface, it should abort with an error.

I did this (on a system without any eth8 network interface):

curl --interface eth8

I expected the following:

"Error: eth8 does not exist"

I instead got this:

"curl: (45) Could not resolve host: eth8"

curl/libcurl version

curl 7.55.1 (x86_64-pc-linux-gnu) libcurl/7.55.1 OpenSSL/1.0.2g zlib/1.2.11 libidn2/2.0.2 libpsl/0.18.0 (+libidn2/2.0.2) librtmp/2.3
Release-Date: 2017-08-14
Protocols: dict file ftp ftps gopher http https imap imaps ldap ldaps pop3 pop3s rtmp rtsp smb smbs smtp smtps telnet tftp
Features: AsynchDNS IDN IPv6 Largefile GSS-API Kerberos SPNEGO NTLM NTLM_WB SSL libz TLS-SRP UnixSockets HTTPS-proxy PSL

operating system

Ubuntu 17.04


jay commented Nov 22, 2017

It does consume the argument:

"curl: (45) Could not resolve host: eth8"

Error code 45 is CURLE_INTERFACE_FAILED so that is the correct error code. The message
is because if the argument is not an interface then it falls back to treating it as host or ip.


Lines 335 to 343 in c514af5

if(!is_interface) {
* This was not an interface, resolve the name as a host name
* or IP number
* Temporarily force name resolution to use only the address type
* of the connection. The resolve functions should really be changed
* to take a type parameter instead.

If you turn on verbose you should see * Couldn't bind to 'eth8'

edit: we could make that bind error message what is shown by overwriting the generic resolve error that takes precedence

diff --git a/lib/connect.c b/lib/connect.c
index 16104bc..45e18bc 100644
--- a/lib/connect.c
+++ b/lib/connect.c
@@ -412,6 +412,10 @@ static CURLcode bindlocal(struct connectdata *conn,
     if(done < 1) {
+      /* errorbuf is set false so failf will overwrite any message already in
+         the error buffer, so the user receives this error message instead of a
+         generic resolve error. */
+      data->state.errorbuf = FALSE;
       failf(data, "Couldn't bind to '%s'", dev);

mkauf commented Nov 22, 2017

You get a better error message if you add the prefix "if!" to the interface name. This tells curl that it's really an interface. For more information, please see CURLOPT_INTERFACE.


$ curl --interface 'if!eth8'
curl: (45) Couldn't bind to interface 'eth8'

@bagder bagder added the not-a-bug label Nov 23, 2017


bagder commented Nov 23, 2017

@jay: sounds like a neat improvement

I see no bug or actual issue here. I'm closing...

@bagder bagder closed this Nov 23, 2017

jay added a commit that referenced this issue Nov 23, 2017

connect: improve the bind error message
eg consider a non-existent interface eth8, curl --interface eth8

Before: curl: (45) Could not resolve host: eth8
After: curl: (45) Couldn't bind to 'eth8'

Bug: #2104
Reported-by: Alfonso Martone
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment