-int nbio_sock_error(int sock)
- {
- int j,i;
- int size;
-
- size=sizeof(int);
- /* Note: under VMS with SOCKETSHR the third parameter is currently
- * of type (int *) whereas under other systems it is (void *) if
- * you don't have a cast it will choke the compiler: if you do
- * have a cast then you can either go for (int *) or (void *).
- */
- i=getsockopt(sock,SOL_SOCKET,SO_ERROR,(char *)&j,(void *)&size);
- if (i < 0)
- return(1);
- else
- return(j);
- }
-
-int nbio_init_client_ip(int *sock, unsigned char ip[4], int port)
- {
- unsigned long addr;
- struct sockaddr_in them;
- int s,i;
-
- if (!sock_init()) return(0);
-
- memset((char *)&them,0,sizeof(them));
- them.sin_family=AF_INET;
- them.sin_port=htons((unsigned short)port);
- addr= (unsigned long)
- ((unsigned long)ip[0]<<24L)|
- ((unsigned long)ip[1]<<16L)|
- ((unsigned long)ip[2]<< 8L)|
- ((unsigned long)ip[3]);
- them.sin_addr.s_addr=htonl(addr);
-
- if (*sock <= 0)
- {
-#ifdef FIONBIO
- unsigned long l=1;
-#endif
-
- s=socket(AF_INET,SOCK_STREAM,SOCKET_PROTOCOL);
- if (s == INVALID_SOCKET) { perror("socket"); return(0); }
-
- i=0;
- i=setsockopt(s,SOL_SOCKET,SO_KEEPALIVE,(char *)&i,sizeof(i));
- if (i < 0) { perror("keepalive"); return(0); }
- *sock=s;
-
-#ifdef FIONBIO
- BIO_socket_ioctl(s,FIONBIO,&l);
-#endif
- }
- else
- s= *sock;
-
- i=connect(s,(struct sockaddr *)&them,sizeof(them));
- if (i == INVALID_SOCKET)
- {
- if (BIO_sock_should_retry(i))
- return(-1);
- else
- return(0);
- }
- else
- return(1);
- }
-