29 #ifdef HAVE_SYS_TYPES_H
30 #include <sys/types.h>
32 #ifdef HAVE_SYS_SOCKET_H
33 #include <sys/socket.h>
35 #include <sys/ioctl.h>
45 #ifdef HAVE_NETINET_IN_H
46 #include <netinet/in.h>
48 #ifdef HAVE_ARPA_INET_H
49 #include <arpa/inet.h>
55 #if (defined(HAVE_FIONBIO) && defined(__NOVELL_LIBC__))
56 #include <sys/filio.h>
58 #if (defined(NETWARE) && defined(__NOVELL_LIBC__))
60 #define in_addr_t unsigned long
79 #define EINPROGRESS WSAEINPROGRESS
80 #define EWOULDBLOCK WSAEWOULDBLOCK
81 #define EISCONN WSAEISCONN
82 #define ENOTSOCK WSAENOTSOCK
83 #define ECONNREFUSED WSAECONNREFUSED
101 return (
int)GetLastError();
118 #ifdef HAVE_O_NONBLOCK
122 flags = fcntl(sockfd, F_GETFL, 0);
123 if (
TRUE == nonblock)
124 return fcntl(sockfd, F_SETFL, flags | O_NONBLOCK);
126 return fcntl(sockfd, F_SETFL, flags & (~O_NONBLOCK));
135 return ioctl(sockfd, FIONBIO, &flags);
139 #ifdef HAVE_IOCTLSOCKET
143 return ioctlsocket(sockfd, FIONBIO, &flags);
147 #ifdef HAVE_IOCTLSOCKET_CASE
149 return IoctlSocket(sockfd, FIONBIO, (
long)nonblock);
153 #ifdef HAVE_SO_NONBLOCK
155 long b = nonblock ? 1 : 0;
156 return setsockopt(sockfd, SOL_SOCKET, SO_NONBLOCK, &b,
sizeof(b));
160 #ifdef HAVE_DISABLED_NONBLOCKING
166 #error "no non-blocking method was found/used/set"
189 verifyconnect(sockfd);
197 FD_SET(sockfd, &errfd);
199 interval.tv_sec = timeout_msec/1000;
200 timeout_msec -= interval.tv_sec*1000;
202 interval.tv_usec = timeout_msec*1000;
204 rc =
select(sockfd+1,
NULL, &fd, &errfd, &interval);
213 if(FD_ISSET(sockfd, &errfd))
224 #ifdef HAVE_INET_NTOA
225 bool bindworked =
FALSE;
234 char myhost[256] =
"";
237 bool was_iface =
FALSE;
280 infof(data,
"We bind local end to %s\n", myhost);
282 #ifdef SO_BINDTODEVICE
295 if (setsockopt(sockfd, SOL_SOCKET, SO_BINDTODEVICE,
299 infof(data,
"SO_BINDTODEVICE %s failed\n",
307 in=inet_addr(myhost);
317 if( bind(sockfd, addr->ai_addr, addr->ai_addrlen) >= 0) {
319 struct sockaddr_in6 add;
324 if(getsockname(sockfd, (
struct sockaddr *) &add,
326 failf(data,
"getsockname() failed");
332 struct sockaddr_in sa;
334 memset((
char *)&sa, 0,
sizeof(sa));
335 memcpy((
char *)&sa.sin_addr, addr->h_addr, addr->h_length);
336 sa.sin_family = AF_INET;
337 sa.sin_addr.s_addr =
in;
340 if( bind(sockfd, (
struct sockaddr *)&sa,
sizeof(sa)) >= 0) {
342 struct sockaddr_in add;
347 if(getsockname(sockfd, (
struct sockaddr *) &add,
349 failf(data,
"getsockname() failed");
358 failf(data,
"Invalid descriptor: %d", errno);
361 failf(data,
"Invalid request: %d", errno);
364 failf(data,
"Address is protected, user not superuser: %d", errno);
368 "Argument is a descriptor for a file, not a socket: %d",
372 failf(data,
"Inaccessable memory error: %d", errno);
375 failf(data,
"Address too long: %d", errno);
378 failf(data,
"Insufficient kernel memory was available: %d", errno);
381 failf(data,
"errno %d", errno);
390 failf(data,
"could't find my own IP address (%s)", myhost);
396 failf(data,
"could't find my own IP address (%s)", myhost);
413 #if defined(SO_ERROR) && !defined(WIN32)
416 if( -1 == getsockopt(sockfd, SOL_SOCKET, SO_ERROR,
417 (
void *)&err, &errSize))
420 if ((0 == err) || (EISCONN ==
err))
464 if(has_passed > 0 ) {
466 failf(data,
"Connection time-out");
477 rc = waitconnect(sockfd, 0);
480 if (verifyconnect(sockfd)) {
486 failf(data,
"Connection failed");
491 failf(data,
"Failed connect to %s:%d, errno: %d",
536 long timeout_ms=300000;
547 #define min(a, b) ((a) < (b) ? (a) : (b))
563 timeout_ms -= (long)has_passed;
567 failf(data,
"Connection time-out");
573 infof(data,
"About to connect() to %s port %d\n",
580 for (ai = remotehost->
addr; ai; ai = ai->ai_next, aliasindex++) {
581 sockfd = socket(ai->ai_family, ai->ai_socktype, ai->ai_protocol);
591 for(rc=-1, aliasindex=0;
592 rc && (
struct in_addr *)remotehost->
addr->h_addr_list[aliasindex];
594 struct sockaddr_in serv_addr;
597 sockfd = socket(AF_INET, SOCK_STREAM, 0);
599 failf(data,
"couldn't create socket");
604 memset((
char *) &serv_addr,
'\0',
sizeof(serv_addr));
605 memcpy((
char *)&(serv_addr.sin_addr),
606 (
struct in_addr *)remotehost->
addr->h_addr_list[aliasindex],
607 sizeof(
struct in_addr));
608 serv_addr.sin_family = remotehost->
addr->h_addrtype;
609 serv_addr.sin_port = htons((
unsigned short)port);
627 rc = connect(sockfd, ai->ai_addr, ai->ai_addrlen);
629 rc = connect(sockfd, (
struct sockaddr *)&serv_addr,
sizeof(serv_addr));
638 #if defined(EAGAIN) && EAGAIN != EWOULDBLOCK
650 rc = waitconnect(sockfd, timeout_ms);
654 failf(data,
"Failed to connect to %s IP number %d: %d",
655 hostname, aliasindex+1, error);
670 if (verifyconnect(sockfd)) {
687 failf(data,
"connect() timed out!");
695 failf(data,
"Connect failed");
706 *addr = (
struct in_addr *)remotehost->
addr->h_addr_list[aliasindex];
enum UrlState::@12 used_interface
int Curl_resolv(struct connectdata *conn, char *hostname, int port, struct Curl_dns_entry **entry)
struct DynamicStatic change
struct in_addr Curl_ipconnect
CURLcode Curl_is_connected(struct connectdata *conn, curl_socket_t sockfd, bool *connected)
int Curl_nonblock(curl_socket_t sockfd, int nonblock)
#define ioctl(a, b, c, d)
void Curl_resolv_unlock(struct SessionHandle *data, struct Curl_dns_entry *dns)
GLsizei GLsizei GLenum GLenum const GLvoid * data
long Curl_tvdiff(struct timeval newer, struct timeval older)
GLenum const GLvoid * addr
struct SessionHandle * data
char * Curl_if2ip(char *interface, char *buf, int buf_size)
static WindowRef ValidModeCallbackProc inCallback OSStatus err
CURLcode Curl_connecthost(struct connectdata *conn, struct Curl_dns_entry *remotehost, int port, curl_socket_t *sockconn, Curl_ipconnect **addr, bool *connected)
CURLcode Curl_wait_for_resolv(struct connectdata *conn, struct Curl_dns_entry **entry)
typedef void(APIENTRYP PFNGLBLENDCOLORPROC)(GLclampf red
struct timeval Curl_tvnow(void)
struct hostent Curl_addrinfo