Use util/mklink.pl instead of util/mklink.sh.
[oweals/openssl.git] / crypto / bio / b_sock.c
index 2c36150b9b038405bac5d852dbab92c777559ded..cc9c1254780e1236951bfd38f9deee9d31a5f586 100644 (file)
@@ -63,9 +63,7 @@
 #include <errno.h>
 #define USE_SOCKETS
 #include "cryptlib.h"
-#include "bio.h"
-
-/*     BIOerr(BIO_F_WSASTARTUP,BIO_R_WSASTARTUP ); */
+#include <openssl/bio.h>
 
 #ifdef WIN16
 #define SOCKET_PROTOCOL 0 /* more microsoft stupidity */
@@ -96,19 +94,10 @@ static struct ghbn_cache_st
        unsigned long order;
        } ghbn_cache[GHBN_NUM];
 
-#ifndef NOPROTO
-static int get_ip(char *str,unsigned char *ip);
+static int get_ip(const char *str,unsigned char *ip);
 static void ghbn_free(struct hostent *a);
 static struct hostent *ghbn_dup(struct hostent *a);
-#else
-static int get_ip();
-static void ghbn_free();
-static struct hostent *ghbn_dup();
-#endif
-
-int BIO_get_host_ip(str,ip)
-char *str;
-unsigned char *ip;
+int BIO_get_host_ip(const char *str, unsigned char *ip)
        {
        int i;
        struct hostent *he;
@@ -146,9 +135,7 @@ unsigned char *ip;
        return(1);
        }
 
-int BIO_get_port(str,port_ptr)
-char *str;
-unsigned short *port_ptr;
+int BIO_get_port(const char *str, unsigned short *port_ptr)
        {
        int i;
        struct servent *s;
@@ -197,24 +184,25 @@ unsigned short *port_ptr;
        return(1);
        }
 
-int BIO_sock_error(sock)
-int sock;
+int BIO_sock_error(int sock)
        {
-       int j,i,size;
+       int j,i;
+       int size;
                 
        size=sizeof(int);
-
-       i=getsockopt(sock,SOL_SOCKET,SO_ERROR,(char *)&j,&size);
+       /* Note: under Windows the third parameter is of type (char *)
+        * 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 (char *) or (void *).
+        */
+       i=getsockopt(sock,SOL_SOCKET,SO_ERROR,(void *)&j,&size);
        if (i < 0)
                return(1);
        else
                return(j);
        }
 
-long BIO_ghbn_ctrl(cmd,iarg,parg)
-int cmd;
-int iarg;
-char *parg;
+long BIO_ghbn_ctrl(int cmd, int iarg, char *parg)
        {
        int i;
        char **p;
@@ -252,8 +240,7 @@ char *parg;
        return(1);
        }
 
-static struct hostent *ghbn_dup(a)
-struct hostent *a;
+static struct hostent *ghbn_dup(struct hostent *a)
        {
        struct hostent *ret;
        int i,j;
@@ -305,11 +292,13 @@ err:
        return(ret);
        }
 
-static void ghbn_free(a)
-struct hostent *a;
+static void ghbn_free(struct hostent *a)
        {
        int i;
 
+       if(a == NULL)
+           return;
+
        if (a->h_aliases != NULL)
                {
                for (i=0; a->h_aliases[i] != NULL; i++)
@@ -326,8 +315,7 @@ struct hostent *a;
        Free(a);
        }
 
-struct hostent *BIO_gethostbyname(name)
-char *name;
+struct hostent *BIO_gethostbyname(const char *name)
        {
        struct hostent *ret;
        int i,lowi=0,j;
@@ -382,7 +370,7 @@ char *name;
        return(ret);
        }
 
-int BIO_sock_init()
+int BIO_sock_init(void)
        {
 #ifdef WINDOWS
        static struct WSAData wsa_state;
@@ -408,7 +396,7 @@ int BIO_sock_init()
        return(1);
        }
 
-void BIO_sock_cleanup()
+void BIO_sock_cleanup(void)
        {
 #ifdef WINDOWS
        if (wsa_init_done)
@@ -420,10 +408,7 @@ void BIO_sock_cleanup()
 #endif
        }
 
-int BIO_socket_ioctl(fd,type,arg)
-int fd;
-long type;
-unsigned long *arg;
+int BIO_socket_ioctl(int fd, long type, unsigned long *arg)
        {
        int i;
 
@@ -435,9 +420,7 @@ unsigned long *arg;
 
 /* The reason I have implemented this instead of using sscanf is because
  * Visual C 1.52c gives an unresolved external when linking a DLL :-( */
-static int get_ip(str,ip)
-char *str;
-unsigned char ip[4];
+static int get_ip(const char *str, unsigned char ip[4])
        {
        unsigned int tmp[4];
        int num=0,c,ok=0;
@@ -472,16 +455,15 @@ unsigned char ip[4];
        return(1);
        }
 
-int BIO_get_accept_socket(host,bind_mode)
-char *host;
-int bind_mode;
+int BIO_get_accept_socket(char *host, int bind_mode)
        {
        int ret=0;
        struct sockaddr_in server,client;
        int s= -1,cs;
        unsigned char ip[4];
-       short port;
-       char *str,*h,*p,*e;
+       unsigned short port;
+       char *str,*e;
+       const char *h,*p;
        unsigned long l;
        int err_num;
 
@@ -515,7 +497,7 @@ int bind_mode;
 
        memset((char *)&server,0,sizeof(server));
        server.sin_family=AF_INET;
-       server.sin_port=htons((unsigned short)port);
+       server.sin_port=htons(port);
 
        if (strcmp(h,"*") == 0)
                server.sin_addr.s_addr=INADDR_ANY;
@@ -600,14 +582,12 @@ err:
        return(s);
        }
 
-int BIO_accept(sock,addr)
-int sock;
-char **addr;
+int BIO_accept(int sock, char **addr)
        {
        int ret=INVALID_SOCKET;
        static struct sockaddr_in from;
        unsigned long l;
-       short port;
+       unsigned short port;
        int len;
        char *p;
 
@@ -644,9 +624,7 @@ end:
        return(ret);
        }
 
-int BIO_set_tcp_ndelay(s,on)
-int s;
-int on;
+int BIO_set_tcp_ndelay(int s, int on)
        {
        int ret=0;
 #if defined(TCP_NODELAY) && (defined(IPPROTO_TCP) || defined(SOL_TCP))
@@ -666,9 +644,7 @@ int on;
        }
 #endif
 
-int BIO_socket_nbio(s,mode)
-int s;
-int mode;
+int BIO_socket_nbio(int s, int mode)
        {
        int ret= -1;
        unsigned long l;