diff options
author | Daniel Stenberg <daniel@haxx.se> | 2003-01-23 05:38:20 +0000 |
---|---|---|
committer | Daniel Stenberg <daniel@haxx.se> | 2003-01-23 05:38:20 +0000 |
commit | a6c395c156a5d399edea10bb8731ea49226e7932 (patch) | |
tree | dc4f32fda6aec70835fc11e1b0239338919f440d /lib | |
parent | 543e0b1e0f3a9ff856009514279ca7c4bcd2c2e4 (diff) |
Duncan Wilcox reported a crash with --interface on FreeBSD when ipv6-enabled
and this has been verified to correct the problem.
Diffstat (limited to 'lib')
-rw-r--r-- | lib/connect.c | 18 |
1 files changed, 14 insertions, 4 deletions
diff --git a/lib/connect.c b/lib/connect.c index 05201bab4..884425326 100644 --- a/lib/connect.c +++ b/lib/connect.c @@ -251,14 +251,23 @@ static CURLcode bindlocal(struct connectdata *conn, Curl_resolv_unlock(h); /* we don't need it anymore after this function has returned */ - memset((char *)&sa, 0, sizeof(sa)); #ifdef ENABLE_IPV6 - memcpy((char *)&sa.sin_addr, addr->ai_addr, addr->ai_addrlen); - sa.sin_family = addr->ai_family; + (void)sa; /* prevent compiler warning */ + if( bind(sockfd, addr->ai_addr, addr->ai_addrlen) >= 0) { + /* we succeeded to bind */ + struct sockaddr_in6 add; + + size = sizeof(add); + if(getsockname(sockfd, (struct sockaddr *) &add, + (socklen_t *)&size)<0) { + failf(data, "getsockname() failed"); + return CURLE_HTTP_PORT_FAILED; + } + } #else + memset((char *)&sa, 0, sizeof(sa)); memcpy((char *)&sa.sin_addr, addr->h_addr, addr->h_length); sa.sin_family = AF_INET; -#endif sa.sin_addr.s_addr = in; sa.sin_port = 0; /* get any port */ @@ -273,6 +282,7 @@ static CURLcode bindlocal(struct connectdata *conn, return CURLE_HTTP_PORT_FAILED; } } +#endif else { switch(errno) { case EBADF: |