Menu

#984 TFTP GET works with IP addr but not with resolvable hostname

closed-fixed
TFTP (14)
5
2013-06-21
2011-01-10
dperham
No

TFTP GET works when using an IP address but not when using a resolvable (confirmed) hostname

Version: curl 7.21.3 (armv5-unknown-linux-gnu) libcurl/7.21.3 OpenSSL/0.9.7e zlib/1.2.1.1
Protocols: dict file ftp ftps gopher http https imap imaps pop3 pop3s rtsp smtp smtps telnet tftp
Features: Largefile NTLM SSL libz

The problem is this, ALTHOUGH tftp.c sets the "conn->socktype" explicitly to SOCK_DGRAM anticipating a UDP connection, hostip4.c[Curl_ipv4_resolve_r()] explicitly sets the hints.ai_socktype to SOCK_STREAM and passes that to Curl_getaddrinfo_ex() which results in the Curl_addrinfo->ai_protocol = IPPROTO_TCP. When connect.c[singleipconnect()) trys to create a socket it fails because ai_socktype is SOCK_DGRAM, but ai_protoco is IPPROTO_TCP.

I guess it worked when using an IP address because it doesn't go through all of the resolver stuff and so ai_protocol didn't get set to IPPROTO_TCP and remained IPPROTO_IP (which is '0')

This problem may be specific to the arm or the ancient montavista toolchain that I'm using to compile -- however, I've seen references that others have had this problem.

this patch fixed my problem:

*** connect.c 4 Jan 2011 21:38:42 -0000 1.1
--- connect.c 10 Jan 2011 16:23:57 -0000 1.2
***************
*** 1055,1060 ****
--- 1055,1063 ----
for (curr_addr = ai, aliasindex=0; curr_addr;
curr_addr = curr_addr->ai_next, aliasindex++) {

+ if( conn->socktype == SOCK_DGRAM
+ && curr_addr->ai_protocol == IPPROTO_TCP )
+ curr_addr->ai_protocol = IPPROTO_UDP;
/* start connecting to the IP curr_addr points to */
CURLcode res =
singleipconnect(conn, curr_addr, timeout_per_addr, &sockfd, connected);

Discussion

  • Daniel Stenberg

    Daniel Stenberg - 2011-01-10

    Thanks, I could repeat this problem and I fixed it slightly differently in the git repo just now.

     
  • Daniel Stenberg

    Daniel Stenberg - 2011-01-10
    • status: open --> closed-fixed
     
Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.