65 #if defined(OPENSSL_SYS_NETWARE) && defined(NETWARE_BSDSOCK)
67 #if defined(NETWARE_CLIB)
68 #include <sys/ioctl.h>
73 #ifndef OPENSSL_NO_SOCK
77 #define SOCKET_PROTOCOL IPPROTO_TCP
80 #define MAX_LISTEN SO_MAXCONN
81 #elif defined(SOMAXCONN)
82 #define MAX_LISTEN SOMAXCONN
87 #if defined(OPENSSL_SYS_WINDOWS) || (defined(OPENSSL_SYS_NETWARE) && !defined(NETWARE_BSDSOCK))
88 static int wsa_init_done=0;
103 static unsigned long BIO_ghbn_hits=0L;
104 static unsigned long BIO_ghbn_miss=0L;
107 static struct ghbn_cache_st
115 static int get_ip(
const char *str,
unsigned char *ip);
117 static void ghbn_free(
struct hostent *
a);
118 static struct hostent *ghbn_dup(
struct hostent *
a);
141 if (i > 0)
return(1);
154 if ((
short)he->h_addrtype != AF_INET)
160 ip[i]=he->h_addr_list[0][i];
187 *port_ptr=(
unsigned short)i;
195 s=getservbyname((
char *)str,
"tcp");
197 s=getservbyname(str,
"tcp");
200 *port_ptr=ntohs((
unsigned short)s->s_port);
204 if (strcmp(str,
"http") == 0)
206 else if (strcmp(str,
"telnet") == 0)
208 else if (strcmp(str,
"socks") == 0)
210 else if (strcmp(str,
"https") == 0)
212 else if (strcmp(str,
"ssl") == 0)
214 else if (strcmp(str,
"ftp") == 0)
216 else if (strcmp(str,
"gopher") == 0)
219 else if (strcmp(str,
"wais") == 0)
238 #if defined(OPENSSL_SYS_BEOS_R5)
248 i=getsockopt(sock,SOL_SOCKET,SO_ERROR,(
void *)&j,(
void *)&size);
256 long BIO_ghbn_ctrl(
int cmd,
int iarg,
char *parg)
264 return(BIO_ghbn_hits);
267 return(BIO_ghbn_miss);
273 if ((iarg >= 0) && (iarg <
GHBN_NUM) &&
274 (ghbn_cache[iarg].order > 0))
277 if (p == NULL)
return(0);
278 *p=ghbn_cache[iarg].name;
279 ghbn_cache[iarg].name[128]=
'\0';
286 ghbn_cache[i].order=0;
296 static struct hostent *ghbn_dup(
struct hostent *
a)
303 if (ret == NULL)
return(NULL);
304 memset(ret,0,
sizeof(
struct hostent));
306 for (i=0; a->h_aliases[i] != NULL; i++)
310 if (ret->h_aliases == NULL)
312 memset(ret->h_aliases, 0, i*
sizeof(
char *));
314 for (i=0; a->h_addr_list[i] != NULL; i++)
318 if (ret->h_addr_list == NULL)
320 memset(ret->h_addr_list, 0, i*
sizeof(
char *));
322 j=strlen(a->h_name)+1;
324 memcpy((
char *)ret->h_name,a->h_name,j);
325 for (i=0; a->h_aliases[i] != NULL; i++)
327 j=strlen(a->h_aliases[i])+1;
329 memcpy(ret->h_aliases[i],a->h_aliases[i],j);
331 ret->h_length=a->h_length;
332 ret->h_addrtype=a->h_addrtype;
333 for (i=0; a->h_addr_list[i] != NULL; i++)
337 memcpy(ret->h_addr_list[i],a->h_addr_list[i],a->h_length);
350 static void ghbn_free(
struct hostent *a)
357 if (a->h_aliases != NULL)
359 for (i=0; a->h_aliases[i] != NULL; i++)
363 if (a->h_addr_list != NULL)
365 for (i=0; a->h_addr_list[i] != NULL; i++)
380 #if (defined(NETWARE_BSDSOCK) && !defined(__NOVELL_LIBC__))
381 return gethostbyname((
char*)name);
383 return gethostbyname(name);
388 unsigned long low= (
unsigned long)-1;
403 if (low > ghbn_cache[i].order)
405 low=ghbn_cache[i].order;
408 if (ghbn_cache[i].order > 0)
410 if (strncmp(name,ghbn_cache[i].name,128) == 0)
424 # ifndef CONST_STRICT
425 ret=gethostbyname((
char *)name);
427 ret=gethostbyname(name);
444 if (ghbn_cache[lowi].ent != NULL)
445 ghbn_free(ghbn_cache[lowi].ent);
446 ghbn_cache[lowi].name[0] =
'\0';
448 if((ret=ghbn_cache[lowi].ent=ghbn_dup(ret)) == NULL)
453 strncpy(ghbn_cache[lowi].name,name,128);
454 ghbn_cache[lowi].order=BIO_ghbn_miss+BIO_ghbn_hits;
459 ret= ghbn_cache[i].ent;
460 ghbn_cache[i].order=BIO_ghbn_miss+BIO_ghbn_hits;
473 #ifdef OPENSSL_SYS_WINDOWS
474 static struct WSAData wsa_state;
481 memset(&wsa_state,0,
sizeof(wsa_state));
487 if (WSAStartup(0x0202,&wsa_state)!=0)
489 err=WSAGetLastError();
497 extern int _watt_do_exit;
503 #if defined(OPENSSL_SYS_NETWARE) && !defined(NETWARE_BSDSOCK)
511 wVerReq = MAKEWORD( 2, 0 );
512 err = WSAStartup(wVerReq,&wsaData);
527 #ifdef OPENSSL_SYS_WINDOWS
532 WSACancelBlockingCall();
536 #elif defined(OPENSSL_SYS_NETWARE) && !defined(NETWARE_BSDSOCK)
545 #if !defined(OPENSSL_SYS_VMS) || __VMS_VER >= 70000000
554 # if defined(OPENSSL_SYS_VMS)
561 # if __INITIAL_POINTER_SIZE == 64
563 # pragma pointer_size save
564 # pragma pointer_size 32
565 unsigned long arg_32;
566 unsigned long *arg_32p;
567 # pragma pointer_size restore
569 arg_32 = *((
unsigned long *) arg);
587 static int get_ip(
const char *str,
unsigned char ip[4])
592 tmp[0]=tmp[1]=tmp[2]=tmp[3]=0;
597 if ((c >=
'0') && (
c <=
'9'))
601 if (tmp[num] > 255)
return(0);
606 if (num == 3)
return(0);
610 else if (c ==
'\0' && (num == 3) && ok)
627 struct sockaddr_in sa_in;
629 struct sockaddr_in6 sa_in6;
632 int s=INVALID_SOCKET,cs,addrlen;
642 if ((str=
BUF_strdup(host)) == NULL)
return(INVALID_SOCKET);
663 static union {
void *
p;
664 int (
WSAAPI *
f)(
const char *,
const char *,
665 const struct addrinfo *,
667 } p_getaddrinfo = {NULL};
668 static union {
void *
p;
670 } p_freeaddrinfo = {NULL};
671 struct addrinfo *res,hint;
673 if (p_getaddrinfo.p==NULL)
677 p_getaddrinfo.p=(
void*)-1;
679 if (p_getaddrinfo.p==(
void *)-1)
break;
685 memset(&hint,0,
sizeof(hint));
686 hint.ai_flags = AI_PASSIVE;
691 if (h[1]==
'\0') h=NULL;
693 hint.ai_family = AF_INET6;
698 else if (h[0]==
'*' && h[1]==
'\0')
700 hint.ai_family = AF_INET;
705 if ((*p_getaddrinfo.f)(h,p,&hint,&res))
break;
707 addrlen = res->ai_addrlen<=
sizeof(server) ?
710 memcpy(&server, res->ai_addr, addrlen);
712 (*p_freeaddrinfo.f)(res);
719 memset((
char *)&server,0,
sizeof(server));
720 server.sa_in.sin_family=AF_INET;
721 server.sa_in.sin_port=htons(port);
722 addrlen =
sizeof(server.sa_in);
724 if (h == NULL || strcmp(h,
"*") == 0)
725 server.sa_in.sin_addr.s_addr=INADDR_ANY;
730 ((
unsigned long)ip[0]<<24L)|
731 ((
unsigned long)ip[1]<<16L)|
732 ((
unsigned long)ip[2]<< 8L)|
733 ((
unsigned long)ip[3]);
734 server.sa_in.sin_addr.s_addr=htonl(l);
739 if (s == INVALID_SOCKET)
752 ret=setsockopt(s,SOL_SOCKET,SO_REUSEADDR,(
char *)&i,
sizeof(i));
756 if (bind(s,&server.sa,addrlen) == -1)
761 #ifdef OPENSSL_SYS_WINDOWS
765 (err_num == WSAEADDRINUSE))
767 (err_num == EADDRINUSE))
771 if (
h == NULL || strcmp(
h,
"*") == 0)
774 if (client.sa.sa_family == AF_INET6)
776 memset(&client.sa_in6.sin6_addr,0,
sizeof(client.sa_in6.sin6_addr));
777 client.sa_in6.sin6_addr.s6_addr[15]=1;
781 if (client.sa.sa_family == AF_INET)
783 client.sa_in.sin_addr.s_addr=htonl(0x7F000001);
788 if (cs != INVALID_SOCKET)
791 ii=connect(cs,&client.sa,addrlen);
793 if (ii == INVALID_SOCKET)
819 if ((ret == 0) && (s != INVALID_SOCKET))
829 int ret=INVALID_SOCKET;
856 union {
size_t s;
int i; }
len;
859 struct sockaddr_in sa_in;
861 struct sockaddr_in6 sa_in6;
867 sa.len.i=
sizeof(sa.from);
868 memset(&sa.from,0,
sizeof(sa.from));
869 ret=accept(sock,&sa.from.sa,(
void *)&sa.len);
870 if (
sizeof(sa.len.i)!=
sizeof(sa.len.s) && sa.len.i==0)
873 sa.len.i = (int)sa.len.s;
876 if (ret == INVALID_SOCKET)
884 if (addr == NULL)
goto end;
888 char h[NI_MAXHOST],s[NI_MAXSERV];
890 static union {
void *
p;
891 int (
WSAAPI *
f)(
const struct sockaddr *,
size_t,
892 char *,size_t,
char *,size_t,int);
893 } p_getnameinfo = {NULL};
900 if (p_getnameinfo.p==NULL)
903 p_getnameinfo.p=(
void*)-1;
905 if (p_getnameinfo.p==(
void *)-1)
break;
907 if ((*p_getnameinfo.f)(&sa.from.sa,sa.len.i,
h,
sizeof(
h),s,
sizeof(s),
908 NI_NUMERICHOST|NI_NUMERICSERV))
break;
909 nl = strlen(h)+strlen(s)+2;
923 if (sa.from.sa.sa_family != AF_INET)
goto end;
924 l=ntohl(sa.from.sa_in.sin_addr.s_addr);
925 port=ntohs(sa.from.sa_in.sin_port);
936 (
unsigned char)(l>>24L)&0xff,
937 (
unsigned char)(l>>16L)&0xff,
938 (
unsigned char)(l>> 8L)&0xff,
939 (
unsigned char)(l )&0xff,
948 #if defined(TCP_NODELAY) && (defined(IPPROTO_TCP) || defined(SOL_TCP))
959 ret=setsockopt(s,opt,TCP_NODELAY,(
char *)&on,
sizeof(on));