diff -r -pu -X diff-exclude openssl-1.0.1c/Configure gsoc/openssl-1.0.1c/Configure --- openssl-1.0.1c/Configure 2012-03-14 23:20:40.000000000 +0100 +++ gsoc/openssl-1.0.1c/Configure 2012-06-26 02:18:50.000000000 +0200 @@ -168,8 +168,8 @@ my %table=( "purify", "purify gcc:-g -DPURIFY -Wall::(unknown)::-lsocket -lnsl::::", "debug", "gcc:-DBN_DEBUG -DREF_CHECK -DCONF_DEBUG -DBN_CTX_DEBUG -DCRYPTO_MDEBUG -DOPENSSL_NO_ASM -ggdb -g2 -Wformat -Wshadow -Wmissing-prototypes -Wmissing-declarations -Werror::(unknown)::-lefence::::", "debug-ben", "gcc:$gcc_devteam_warn -DBN_DEBUG -DREF_CHECK -DCONF_DEBUG -DBN_CTX_DEBUG -DCRYPTO_MDEBUG -DDEBUG_SAFESTACK -O2 -pipe::(unknown):::::", -"debug-ben-openbsd","gcc:-DBN_DEBUG -DREF_CHECK -DCONF_DEBUG -DBN_CTX_DEBUG -DCRYPTO_MDEBUG -DPEDANTIC -DDEBUG_SAFESTACK -DOPENSSL_OPENBSD_DEV_CRYPTO -DOPENSSL_NO_ASM -O2 -pedantic -Wall -Wshadow -Werror -pipe::(unknown)::::", -"debug-ben-openbsd-debug","gcc:-DBN_DEBUG -DREF_CHECK -DCONF_DEBUG -DBN_CTX_DEBUG -DCRYPTO_MDEBUG -DPEDANTIC -DDEBUG_SAFESTACK -DOPENSSL_OPENBSD_DEV_CRYPTO -DOPENSSL_NO_ASM -g3 -O2 -pedantic -Wall -Wshadow -Werror -pipe::(unknown)::::", +"debug-ben-openbsd","gcc:-DHAVE_SIN_LEN -DBN_DEBUG -DREF_CHECK -DCONF_DEBUG -DBN_CTX_DEBUG -DCRYPTO_MDEBUG -DPEDANTIC -DDEBUG_SAFESTACK -DOPENSSL_OPENBSD_DEV_CRYPTO -DOPENSSL_NO_ASM -O2 -pedantic -Wall -Wshadow -Werror -pipe::(unknown)::::", +"debug-ben-openbsd-debug","gcc:-DHAVE_SIN_LEN -DBN_DEBUG -DREF_CHECK -DCONF_DEBUG -DBN_CTX_DEBUG -DCRYPTO_MDEBUG -DPEDANTIC -DDEBUG_SAFESTACK -DOPENSSL_OPENBSD_DEV_CRYPTO -DOPENSSL_NO_ASM -g3 -O2 -pedantic -Wall -Wshadow -Werror -pipe::(unknown)::::", "debug-ben-debug", "gcc44:$gcc_devteam_warn -DBN_DEBUG -DCONF_DEBUG -DDEBUG_SAFESTACK -DDEBUG_UNUSED -g3 -O2 -pipe::(unknown)::::::", "debug-ben-macos", "cc:$gcc_devteam_warn -arch i386 -DBN_DEBUG -DCONF_DEBUG -DDEBUG_SAFESTACK -DDEBUG_UNUSED -DOPENSSL_THREADS -D_REENTRANT -DDSO_DLFCN -DHAVE_DLFCN_H -O3 -DL_ENDIAN -g3 -pipe::(unknown)::-Wl,-search_paths_first::::", "debug-ben-macos-gcc46", "gcc-mp-4.6:$gcc_devteam_warn -Wconversion -DBN_DEBUG -DCONF_DEBUG -DDEBUG_SAFESTACK -DDEBUG_UNUSED -DOPENSSL_THREADS -D_REENTRANT -DDSO_DLFCN -DHAVE_DLFCN_H -O3 -DL_ENDIAN -g3 -pipe::(unknown)::::::", @@ -407,21 +407,21 @@ my %table=( "android-armv7","gcc:-march=armv7-a -mandroid -I\$(ANDROID_DEV)/include -B\$(ANDROID_DEV)/lib -O3 -fomit-frame-pointer -Wall::-D_REENTRANT::-ldl:BN_LLONG RC4_CHAR RC4_CHUNK DES_INT DES_UNROLL BF_PTR:${armv4_asm}:dlfcn:linux-shared:-fPIC::.so.\$(SHLIB_MAJOR).\$(SHLIB_MINOR)", #### *BSD [do see comment about ${BSDthreads} above!] -"BSD-generic32","gcc:-DTERMIOS -O3 -fomit-frame-pointer -Wall::${BSDthreads}:::BN_LLONG RC2_CHAR RC4_INDEX DES_INT DES_UNROLL:${no_asm}:dlfcn:bsd-gcc-shared:-fPIC::.so.\$(SHLIB_MAJOR).\$(SHLIB_MINOR)", -"BSD-x86", "gcc:-DL_ENDIAN -DTERMIOS -O3 -fomit-frame-pointer -Wall::${BSDthreads}:::BN_LLONG ${x86_gcc_des} ${x86_gcc_opts}:${x86_asm}:a.out:dlfcn:bsd-shared:-fPIC::.so.\$(SHLIB_MAJOR).\$(SHLIB_MINOR)", -"BSD-x86-elf", "gcc:-DL_ENDIAN -DTERMIOS -O3 -fomit-frame-pointer -Wall::${BSDthreads}:::BN_LLONG ${x86_gcc_des} ${x86_gcc_opts}:${x86_elf_asm}:dlfcn:bsd-shared:-fPIC::.so.\$(SHLIB_MAJOR).\$(SHLIB_MINOR)", -"debug-BSD-x86-elf", "gcc:-DL_ENDIAN -DTERMIOS -O3 -Wall -g::${BSDthreads}:::BN_LLONG ${x86_gcc_des} ${x86_gcc_opts}:${x86_elf_asm}:dlfcn:bsd-shared:-fPIC::.so.\$(SHLIB_MAJOR).\$(SHLIB_MINOR)", -"BSD-sparcv8", "gcc:-DB_ENDIAN -DTERMIOS -O3 -mv8 -Wall::${BSDthreads}:::BN_LLONG RC2_CHAR RC4_INDEX DES_INT DES_UNROLL:${sparcv8_asm}:dlfcn:bsd-gcc-shared:-fPIC::.so.\$(SHLIB_MAJOR).\$(SHLIB_MINOR)", +"BSD-generic32","gcc:-DHAVE_SIN_LEN -DTERMIOS -O3 -fomit-frame-pointer -Wall::${BSDthreads}:::BN_LLONG RC2_CHAR RC4_INDEX DES_INT DES_UNROLL:${no_asm}:dlfcn:bsd-gcc-shared:-fPIC::.so.\$(SHLIB_MAJOR).\$(SHLIB_MINOR)", +"BSD-x86", "gcc:-DHAVE_SIN_LEN -DL_ENDIAN -DTERMIOS -O3 -fomit-frame-pointer -Wall::${BSDthreads}:::BN_LLONG ${x86_gcc_des} ${x86_gcc_opts}:${x86_asm}:a.out:dlfcn:bsd-shared:-fPIC::.so.\$(SHLIB_MAJOR).\$(SHLIB_MINOR)", +"BSD-x86-elf", "gcc:-DHAVE_SIN_LEN -DL_ENDIAN -DTERMIOS -O3 -fomit-frame-pointer -Wall::${BSDthreads}:::BN_LLONG ${x86_gcc_des} ${x86_gcc_opts}:${x86_elf_asm}:dlfcn:bsd-shared:-fPIC::.so.\$(SHLIB_MAJOR).\$(SHLIB_MINOR)", +"debug-BSD-x86-elf", "gcc:-DHAVE_SIN_LEN -DL_ENDIAN -DTERMIOS -O3 -Wall -g::${BSDthreads}:::BN_LLONG ${x86_gcc_des} ${x86_gcc_opts}:${x86_elf_asm}:dlfcn:bsd-shared:-fPIC::.so.\$(SHLIB_MAJOR).\$(SHLIB_MINOR)", +"BSD-sparcv8", "gcc:-DHAVE_SIN_LEN -DB_ENDIAN -DTERMIOS -O3 -mv8 -Wall::${BSDthreads}:::BN_LLONG RC2_CHAR RC4_INDEX DES_INT DES_UNROLL:${sparcv8_asm}:dlfcn:bsd-gcc-shared:-fPIC::.so.\$(SHLIB_MAJOR).\$(SHLIB_MINOR)", -"BSD-generic64","gcc:-DTERMIOS -O3 -Wall::${BSDthreads}:::SIXTY_FOUR_BIT_LONG RC4_CHUNK DES_INT DES_UNROLL:${no_asm}:dlfcn:bsd-gcc-shared:-fPIC::.so.\$(SHLIB_MAJOR).\$(SHLIB_MINOR)", +"BSD-generic64","gcc:-DHAVE_SIN_LEN -DTERMIOS -O3 -Wall::${BSDthreads}:::SIXTY_FOUR_BIT_LONG RC4_CHUNK DES_INT DES_UNROLL:${no_asm}:dlfcn:bsd-gcc-shared:-fPIC::.so.\$(SHLIB_MAJOR).\$(SHLIB_MINOR)", # -DMD32_REG_T=int doesn't actually belong in sparc64 target, it # simply *happens* to work around a compiler bug in gcc 3.3.3, # triggered by RIPEMD160 code. -"BSD-sparc64", "gcc:-DB_ENDIAN -DTERMIOS -O3 -DMD32_REG_T=int -Wall::${BSDthreads}:::BN_LLONG RC2_CHAR RC4_CHUNK DES_INT DES_PTR DES_RISC2 BF_PTR:${sparcv9_asm}:dlfcn:bsd-gcc-shared:-fPIC::.so.\$(SHLIB_MAJOR).\$(SHLIB_MINOR)", -"BSD-ia64", "gcc:-DL_ENDIAN -DTERMIOS -O3 -Wall::${BSDthreads}:::SIXTY_FOUR_BIT_LONG RC4_CHUNK DES_UNROLL DES_INT:${ia64_asm}:dlfcn:bsd-gcc-shared:-fPIC::.so.\$(SHLIB_MAJOR).\$(SHLIB_MINOR)", -"BSD-x86_64", "gcc:-DL_ENDIAN -DTERMIOS -O3 -Wall::${BSDthreads}:::SIXTY_FOUR_BIT_LONG RC4_CHUNK DES_INT DES_UNROLL:${x86_64_asm}:elf:dlfcn:bsd-gcc-shared:-fPIC::.so.\$(SHLIB_MAJOR).\$(SHLIB_MINOR)", +"BSD-sparc64", "gcc:-DHAVE_SIN_LEN -DB_ENDIAN -DTERMIOS -O3 -DMD32_REG_T=int -Wall::${BSDthreads}:::BN_LLONG RC2_CHAR RC4_CHUNK DES_INT DES_PTR DES_RISC2 BF_PTR:${sparcv9_asm}:dlfcn:bsd-gcc-shared:-fPIC::.so.\$(SHLIB_MAJOR).\$(SHLIB_MINOR)", +"BSD-ia64", "gcc:-DHAVE_SIN_LEN -DL_ENDIAN -DTERMIOS -O3 -Wall::${BSDthreads}:::SIXTY_FOUR_BIT_LONG RC4_CHUNK DES_UNROLL DES_INT:${ia64_asm}:dlfcn:bsd-gcc-shared:-fPIC::.so.\$(SHLIB_MAJOR).\$(SHLIB_MINOR)", +"BSD-x86_64", "gcc:-DHAVE_SIN_LEN -DL_ENDIAN -DTERMIOS -O3 -Wall::${BSDthreads}:::SIXTY_FOUR_BIT_LONG RC4_CHUNK DES_INT DES_UNROLL:${x86_64_asm}:elf:dlfcn:bsd-gcc-shared:-fPIC::.so.\$(SHLIB_MAJOR).\$(SHLIB_MINOR)", -"bsdi-elf-gcc", "gcc:-DPERL5 -DL_ENDIAN -fomit-frame-pointer -O3 -march=i486 -Wall::(unknown)::-ldl:BN_LLONG ${x86_gcc_des} ${x86_gcc_opts}:${x86_elf_asm}:dlfcn:bsd-gcc-shared:-fPIC::.so.\$(SHLIB_MAJOR).\$(SHLIB_MINOR)", +"bsdi-elf-gcc", "gcc:-DHAVE_SIN_LEN -DPERL5 -DL_ENDIAN -fomit-frame-pointer -O3 -march=i486 -Wall::(unknown)::-ldl:BN_LLONG ${x86_gcc_des} ${x86_gcc_opts}:${x86_elf_asm}:dlfcn:bsd-gcc-shared:-fPIC::.so.\$(SHLIB_MAJOR).\$(SHLIB_MINOR)", "nextstep", "cc:-O -Wall::(unknown):::BN_LLONG ${x86_gcc_des} ${x86_gcc_opts}:::", "nextstep3.3", "cc:-O3 -Wall::(unknown):::BN_LLONG ${x86_gcc_des} ${x86_gcc_opts}:::", @@ -574,13 +574,13 @@ my %table=( ##"ultrix","cc:-O2 -DNOPROTO -DNOCONST -DL_ENDIAN::(unknown):::::::", ##### MacOS X (a.k.a. Rhapsody or Darwin) setup -"rhapsody-ppc-cc","cc:-O3 -DB_ENDIAN::(unknown):MACOSX_RHAPSODY::BN_LLONG RC4_CHAR RC4_CHUNK DES_UNROLL BF_PTR:${no_asm}::", -"darwin-ppc-cc","cc:-arch ppc -O3 -DB_ENDIAN -Wa,-force_cpusubtype_ALL::-D_REENTRANT:MACOSX:-Wl,-search_paths_first%:BN_LLONG RC4_CHAR RC4_CHUNK DES_UNROLL BF_PTR:${ppc32_asm}:osx32:dlfcn:darwin-shared:-fPIC -fno-common:-arch ppc -dynamiclib:.\$(SHLIB_MAJOR).\$(SHLIB_MINOR).dylib", -"darwin64-ppc-cc","cc:-arch ppc64 -O3 -DB_ENDIAN::-D_REENTRANT:MACOSX:-Wl,-search_paths_first%:SIXTY_FOUR_BIT_LONG RC4_CHAR RC4_CHUNK DES_UNROLL BF_PTR:${ppc64_asm}:osx64:dlfcn:darwin-shared:-fPIC -fno-common:-arch ppc64 -dynamiclib:.\$(SHLIB_MAJOR).\$(SHLIB_MINOR).dylib", -"darwin-i386-cc","cc:-arch i386 -O3 -fomit-frame-pointer -DL_ENDIAN::-D_REENTRANT:MACOSX:-Wl,-search_paths_first%:BN_LLONG RC4_INT RC4_CHUNK DES_UNROLL BF_PTR:".eval{my $asm=$x86_asm;$asm=~s/cast\-586\.o//;$asm}.":macosx:dlfcn:darwin-shared:-fPIC -fno-common:-arch i386 -dynamiclib:.\$(SHLIB_MAJOR).\$(SHLIB_MINOR).dylib", -"debug-darwin-i386-cc","cc:-arch i386 -g3 -DL_ENDIAN::-D_REENTRANT:MACOSX:-Wl,-search_paths_first%:BN_LLONG RC4_INT RC4_CHUNK DES_UNROLL BF_PTR:${x86_asm}:macosx:dlfcn:darwin-shared:-fPIC -fno-common:-arch i386 -dynamiclib:.\$(SHLIB_MAJOR).\$(SHLIB_MINOR).dylib", -"darwin64-x86_64-cc","cc:-arch x86_64 -O3 -DL_ENDIAN -Wall::-D_REENTRANT:MACOSX:-Wl,-search_paths_first%:SIXTY_FOUR_BIT_LONG RC4_CHAR RC4_CHUNK DES_INT DES_UNROLL:".eval{my $asm=$x86_64_asm;$asm=~s/rc4\-[^:]+//;$asm}.":macosx:dlfcn:darwin-shared:-fPIC -fno-common:-arch x86_64 -dynamiclib:.\$(SHLIB_MAJOR).\$(SHLIB_MINOR).dylib", -"debug-darwin-ppc-cc","cc:-DBN_DEBUG -DREF_CHECK -DCONF_DEBUG -DCRYPTO_MDEBUG -DB_ENDIAN -g -Wall -O::-D_REENTRANT:MACOSX::BN_LLONG RC4_CHAR RC4_CHUNK DES_UNROLL BF_PTR:${ppc32_asm}:osx32:dlfcn:darwin-shared:-fPIC:-dynamiclib:.\$(SHLIB_MAJOR).\$(SHLIB_MINOR).dylib", +"rhapsody-ppc-cc","cc:-O3 -DHAVE_SIN_LEN -DB_ENDIAN::(unknown):MACOSX_RHAPSODY::BN_LLONG RC4_CHAR RC4_CHUNK DES_UNROLL BF_PTR:${no_asm}::", +"darwin-ppc-cc","cc:-arch ppc -O3 -DHAVE_SIN_LEN -DB_ENDIAN -Wa,-force_cpusubtype_ALL::-D_REENTRANT:MACOSX:-Wl,-search_paths_first%:BN_LLONG RC4_CHAR RC4_CHUNK DES_UNROLL BF_PTR:${ppc32_asm}:osx32:dlfcn:darwin-shared:-fPIC -fno-common:-arch ppc -dynamiclib:.\$(SHLIB_MAJOR).\$(SHLIB_MINOR).dylib", +"darwin64-ppc-cc","cc:-arch ppc64 -O3 -DHAVE_SIN_LEN -DB_ENDIAN::-D_REENTRANT:MACOSX:-Wl,-search_paths_first%:SIXTY_FOUR_BIT_LONG RC4_CHAR RC4_CHUNK DES_UNROLL BF_PTR:${ppc64_asm}:osx64:dlfcn:darwin-shared:-fPIC -fno-common:-arch ppc64 -dynamiclib:.\$(SHLIB_MAJOR).\$(SHLIB_MINOR).dylib", +"darwin-i386-cc","cc:-arch i386 -O3 -fomit-frame-pointer -DHAVE_SIN_LEN -DL_ENDIAN::-D_REENTRANT:MACOSX:-Wl,-search_paths_first%:BN_LLONG RC4_INT RC4_CHUNK DES_UNROLL BF_PTR:".eval{my $asm=$x86_asm;$asm=~s/cast\-586\.o//;$asm}.":macosx:dlfcn:darwin-shared:-fPIC -fno-common:-arch i386 -dynamiclib:.\$(SHLIB_MAJOR).\$(SHLIB_MINOR).dylib", +"debug-darwin-i386-cc","cc:-arch i386 -g3 -DHAVE_SIN_LEN -DL_ENDIAN::-D_REENTRANT:MACOSX:-Wl,-search_paths_first%:BN_LLONG RC4_INT RC4_CHUNK DES_UNROLL BF_PTR:${x86_asm}:macosx:dlfcn:darwin-shared:-fPIC -fno-common:-arch i386 -dynamiclib:.\$(SHLIB_MAJOR).\$(SHLIB_MINOR).dylib", +"darwin64-x86_64-cc","cc:-arch x86_64 -O3 -DHAVE_SIN_LEN -DL_ENDIAN -Wall::-D_REENTRANT:MACOSX:-Wl,-search_paths_first%:SIXTY_FOUR_BIT_LONG RC4_CHAR RC4_CHUNK DES_INT DES_UNROLL:".eval{my $asm=$x86_64_asm;$asm=~s/rc4\-[^:]+//;$asm}.":macosx:dlfcn:darwin-shared:-fPIC -fno-common:-arch x86_64 -dynamiclib:.\$(SHLIB_MAJOR).\$(SHLIB_MINOR).dylib", +"debug-darwin-ppc-cc","cc:-DHAVE_SIN_LEN -DBN_DEBUG -DREF_CHECK -DCONF_DEBUG -DCRYPTO_MDEBUG -DB_ENDIAN -g -Wall -O::-D_REENTRANT:MACOSX::BN_LLONG RC4_CHAR RC4_CHUNK DES_UNROLL BF_PTR:${ppc32_asm}:osx32:dlfcn:darwin-shared:-fPIC:-dynamiclib:.\$(SHLIB_MAJOR).\$(SHLIB_MINOR).dylib", # iPhoneOS/iOS "iphoneos-cross","llvm-gcc:-O3 -isysroot \$(CROSS_TOP)/SDKs/\$(CROSS_SDK) -fomit-frame-pointer -fno-common::-D_REENTRANT:iOS:-Wl,-search_paths_first%:BN_LLONG RC4_CHAR RC4_CHUNK DES_UNROLL BF_PTR:${no_asm}:dlfcn:darwin-shared:-fPIC -fno-common:-dynamiclib:.\$(SHLIB_MAJOR).\$(SHLIB_MINOR).dylib", diff -r -pu -X diff-exclude openssl-1.0.1c/apps/s_apps.h gsoc/openssl-1.0.1c/apps/s_apps.h --- openssl-1.0.1c/apps/s_apps.h 2009-09-04 19:42:04.000000000 +0200 +++ gsoc/openssl-1.0.1c/apps/s_apps.h 2012-06-26 01:10:06.000000000 +0200 @@ -148,7 +148,7 @@ typedef fd_mask fd_set; #define PORT_STR "4433" #define PROTOCOL "tcp" -int do_server(int port, int type, int *ret, int (*cb) (char *hostname, int s, unsigned char *context), unsigned char *context); +int do_server(char *port, int type, int *ret, int (*cb) (char *hostname, int s, unsigned char *context), unsigned char *context, int family); #ifdef HEADER_X509_H int MS_CALLBACK verify_callback(int ok, X509_STORE_CTX *ctx); #endif @@ -156,10 +156,8 @@ int MS_CALLBACK verify_callback(int ok, int set_cert_stuff(SSL_CTX *ctx, char *cert_file, char *key_file); int set_cert_key_stuff(SSL_CTX *ctx, X509 *cert, EVP_PKEY *key); #endif -int init_client(int *sock, char *server, int port, int type); +int init_client(int *sock, char *server, char *port, int type, int family); int should_retry(int i); -int extract_port(char *str, short *port_ptr); -int extract_host_port(char *str,char **host_ptr,unsigned char *ip,short *p); long MS_CALLBACK bio_dump_callback(BIO *bio, int cmd, const char *argp, int argi, long argl, long ret); diff -r -pu -X diff-exclude openssl-1.0.1c/apps/s_client.c gsoc/openssl-1.0.1c/apps/s_client.c --- openssl-1.0.1c/apps/s_client.c 2012-03-18 19:16:05.000000000 +0100 +++ gsoc/openssl-1.0.1c/apps/s_client.c 2012-07-16 17:02:41.000000000 +0200 @@ -287,6 +287,10 @@ static void sc_usage(void) BIO_printf(bio_err,"\n"); BIO_printf(bio_err," -host host - use -connect instead\n"); BIO_printf(bio_err," -port port - use -connect instead\n"); + BIO_printf(bio_err," -4 - use IPv4 only\n"); +#if OPENSSL_USE_IPV6 + BIO_printf(bio_err," -6 - use IPv6 only\n"); +#endif BIO_printf(bio_err," -connect host:port - who to connect to (default is %s:%s)\n",SSL_HOST_NAME,PORT_STR); BIO_printf(bio_err," -verify arg - turn on peer certificate verification\n"); @@ -563,7 +567,8 @@ int MAIN(int argc, char **argv) int cbuf_len,cbuf_off; int sbuf_len,sbuf_off; fd_set readfds,writefds; - short port=PORT; + char *port=PORT_STR; + int family; int full_log=1; char *host=SSL_HOST_NAME; char *cert_file=NULL,*key_file=NULL; @@ -652,6 +657,12 @@ int MAIN(int argc, char **argv) c_nbio=0; #endif +#if OPENSSL_USE_IPV6 + family = PF_INET6; +#else + family = PF_INET; +#endif + argc--; argv++; while (argc >= 1) @@ -664,13 +675,18 @@ int MAIN(int argc, char **argv) else if (strcmp(*argv,"-port") == 0) { if (--argc < 1) goto bad; - port=atoi(*(++argv)); - if (port == 0) goto bad; + port= *(++argv); } + else if (strcmp(*argv,"-4") == 0) + family = PF_INET; +#if OPENSSL_USE_IPV6 + else if (strcmp(*argv,"-6") == 0) + family = PF_INET6; +#endif else if (strcmp(*argv,"-connect") == 0) { if (--argc < 1) goto bad; - if (!extract_host_port(*(++argv),&host,NULL,&port)) + if (!BIO_extract_addr(*(++argv),&host,&port,NULL)) goto bad; } else if (strcmp(*argv,"-verify") == 0) @@ -1252,10 +1268,9 @@ bad: re_start: - if (init_client(&s,host,port,socket_type) == 0) + if (init_client(&s,host,port,socket_type,family) == 0) { - BIO_printf(bio_err,"connect:errno=%d\n",get_last_socket_error()); - SHUTDOWN(s); + ERR_print_errors(bio_err); goto end; } BIO_printf(bio_c_out,"CONNECTED(%08X)\n",s); diff -r -pu -X diff-exclude openssl-1.0.1c/apps/s_server.c gsoc/openssl-1.0.1c/apps/s_server.c --- openssl-1.0.1c/apps/s_server.c 2012-03-18 19:16:05.000000000 +0100 +++ gsoc/openssl-1.0.1c/apps/s_server.c 2012-06-26 01:24:25.000000000 +0200 @@ -460,6 +460,10 @@ static void sv_usage(void) BIO_printf(bio_err,"usage: s_server [args ...]\n"); BIO_printf(bio_err,"\n"); BIO_printf(bio_err," -accept arg - port to accept on (default is %d)\n",PORT); + BIO_printf(bio_err," -4 - use IPv4 only\n"); +#if OPENSSL_USE_IPV6 + BIO_printf(bio_err," -6 - use IPv6 only\n"); +#endif BIO_printf(bio_err," -context arg - set session ID context\n"); BIO_printf(bio_err," -verify arg - turn on peer certificate verification\n"); BIO_printf(bio_err," -Verify arg - turn on peer certificate verification, must have a cert.\n"); @@ -929,7 +933,8 @@ int MAIN(int argc, char *argv[]) { X509_VERIFY_PARAM *vpm = NULL; int badarg = 0; - short port=PORT; + char *port = PORT_STR; + int family; char *CApath=NULL,*CAfile=NULL; unsigned char *context = NULL; char *dhfile = NULL; @@ -991,6 +996,12 @@ int MAIN(int argc, char *argv[]) #endif s_nbio_test=0; +#if OPENSSL_USE_IPV6 + family = PF_INET6; +#else + family = PF_INET; +#endif + argc--; argv++; @@ -1000,9 +1011,14 @@ int MAIN(int argc, char *argv[]) (strcmp(*argv,"-accept") == 0)) { if (--argc < 1) goto bad; - if (!extract_port(*(++argv),&port)) - goto bad; + port= *(++argv); } + else if (strcmp(*argv,"-4") == 0) + family = PF_INET; +#if OPENSSL_USE_IPV6 + else if (strcmp(*argv,"-6") == 0) + family = PF_INET6; +#endif else if (strcmp(*argv,"-verify") == 0) { s_server_verify=SSL_VERIFY_PEER|SSL_VERIFY_CLIENT_ONCE; @@ -1874,9 +1890,11 @@ bad: BIO_printf(bio_s_out,"ACCEPT\n"); (void)BIO_flush(bio_s_out); if (www) - do_server(port,socket_type,&accept_socket,www_body, context); + ret = do_server(port,socket_type,&accept_socket,www_body, context, family); else - do_server(port,socket_type,&accept_socket,sv_body, context); + ret = do_server(port,socket_type,&accept_socket,sv_body, context, family); + if (ret == 0) + ERR_print_errors(bio_err); print_stats(bio_s_out,ctx); ret=0; end: diff -r -pu -X diff-exclude openssl-1.0.1c/apps/s_socket.c gsoc/openssl-1.0.1c/apps/s_socket.c --- openssl-1.0.1c/apps/s_socket.c 2011-12-02 15:39:40.000000000 +0100 +++ gsoc/openssl-1.0.1c/apps/s_socket.c 2012-06-26 02:04:07.000000000 +0200 @@ -97,16 +97,15 @@ typedef unsigned int u_int; #include "netdb.h" #endif -static struct hostent *GetHostByName(char *name); +#if 0 #if defined(OPENSSL_SYS_WINDOWS) || (defined(OPENSSL_SYS_NETWARE) && !defined(NETWARE_BSDSOCK)) static void ssl_sock_cleanup(void); #endif static int ssl_sock_init(void); -static int init_client_ip(int *sock,unsigned char ip[4], int port, int type); -static int init_server(int *sock, int port, int type); -static int init_server_long(int *sock, int port,char *ip, int type); static int do_accept(int acc_sock, int *sock, char **host); -static int host_ip(char *str, unsigned char ip[4]); +#endif +static int init_server(int *sock, char *port, int type, int family); +static int init_server_long(int *sock, char *port,char *ip, int type, int family); #ifdef OPENSSL_SYS_WIN16 #define SOCKET_PROTOCOL 0 /* more microsoft stupidity */ @@ -114,6 +113,8 @@ static int host_ip(char *str, unsigned c #define SOCKET_PROTOCOL IPPROTO_TCP #endif +#if 0 + #if defined(OPENSSL_SYS_NETWARE) && !defined(NETWARE_BSDSOCK) static int wsa_init_done=0; #endif @@ -234,64 +235,68 @@ static int ssl_sock_init(void) return(1); } -int init_client(int *sock, char *host, int port, int type) - { - unsigned char ip[4]; - - memset(ip, '\0', sizeof ip); - if (!host_ip(host,&(ip[0]))) - return 0; - return init_client_ip(sock,ip,port,type); - } +#endif -static int init_client_ip(int *sock, unsigned char ip[4], int port, int type) +int init_client(int *sock, char *host, char *port, int type, int family) { - unsigned long addr; - struct sockaddr_in them; - int s,i; - - if (!ssl_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 (type == SOCK_STREAM) - s=socket(AF_INET,SOCK_STREAM,SOCKET_PROTOCOL); - else /* ( type == SOCK_DGRAM) */ - s=socket(AF_INET,SOCK_DGRAM,IPPROTO_UDP); - - if (s == INVALID_SOCKET) { perror("socket"); return(0); } + char addr[128]; /* Should be enough */ + union sa_storage them; + int themlen; + int s=INVALID_SOCKET; + int ret=0; + int i=0; + if (BIO_sock_init() != 1) return(0); + if (host == NULL) + host="*"; +#if OPENSSL_USE_IPV6 + if (family == PF_INET6) + BIO_snprintf(addr, sizeof(addr), "[%s]:%s", host, port); + else +#endif + BIO_snprintf(addr, sizeof(addr), "%s:%s", host, port); + s=socket(family,type,SOCKET_PROTOCOL); + if (s == INVALID_SOCKET) goto err; + if (BIO_get_host_addr(addr, &them, &themlen, 0) != 1) goto err; #if defined(SO_KEEPALIVE) && !defined(OPENSSL_SYS_MPE) if (type == SOCK_STREAM) - { - i=0; + { i=setsockopt(s,SOL_SOCKET,SO_KEEPALIVE,(char *)&i,sizeof(i)); - if (i < 0) { perror("keepalive"); return(0); } + if (i < 0) + { + SYSerr(SYS_F_SETSOCKOPT,get_last_socket_error()); + goto err; + } } #endif - - if (connect(s,(struct sockaddr *)&them,sizeof(them)) == -1) - { closesocket(s); perror("connect"); return(0); } + if (connect(s,(struct sockaddr *)&them,themlen) == -1) + { + SYSerr(SYS_F_CONNECT,get_last_socket_error()); + goto err; + } *sock=s; - return(1); + ret=1; +err: + if ((ret == 0) && (s != INVALID_SOCKET)) + { + SHUTDOWN(s); + } + return (ret); } -int do_server(int port, int type, int *ret, int (*cb)(char *hostname, int s, unsigned char *context), unsigned char *context) +int do_server(char *port, int type, int *ret, int (*cb)(char *hostname, int s, unsigned char *context), unsigned char *context, int family) { int sock; char *name = NULL; int accept_socket = 0; int i; - if (!init_server(&accept_socket,port,type)) return(0); + if (!init_server(&accept_socket,port,type,family)) + return(0); + +#ifdef SIGINT + signal(SIGINT,(void (*)(int))BIO_sock_cleanup); +#endif if (ret != NULL) { @@ -302,7 +307,8 @@ int do_server(int port, int type, int *r { if (type==SOCK_STREAM) { - if (do_accept(accept_socket,&sock,&name) == 0) + sock = BIO_accept(accept_socket, &name); + if (sock == INVALID_SOCKET) { SHUTDOWN(accept_socket); return(0); @@ -322,33 +328,33 @@ int do_server(int port, int type, int *r } } -static int init_server_long(int *sock, int port, char *ip, int type) +static int init_server_long(int *sock, char *port, char *ip, int type, int family) { + char addr[128]; /* Should be enough */ + union sa_storage server; + int servlen; + int s=INVALID_SOCKET; int ret=0; - struct sockaddr_in server; - int s= -1; - if (!ssl_sock_init()) return(0); - - memset((char *)&server,0,sizeof(server)); - server.sin_family=AF_INET; - server.sin_port=htons((unsigned short)port); + if (BIO_sock_init() != 1) return(0); if (ip == NULL) - server.sin_addr.s_addr=INADDR_ANY; + ip="*"; +#if OPENSSL_USE_IPV6 + if (family == PF_INET6) + BIO_snprintf(addr, sizeof(addr), "[%s]:%s", ip, port); else -/* Added for T3E, address-of fails on bit field (beckman@acl.lanl.gov) */ -#ifndef BIT_FIELD_LIMITS - memcpy(&server.sin_addr.s_addr,ip,4); -#else - memcpy(&server.sin_addr,ip,4); #endif - - if (type == SOCK_STREAM) - s=socket(AF_INET,SOCK_STREAM,SOCKET_PROTOCOL); - else /* type == SOCK_DGRAM */ - s=socket(AF_INET, SOCK_DGRAM,IPPROTO_UDP); - - if (s == INVALID_SOCKET) goto err; + BIO_snprintf(addr, sizeof(addr), "%s:%s", ip, port); + if (type == SOCK_STREAM) + { + s = BIO_get_accept_socket(addr, BIO_BIND_REUSEADDR); + if (s == INVALID_SOCKET) goto err; + } + else /* type == SOCK_DGRAM */ + { + s=socket(family, SOCK_DGRAM,IPPROTO_UDP); + if (s == INVALID_SOCKET) goto err; + if (BIO_get_host_addr(addr, &server, &servlen, 1) != 1) goto err; #if defined SOL_SOCKET && defined SO_REUSEADDR { int j = 1; @@ -356,30 +362,28 @@ static int init_server_long(int *sock, i (void *) &j, sizeof j); } #endif - if (bind(s,(struct sockaddr *)&server,sizeof(server)) == -1) - { -#ifndef OPENSSL_SYS_WINDOWS - perror("bind"); -#endif - goto err; + if (bind(s,(struct sockaddr *)&server,servlen) == -1) + { + SYSerr(SYS_F_BIND,get_last_socket_error()); + goto err; + } } - /* Make it 128 for linux */ - if (type==SOCK_STREAM && listen(s,128) == -1) goto err; *sock=s; ret=1; err: - if ((ret == 0) && (s != -1)) + if ((ret == 0) && (s != INVALID_SOCKET)) { SHUTDOWN(s); } - return(ret); + return (ret); } -static int init_server(int *sock, int port, int type) +static int init_server(int *sock, char *port, int type, int family) { - return(init_server_long(sock, port, NULL, type)); + return(init_server_long(sock, port, NULL, type, family)); } +#if 0 static int do_accept(int acc_sock, int *sock, char **host) { int ret; @@ -470,150 +474,6 @@ end: *sock=ret; return(1); } - -int extract_host_port(char *str, char **host_ptr, unsigned char *ip, - short *port_ptr) - { - char *h,*p; - - h=str; - p=strchr(str,':'); - if (p == NULL) - { - BIO_printf(bio_err,"no port defined\n"); - return(0); - } - *(p++)='\0'; - - if ((ip != NULL) && !host_ip(str,ip)) - goto err; - if (host_ptr != NULL) *host_ptr=h; - - if (!extract_port(p,port_ptr)) - goto err; - return(1); -err: - return(0); - } - -static int host_ip(char *str, unsigned char ip[4]) - { - unsigned int in[4]; - int i; - - if (sscanf(str,"%u.%u.%u.%u",&(in[0]),&(in[1]),&(in[2]),&(in[3])) == 4) - { - for (i=0; i<4; i++) - if (in[i] > 255) - { - BIO_printf(bio_err,"invalid IP address\n"); - goto err; - } - ip[0]=in[0]; - ip[1]=in[1]; - ip[2]=in[2]; - ip[3]=in[3]; - } - else - { /* do a gethostbyname */ - struct hostent *he; - - if (!ssl_sock_init()) return(0); - - he=GetHostByName(str); - if (he == NULL) - { - BIO_printf(bio_err,"gethostbyname failure\n"); - goto err; - } - /* cast to short because of win16 winsock definition */ - if ((short)he->h_addrtype != AF_INET) - { - BIO_printf(bio_err,"gethostbyname addr is not AF_INET\n"); - return(0); - } - ip[0]=he->h_addr_list[0][0]; - ip[1]=he->h_addr_list[0][1]; - ip[2]=he->h_addr_list[0][2]; - ip[3]=he->h_addr_list[0][3]; - } - return(1); -err: - return(0); - } - -int extract_port(char *str, short *port_ptr) - { - int i; - struct servent *s; - - i=atoi(str); - if (i != 0) - *port_ptr=(unsigned short)i; - else - { - s=getservbyname(str,"tcp"); - if (s == NULL) - { - BIO_printf(bio_err,"getservbyname failure for %s\n",str); - return(0); - } - *port_ptr=ntohs((unsigned short)s->s_port); - } - return(1); - } - -#define GHBN_NUM 4 -static struct ghbn_cache_st - { - char name[128]; - struct hostent ent; - unsigned long order; - } ghbn_cache[GHBN_NUM]; - -static unsigned long ghbn_hits=0L; -static unsigned long ghbn_miss=0L; - -static struct hostent *GetHostByName(char *name) - { - struct hostent *ret; - int i,lowi=0; - unsigned long low= (unsigned long)-1; - - for (i=0; i ghbn_cache[i].order) - { - low=ghbn_cache[i].order; - lowi=i; - } - if (ghbn_cache[i].order > 0) - { - if (strncmp(name,ghbn_cache[i].name,128) == 0) - break; - } - } - if (i == GHBN_NUM) /* no hit*/ - { - ghbn_miss++; - ret=gethostbyname(name); - if (ret == NULL) return(NULL); - /* else add to cache */ - if(strlen(name) < sizeof ghbn_cache[0].name) - { - strcpy(ghbn_cache[lowi].name,name); - memcpy((char *)&(ghbn_cache[lowi].ent),ret,sizeof(struct hostent)); - ghbn_cache[lowi].order=ghbn_miss+ghbn_hits; - } - return(ret); - } - else - { - ghbn_hits++; - ret= &(ghbn_cache[i].ent); - ghbn_cache[i].order=ghbn_miss+ghbn_hits; - return(ret); - } - } +#endif #endif diff -r -pu -X diff-exclude openssl-1.0.1c/crypto/bio/b_sock.c gsoc/openssl-1.0.1c/crypto/bio/b_sock.c --- openssl-1.0.1c/crypto/bio/b_sock.c 2012-04-16 19:43:14.000000000 +0200 +++ gsoc/openssl-1.0.1c/crypto/bio/b_sock.c 2012-07-16 17:14:45.000000000 +0200 @@ -113,21 +113,39 @@ static struct ghbn_cache_st #endif static int get_ip(const char *str,unsigned char *ip); +static int fill_addr(union sa_storage *sa, const char *host, const char *port, int is_inet6, int is_local); #if 0 static void ghbn_free(struct hostent *a); static struct hostent *ghbn_dup(struct hostent *a); #endif int BIO_get_host_ip(const char *str, unsigned char *ip) { + int err; + + err = BIO_get_host_ip6(str, ip, BIO_RESOLV_INETONLY); + return (err > 0); /* don't generate another error code here */ + } + +int BIO_get_host_ip6(const char *str, unsigned char *ip, unsigned char mode) + { int i; int err = 1; int locked = 0; struct hostent *he; + struct addrinfo hint, *res = NULL; + char *addr = NULL; + int addrlen = 4; + int gai_err; - i=get_ip(str,ip); + if ((mode & BIO_RESOLV_INETONLY) && (mode & BIO_RESOLV_INET6ONLY)) + { + BIOerr(BIO_F_BIO_GET_HOST_IP6,BIO_R_INVALID_ARGUMENT); + return 0; + } + i=get_ip(str,ip); /* Search for an IPv4 address in in standard dot notation */ if (i < 0) { - BIOerr(BIO_F_BIO_GET_HOST_IP,BIO_R_INVALID_IP_ADDRESS); + BIOerr(BIO_F_BIO_GET_HOST_IP6,BIO_R_INVALID_IP_ADDRESS); goto err; } @@ -138,38 +156,93 @@ int BIO_get_host_ip(const char *str, uns /* If the string actually contained an IP address, we need not do anything more */ - if (i > 0) return(1); + if (i > 0) return(4); - /* do a gethostbyname */ - CRYPTO_w_lock(CRYPTO_LOCK_GETHOSTBYNAME); - locked = 1; - he=BIO_gethostbyname(str); - if (he == NULL) + memset(&hint,0,sizeof(hint)); +#if OPENSSL_USE_IPV6 + if ((mode & BIO_RESOLV_INETONLY)) + hint.ai_family=AF_INET; + else if ((mode & BIO_RESOLV_INET6ONLY)) + hint.ai_family=AF_INET6; + else + hint.ai_family=AF_UNSPEC; +#else + if ((mode & BIO_RESOLV_INET6ONLY)) { - BIOerr(BIO_F_BIO_GET_HOST_IP,BIO_R_BAD_HOSTNAME_LOOKUP); + /* Non sense, openssl is not configured to support inet6 */ + BIOerr(BIO_F_BIO_GET_HOST_IP6,BIO_R_INET6_UNSUPPORTED); goto err; } - - /* cast to short because of win16 winsock definition */ - if ((short)he->h_addrtype != AF_INET) + hint.ai_family=AF_INET; +#endif + if ((mode & BIO_RESOLV_LOCAL)) + hint.ai_flags = AI_PASSIVE; + gai_err = BIO_getaddrinfo(str, NULL, &hint, &res); + if (gai_err == 0) { - BIOerr(BIO_F_BIO_GET_HOST_IP,BIO_R_GETHOSTBYNAME_ADDR_IS_NOT_AF_INET); + res=NULL; goto err; } - for (i=0; i<4; i++) - ip[i]=he->h_addr_list[0][i]; + else if (gai_err < 0) /* Not supported fallback in gethostbyname */ + { + if ((mode & BIO_RESOLV_INET6ONLY)) + { + /* Do not expect that BIO_gethostbyname succeeds with inet6 only */ + BIOerr(BIO_F_BIO_GET_HOST_IP6,BIO_R_INET6_UNSUPPORTED); + goto err; + } + /* do a gethostbyname */ + CRYPTO_w_lock(CRYPTO_LOCK_GETHOSTBYNAME); + locked = 1; + he=BIO_gethostbyname(str); + if (he == NULL) + { + BIOerr(BIO_F_BIO_GET_HOST_IP6,BIO_R_BAD_HOSTNAME_LOOKUP); + goto err; + } + + /* cast to short because of win16 winsock definition */ + if ((short)he->h_addrtype != AF_INET) + { + BIOerr(BIO_F_BIO_GET_HOST_IP6,BIO_R_GETHOSTBYNAME_ADDR_IS_NOT_AF_INET); + goto err; + } + addr = he->h_addr; + addrlen = he->h_length; + } + else + { + if (res->ai_family == AF_INET) + { + OPENSSL_assert(res->ai_addrlen == sizeof(struct sockaddr_in)); + addr = (char *) &((struct sockaddr_in *) res->ai_addr)->sin_addr.s_addr; + addrlen = 4; + } + else if (res->ai_family == AF_INET6) + { + OPENSSL_assert(res->ai_addrlen == sizeof(struct sockaddr_in6)); + addr = (char *) &((struct sockaddr_in6 *) res->ai_addr)->sin6_addr.s6_addr; + addrlen = 16; + } + else + goto err; + } + for (i=0; i < addrlen; i++) + ip[i]=addr[i]; /* Store the address in network byte order */ err = 0; err: if (locked) CRYPTO_w_unlock(CRYPTO_LOCK_GETHOSTBYNAME); + if (res) + BIO_freeaddrinfo(res); if (err) { ERR_add_error_data(2,"host=",str); return 0; } else - return 1; + return addrlen; } int BIO_get_port(const char *str, unsigned short *port_ptr) @@ -467,9 +540,90 @@ end: #endif } +int BIO_getaddrinfo(const char *hostname, const char *servname, + const struct addrinfo *hints, struct addrinfo **res) + { +#ifdef EAI_FAMILY + int err; + const char *reason; + static union { void *p; + int (WSAAPI *f)(const char *,const char *, + const struct addrinfo *, + struct addrinfo **); + } p_getaddrinfo = {NULL}; + static union { void *p; + const char * (WSAAPI *f)(int); + } p_gai_strerror = {NULL}; + + if ((p_getaddrinfo.p=DSO_global_lookup("getaddrinfo"))!=NULL) + { + if ((err = (*p_getaddrinfo.f)(hostname,servname,hints,res))) + { + BIOerr(BIO_F_BIO_GETADDRINFO,BIO_R_BAD_HOSTNAME_LOOKUP); + if ((p_gai_strerror.p=DSO_global_lookup("gai_strerror"))!=NULL) + { +#ifdef OPENSSL_SYS_WINDOWS /* gai_strerror is not thread-safe under Microsoft Windows */ + CRYPTO_w_lock(CRYPTO_LOCK_GAI_STRERROR); + reason = (*p_gai_strerror.f)(err); + CRYPTO_w_unlock(CRYPTO_LOCK_GAI_STRERROR); +#else + reason = (*p_gai_strerror.f)(err); +#endif + ERR_add_error_data(1, reason); + } + return (0); + } + return (1); + } +#endif + BIOerr(BIO_F_BIO_GETADDRINFO,BIO_R_UNSUPPORTED_METHOD); + return (-1); + } + +void BIO_freeaddrinfo(struct addrinfo *ai) + { +#ifdef EAI_FAMILY + static union { void *p; + void (WSAAPI *f)(struct addrinfo *); + } p_freeaddrinfo = {NULL}; -int BIO_sock_init(void) + if ((p_freeaddrinfo.p=DSO_global_lookup("freeaddrinfo"))!=NULL) + (*p_freeaddrinfo.f)(ai); + else +#endif + BIOerr(BIO_F_BIO_FREEADDRINFO,BIO_R_UNSUPPORTED_METHOD); + } + +int BIO_getnameinfo(const struct sockaddr *sa, size_t salen, + char *host, size_t hostlen, char *serv, size_t servlen, int flags) { +#ifdef EAI_FAMILY + static union { void *p; + int (WSAAPI *f)(const struct sockaddr *,size_t/*socklen_t*/, + char *,size_t,char *,size_t,int); + } p_getnameinfo = {NULL}; + /* 2nd argument to getnameinfo is specified to + * be socklen_t. Unfortunately there is a number + * of environments where socklen_t is not defined. + * As it's passed by value, it's safe to pass it + * as size_t... */ + + if ((p_getnameinfo.p=DSO_global_lookup("getnameinfo"))!=NULL) + { + if (((*p_getnameinfo.f)(sa,salen,host,hostlen,serv,servlen,flags))!=0) + { + BIOerr(BIO_F_BIO_GETNAMEINFO,BIO_R_BAD_ADDR_RLOOKUP); + return (0); + } + return (1); + } +#endif + BIOerr(BIO_F_BIO_GETNAMEINFO,BIO_R_UNSUPPORTED_METHOD); + return (-1); + } + +int BIO_sock_init(void) + { #ifdef OPENSSL_SYS_WINDOWS static struct WSAData wsa_state; @@ -619,121 +773,153 @@ static int get_ip(const char *str, unsig return(1); } -int BIO_get_accept_socket(char *host, int bind_mode) +int BIO_extract_addr(char *addr, char **host, char **port, int *is_inet6) { - int ret=0; - union { - struct sockaddr sa; - struct sockaddr_in sa_in; -#if OPENSSL_USE_IPV6 - struct sockaddr_in6 sa_in6; -#endif - } server,client; - int s=INVALID_SOCKET,cs,addrlen; - unsigned char ip[4]; - unsigned short port; - char *str=NULL,*e; - char *h,*p; - unsigned long l; - int err_num; - - if (BIO_sock_init() != 1) return(INVALID_SOCKET); - - if ((str=BUF_strdup(host)) == NULL) return(INVALID_SOCKET); - - h=p=NULL; - h=str; - for (e=str; *e; e++) - { - if (*e == ':') + char *tmp; + char *h = *host = NULL; + char *p = *port = NULL; + + if (is_inet6) + *is_inet6 = 0; + if (*addr == '\0') + return (0); + if (*addr == '[' && (tmp = strchr(addr + 1, ']'))) + { + h = addr + 1; + *tmp++ = '\0'; + if (*tmp == ':') + p = tmp + 1; + else if (*tmp != '\0') + return (0); + if (is_inet6) + *is_inet6 = 1; + } + else + { + if ((tmp = strchr(addr, ':'))) { - p=e; + h = addr; + *tmp++ = '\0'; + p = tmp; } - else if (*e == '/') + else if ((tmp = strchr(addr, '/'))) { - *e='\0'; - break; + if (*(tmp + 1) != '\0') + return (0); + p = addr; + *tmp = '\0'; } - } - if (p) *p++='\0'; /* points at last ':', '::port' is special [see below] */ - else p=h,h=NULL; - -#ifdef EAI_FAMILY - do { - static union { void *p; - int (WSAAPI *f)(const char *,const char *, - const struct addrinfo *, - struct addrinfo **); - } p_getaddrinfo = {NULL}; - static union { void *p; - void (WSAAPI *f)(struct addrinfo *); - } p_freeaddrinfo = {NULL}; - struct addrinfo *res,hint; + else + h = addr; + } + if (h && (*h == '\0' || !strcmp(h, "*"))) + h = NULL; + if (p && (*p == '\0' || !strcmp(p, "*"))) + p = NULL; + *host = h; + *port = p; + return (1); + } - if (p_getaddrinfo.p==NULL) - { - if ((p_getaddrinfo.p=DSO_global_lookup("getaddrinfo"))==NULL || - (p_freeaddrinfo.p=DSO_global_lookup("freeaddrinfo"))==NULL) - p_getaddrinfo.p=(void*)-1; - } - if (p_getaddrinfo.p==(void *)-1) break; +static int fill_addr(union sa_storage *sa, const char *host, const char *port, int is_inet6, int is_local) + { + unsigned short p; + int sa_len = 0; +#ifdef OPENSSL_USE_IPV6 + unsigned char h[16]; +#else + unsigned char h[4]; +#endif - /* '::port' enforces IPv6 wildcard listener. Some OSes, - * e.g. Solaris, default to IPv6 without any hint. Also - * note that commonly IPv6 wildchard socket can service - * IPv4 connections just as well... */ - memset(&hint,0,sizeof(hint)); - hint.ai_flags = AI_PASSIVE; - if (h) - { - if (strchr(h,':')) + is_local = (is_local ? BIO_RESOLV_LOCAL : 0); + if (!BIO_get_port(port,&p)) return (0); + memset((char *)sa,0,sizeof(*sa)); + memset(h, 0, sizeof(h)); + if (is_inet6) /* deal with inet6 format (ie: [host]:port) */ + { +#ifdef OPENSSL_USE_IPV6 + OPENSSL_assert(sizeof(*sa) >= sizeof(struct sockaddr_in6)); + sa->sa_in6.sin6_family = AF_INET6; + sa->sa_in6.sin6_port = htons(p); + sa_len = sizeof(sa->sa_in6); +#ifdef SIN6_LEN /* BSD 4.4 */ + sa->sa_in6.sin6_len = sa_len; +#endif + if (host == NULL) + sa->sa_in6.sin6_addr = in6addr_any; + else { - if (h[1]=='\0') h=NULL; -#if OPENSSL_USE_IPV6 - hint.ai_family = AF_INET6; + if (!BIO_get_host_ip6(host, h, BIO_RESOLV_INET6ONLY|is_local)) return (0); +#ifndef BIT_FIELD_LIMITS /* Added for T3E, address-of fails on bit field (beckman@acl.lanl.gov) */ + memcpy(&sa->sa_in6.sin6_addr.s6_addr, h, sizeof(h)); #else - h=NULL; + memcpy(&sa->sa_in6.sin6_addr, h, sizeof(h)); #endif } - else if (h[0]=='*' && h[1]=='\0') +#else + /* inet6 format used without OPENSSL configured properly, thus invalid */ + return (0); +#endif + } + else /* we must resolve an inet4 address */ + { + OPENSSL_assert(sizeof(*sa) >= sizeof(struct sockaddr_in)); + sa->sa_in.sin_family=AF_INET; + sa->sa_in.sin_port=htons(p); + sa_len = sizeof(sa->sa_in); +#if HAVE_SIN_LEN /* BSD 4.4 */ + sa->sa_in.sin_len = sa_len; +#endif + if (host == NULL) + sa->sa_in.sin_addr.s_addr=INADDR_ANY; + else { - hint.ai_family = AF_INET; - h=NULL; + if (!BIO_get_host_ip6(host, h, BIO_RESOLV_INETONLY|is_local)) return (0); +#ifndef BIT_FIELD_LIMITS + memcpy(&sa->sa_in.sin_addr.s_addr, h, 4); /* always 4 here especially when using inet6 */ +#else + memcpy(&sa->sa_in.sin_addr, h, 4); +#endif } } + return (sa_len); + } - if ((*p_getaddrinfo.f)(h,p,&hint,&res)) break; - - addrlen = res->ai_addrlen<=sizeof(server) ? - res->ai_addrlen : - sizeof(server); - memcpy(&server, res->ai_addr, addrlen); - - (*p_freeaddrinfo.f)(res); - goto again; - } while (0); -#endif +int BIO_get_host_addr(char *host, union sa_storage *sa, int *sa_len, int local_query) + { + char *h, *p; + int is_inet6 = 0; - if (!BIO_get_port(p,&port)) goto err; + if (BIO_extract_addr(host, &h, &p, &is_inet6) != 1) + { + BIOerr(BIO_F_BIO_GET_HOST_ADDR,BIO_R_INVALID_IP_ADDRESS); + return (0); + } + *sa_len = fill_addr(sa, h, p, is_inet6, local_query); + if (*sa_len == 0) + return (0); /* Errors have been already generated */ + return (1); + } - memset((char *)&server,0,sizeof(server)); - server.sa_in.sin_family=AF_INET; - server.sa_in.sin_port=htons(port); - addrlen = sizeof(server.sa_in); +int BIO_get_accept_socket(char *host, int bind_mode) + { + union sa_storage server,client; + int s=INVALID_SOCKET,cs,addrlen; + char *str=NULL; + int err_num; + int ret = 0; + char *h, *p; + int is_inet6 = 0; - if (h == NULL || strcmp(h,"*") == 0) - server.sa_in.sin_addr.s_addr=INADDR_ANY; - else + if (BIO_sock_init() != 1) return(INVALID_SOCKET); + if ((str=BUF_strdup(host)) == NULL) return(INVALID_SOCKET); + if (BIO_extract_addr(str, &h, &p, &is_inet6) != 1) { - if (!BIO_get_host_ip(h,&(ip[0]))) goto err; - l=(unsigned long) - ((unsigned long)ip[0]<<24L)| - ((unsigned long)ip[1]<<16L)| - ((unsigned long)ip[2]<< 8L)| - ((unsigned long)ip[3]); - server.sa_in.sin_addr.s_addr=htonl(l); + BIOerr(BIO_F_BIO_GET_ACCEPT_SOCKET,BIO_R_INVALID_IP_ADDRESS); + goto err; } - + if ((addrlen = fill_addr(&server, h, p, is_inet6, 1)) == 0) + goto err; again: s=socket(server.sa.sa_family,SOCK_STREAM,SOCKET_PROTOCOL); if (s == INVALID_SOCKET) @@ -768,7 +954,7 @@ again: #endif { client = server; - if (h == NULL || strcmp(h,"*") == 0) + if (h == NULL) { #if OPENSSL_USE_IPV6 if (client.sa.sa_family == AF_INET6) @@ -830,6 +1016,9 @@ int BIO_accept(int sock, char **addr) unsigned long l; unsigned short port; char *p; + int err; + char h[NI_MAXHOST],s[NI_MAXSERV]; + size_t nl; struct { /* @@ -854,13 +1043,7 @@ int BIO_accept(int sock, char **addr) * */ union { size_t s; int i; } len; - union { - struct sockaddr sa; - struct sockaddr_in sa_in; -#if OPENSSL_USE_IPV6 - struct sockaddr_in6 sa_in6; -#endif - } from; + union sa_storage from; } sa; sa.len.s=0; @@ -883,43 +1066,27 @@ int BIO_accept(int sock, char **addr) if (addr == NULL) goto end; -#ifdef EAI_FAMILY - do { - char h[NI_MAXHOST],s[NI_MAXSERV]; - size_t nl; - static union { void *p; - int (WSAAPI *f)(const struct sockaddr *,size_t/*socklen_t*/, - char *,size_t,char *,size_t,int); - } p_getnameinfo = {NULL}; - /* 2nd argument to getnameinfo is specified to - * be socklen_t. Unfortunately there is a number - * of environments where socklen_t is not defined. - * As it's passed by value, it's safe to pass it - * as size_t... */ - - if (p_getnameinfo.p==NULL) - { - if ((p_getnameinfo.p=DSO_global_lookup("getnameinfo"))==NULL) - p_getnameinfo.p=(void*)-1; - } - if (p_getnameinfo.p==(void *)-1) break; - - if ((*p_getnameinfo.f)(&sa.from.sa,sa.len.i,h,sizeof(h),s,sizeof(s), - NI_NUMERICHOST|NI_NUMERICSERV)) break; - nl = strlen(h)+strlen(s)+2; - p = *addr; - if (p) { *p = '\0'; p = OPENSSL_realloc(p,nl); } - else { p = OPENSSL_malloc(nl); } - if (p==NULL) - { - BIOerr(BIO_F_BIO_ACCEPT,ERR_R_MALLOC_FAILURE); + err = BIO_getnameinfo(&sa.from.sa,sa.len.i,h,sizeof(h),s,sizeof(s), + NI_NUMERICHOST|NI_NUMERICSERV); + if (err == 1) /* BIO_getnameinfo has succeeded */ + { + nl = strlen(h)+strlen(s)+4; + p = *addr; + if (p) { *p = '\0'; p = OPENSSL_realloc(p,nl); } + else { p = OPENSSL_malloc(nl); } + if (p==NULL) + { + BIOerr(BIO_F_BIO_ACCEPT,ERR_R_MALLOC_FAILURE); + goto end; + } + *addr = p; + if (sa.from.sa.sa_family == AF_INET) + BIO_snprintf(*addr,nl,"%s:%s",h,s); + else + BIO_snprintf(*addr,nl,"[%s]:%s",h,s); goto end; } - *addr = p; - BIO_snprintf(*addr,nl,"%s:%s",h,s); - goto end; - } while(0); -#endif + /* else, BIO_getnameinfo is not supported or has failed */ if (sa.from.sa.sa_family != AF_INET) goto end; l=ntohl(sa.from.sa_in.sin_addr.s_addr); port=ntohs(sa.from.sa_in.sin_port); diff -r -pu -X diff-exclude openssl-1.0.1c/crypto/bio/bio.h gsoc/openssl-1.0.1c/crypto/bio/bio.h --- openssl-1.0.1c/crypto/bio/bio.h 2012-03-06 14:47:26.000000000 +0100 +++ gsoc/openssl-1.0.1c/crypto/bio/bio.h 2012-07-16 17:18:33.000000000 +0200 @@ -76,6 +76,13 @@ # endif #endif +/* TODO Under which conditions include the following OPENSSL_SYS_UNIX ? */ +#ifdef OPENSSL_SYS_UNIX +#include +#include +#include +#endif + #ifdef __cplusplus extern "C" { #endif @@ -715,11 +722,67 @@ struct hostent *BIO_gethostbyname(const * substructures; if the buffer does not suffice, NULL is returned * and an appropriate error code is set). */ + +#ifndef EAI_FAMILY + +struct addrinfo /* fake interface */ + { + int ai_flags; + int ai_family; + int ai_socktype; + int ai_protocol; + int ai_addrlen; + char* ai_canonname; + struct sockaddr *ai_addr; + struct addrinfo *ai_next; + }; + +/* dummy definitions */ +#define AI_PASSIVE 0 +#define AI_CANONNAME 0 +#define AI_NUMERICHOST 0 +#define AI_NUMERICSERV 0 +#define AI_ALL 0 +#define AI_V4MAPPED_CFG 0 +#define AI_ADDRCONFIG 0 +#define AI_V4MAPPED 0 + +#define NI_MAXHOST 1025 +#define NI_MAXSERV 32 +#define NI_NOFQDN 0 +#define NI_NUMERICHOST 0 +#define NI_NAMEREQD 0 +#define NI_NUMERICSERV 0 +#define NI_DGRAM 0 + +#endif + +union sa_storage + { + struct sockaddr sa; + struct sockaddr_in sa_in; +#if OPENSSL_USE_IPV6 + struct sockaddr_in6 sa_in6; +#endif + }; + +#define BIO_RESOLV_INETONLY 0x01 +#define BIO_RESOLV_INET6ONLY 0x02 +#define BIO_RESOLV_LOCAL 0x04 + +int BIO_getaddrinfo(const char *hostname, const char *servname, + const struct addrinfo *hints, struct addrinfo **res); +void BIO_freeaddrinfo(struct addrinfo *ai); +int BIO_getnameinfo(const struct sockaddr *sa, size_t salen, + char *host, size_t hostlen, char *serv, size_t servlen, int flags); +int BIO_get_host_addr(char *host, union sa_storage *sa, int *sa_len, int local_query); int BIO_sock_error(int sock); int BIO_socket_ioctl(int fd, long type, void *arg); int BIO_socket_nbio(int fd,int mode); int BIO_get_port(const char *str, unsigned short *port_ptr); int BIO_get_host_ip(const char *str, unsigned char *ip); +int BIO_get_host_ip6(const char *str, unsigned char *ip, unsigned char mode); +int BIO_extract_addr(char *addr, char **host, char **port, int *is_inet6); int BIO_get_accept_socket(char *host_port,int mode); int BIO_accept(int sock,char **ip_port); int BIO_sock_init(void ); @@ -782,9 +845,14 @@ void ERR_load_BIO_strings(void); #define BIO_F_BIO_CALLBACK_CTRL 131 #define BIO_F_BIO_CTRL 103 #define BIO_F_BIO_GETHOSTBYNAME 120 +#define BIO_F_BIO_GETADDRINFO 133 +#define BIO_F_BIO_FREEADDRINFO 134 +#define BIO_F_BIO_GETNAMEINFO 135 #define BIO_F_BIO_GETS 104 #define BIO_F_BIO_GET_ACCEPT_SOCKET 105 #define BIO_F_BIO_GET_HOST_IP 106 +#define BIO_F_BIO_GET_HOST_ADDR 137 +#define BIO_F_BIO_GET_HOST_IP6 136 #define BIO_F_BIO_GET_PORT 107 #define BIO_F_BIO_MAKE_PAIR 121 #define BIO_F_BIO_NEW 108 @@ -814,6 +882,7 @@ void ERR_load_BIO_strings(void); #define BIO_R_ACCEPT_ERROR 100 #define BIO_R_BAD_FOPEN_MODE 101 #define BIO_R_BAD_HOSTNAME_LOOKUP 102 +#define BIO_R_BAD_ADDR_RLOOKUP 129 #define BIO_R_BROKEN_PIPE 124 #define BIO_R_CONNECT_ERROR 103 #define BIO_R_EOF_ON_MEMORY_BIO 127 @@ -840,6 +909,7 @@ void ERR_load_BIO_strings(void); #define BIO_R_UNSUPPORTED_METHOD 121 #define BIO_R_WRITE_TO_READ_ONLY_BIO 126 #define BIO_R_WSASTARTUP 122 +#define BIO_R_INET6_UNSUPPORTED 130 #ifdef __cplusplus } diff -r -pu -X diff-exclude openssl-1.0.1c/crypto/bio/bio_err.c gsoc/openssl-1.0.1c/crypto/bio/bio_err.c --- openssl-1.0.1c/crypto/bio/bio_err.c 2011-12-27 15:37:43.000000000 +0100 +++ gsoc/openssl-1.0.1c/crypto/bio/bio_err.c 2012-06-25 12:36:42.000000000 +0200 @@ -76,9 +76,14 @@ static ERR_STRING_DATA BIO_str_functs[]= {ERR_FUNC(BIO_F_BIO_CALLBACK_CTRL), "BIO_callback_ctrl"}, {ERR_FUNC(BIO_F_BIO_CTRL), "BIO_ctrl"}, {ERR_FUNC(BIO_F_BIO_GETHOSTBYNAME), "BIO_gethostbyname"}, +{ERR_FUNC(BIO_F_BIO_GETADDRINFO), "BIO_getaddrinfo"}, +{ERR_FUNC(BIO_F_BIO_FREEADDRINFO), "BIO_freeaddrinfo"}, +{ERR_FUNC(BIO_F_BIO_GETNAMEINFO), "BIO_getnameinfo"}, {ERR_FUNC(BIO_F_BIO_GETS), "BIO_gets"}, {ERR_FUNC(BIO_F_BIO_GET_ACCEPT_SOCKET), "BIO_get_accept_socket"}, {ERR_FUNC(BIO_F_BIO_GET_HOST_IP), "BIO_get_host_ip"}, +{ERR_FUNC(BIO_F_BIO_GET_HOST_ADDR), "BIO_get_host_addr"}, +{ERR_FUNC(BIO_F_BIO_GET_HOST_IP6), "BIO_get_host_ip6"}, {ERR_FUNC(BIO_F_BIO_GET_PORT), "BIO_get_port"}, {ERR_FUNC(BIO_F_BIO_MAKE_PAIR), "BIO_MAKE_PAIR"}, {ERR_FUNC(BIO_F_BIO_NEW), "BIO_new"}, @@ -111,6 +116,7 @@ static ERR_STRING_DATA BIO_str_reasons[] {ERR_REASON(BIO_R_ACCEPT_ERROR) ,"accept error"}, {ERR_REASON(BIO_R_BAD_FOPEN_MODE) ,"bad fopen mode"}, {ERR_REASON(BIO_R_BAD_HOSTNAME_LOOKUP) ,"bad hostname lookup"}, +{ERR_REASON(BIO_R_BAD_ADDR_RLOOKUP) ,"bad reverse address lookup"}, {ERR_REASON(BIO_R_BROKEN_PIPE) ,"broken pipe"}, {ERR_REASON(BIO_R_CONNECT_ERROR) ,"connect error"}, {ERR_REASON(BIO_R_EOF_ON_MEMORY_BIO) ,"EOF on memory BIO"}, @@ -137,6 +143,7 @@ static ERR_STRING_DATA BIO_str_reasons[] {ERR_REASON(BIO_R_UNSUPPORTED_METHOD) ,"unsupported method"}, {ERR_REASON(BIO_R_WRITE_TO_READ_ONLY_BIO),"write to read only BIO"}, {ERR_REASON(BIO_R_WSASTARTUP) ,"WSAStartup"}, +{ERR_REASON(BIO_R_INET6_UNSUPPORTED) ,"inet6 could not be used"}, {0,NULL} }; diff -r -pu -X diff-exclude openssl-1.0.1c/crypto/bio/bss_dgram.c gsoc/openssl-1.0.1c/crypto/bio/bss_dgram.c --- openssl-1.0.1c/crypto/bio/bss_dgram.c 2012-03-06 14:47:26.000000000 +0100 +++ gsoc/openssl-1.0.1c/crypto/bio/bss_dgram.c 2012-06-25 19:05:34.000000000 +0200 @@ -143,13 +143,7 @@ static BIO_METHOD methods_dgramp_sctp= typedef struct bio_dgram_data_st { - union { - struct sockaddr sa; - struct sockaddr_in sa_in; -#if OPENSSL_USE_IPV6 - struct sockaddr_in6 sa_in6; -#endif - } peer; + union sa_storage peer; unsigned int connected; unsigned int _errno; unsigned int mtu; @@ -167,13 +161,7 @@ typedef struct bio_dgram_sctp_save_messa typedef struct bio_dgram_sctp_data_st { - union { - struct sockaddr sa; - struct sockaddr_in sa_in; -#if OPENSSL_USE_IPV6 - struct sockaddr_in6 sa_in6; -#endif - } peer; + union sa_storage peer; unsigned int connected; unsigned int _errno; unsigned int mtu; @@ -354,13 +342,7 @@ static int dgram_read(BIO *b, char *out, * See commentary in b_sock.c. */ union { size_t s; int i; } len; - union { - struct sockaddr sa; - struct sockaddr_in sa_in; -#if OPENSSL_USE_IPV6 - struct sockaddr_in6 sa_in6; -#endif - } peer; + union sa_storage peer; } sa; sa.len.s=0; @@ -451,13 +433,7 @@ static long dgram_ctrl(BIO *b, int cmd, #endif #ifdef OPENSSL_SYS_LINUX socklen_t addr_len; - union { - struct sockaddr sa; - struct sockaddr_in s4; -#if OPENSSL_USE_IPV6 - struct sockaddr_in6 s6; -#endif - } addr; + union sa_storage addr; #endif data = (bio_dgram_data *)b->ptr; diff -r -pu -X diff-exclude openssl-1.0.1c/crypto/crypto.h gsoc/openssl-1.0.1c/crypto/crypto.h --- openssl-1.0.1c/crypto/crypto.h 2011-06-01 18:54:03.000000000 +0200 +++ gsoc/openssl-1.0.1c/crypto/crypto.h 2012-06-10 01:01:26.000000000 +0200 @@ -222,6 +222,7 @@ typedef struct openssl_item_st #define CRYPTO_LOCK_FIPS 39 #define CRYPTO_LOCK_FIPS2 40 #define CRYPTO_NUM_LOCKS 41 +#define CRYPTO_LOCK_GAI_STRERROR 42 #define CRYPTO_LOCK 1 #define CRYPTO_UNLOCK 2 diff -r -pu -X diff-exclude openssl-1.0.1c/crypto/err/err.c gsoc/openssl-1.0.1c/crypto/err/err.c --- openssl-1.0.1c/crypto/err/err.c 2011-01-14 16:13:59.000000000 +0100 +++ gsoc/openssl-1.0.1c/crypto/err/err.c 2012-06-26 01:41:28.000000000 +0200 @@ -174,6 +174,7 @@ static ERR_STRING_DATA ERR_str_functs[]= #endif {ERR_PACK(0,SYS_F_OPENDIR,0), "opendir"}, {ERR_PACK(0,SYS_F_FREAD,0), "fread"}, + {ERR_PACK(0,SYS_F_SETSOCKOPT,0), "setsockopt"}, {0,NULL}, }; diff -r -pu -X diff-exclude openssl-1.0.1c/crypto/err/err.h gsoc/openssl-1.0.1c/crypto/err/err.h --- openssl-1.0.1c/crypto/err/err.h 2011-06-06 13:49:35.000000000 +0200 +++ gsoc/openssl-1.0.1c/crypto/err/err.h 2012-06-26 01:41:21.000000000 +0200 @@ -258,6 +258,7 @@ typedef struct err_state_st #define SYS_F_WSASTARTUP 9 /* Winsock stuff */ #define SYS_F_OPENDIR 10 #define SYS_F_FREAD 11 +#define SYS_F_SETSOCKOPT 12 /* reasons */ diff -r -pu -X diff-exclude openssl-1.0.1c/include/openssl/bio.h gsoc/openssl-1.0.1c/include/openssl/bio.h --- openssl-1.0.1c/include/openssl/bio.h 2012-03-06 14:47:26.000000000 +0100 +++ gsoc/openssl-1.0.1c/include/openssl/bio.h 2012-07-16 17:18:33.000000000 +0200 @@ -76,6 +76,13 @@ # endif #endif +/* TODO Under which conditions include the following OPENSSL_SYS_UNIX ? */ +#ifdef OPENSSL_SYS_UNIX +#include +#include +#include +#endif + #ifdef __cplusplus extern "C" { #endif @@ -715,11 +722,67 @@ struct hostent *BIO_gethostbyname(const * substructures; if the buffer does not suffice, NULL is returned * and an appropriate error code is set). */ + +#ifndef EAI_FAMILY + +struct addrinfo /* fake interface */ + { + int ai_flags; + int ai_family; + int ai_socktype; + int ai_protocol; + int ai_addrlen; + char* ai_canonname; + struct sockaddr *ai_addr; + struct addrinfo *ai_next; + }; + +/* dummy definitions */ +#define AI_PASSIVE 0 +#define AI_CANONNAME 0 +#define AI_NUMERICHOST 0 +#define AI_NUMERICSERV 0 +#define AI_ALL 0 +#define AI_V4MAPPED_CFG 0 +#define AI_ADDRCONFIG 0 +#define AI_V4MAPPED 0 + +#define NI_MAXHOST 1025 +#define NI_MAXSERV 32 +#define NI_NOFQDN 0 +#define NI_NUMERICHOST 0 +#define NI_NAMEREQD 0 +#define NI_NUMERICSERV 0 +#define NI_DGRAM 0 + +#endif + +union sa_storage + { + struct sockaddr sa; + struct sockaddr_in sa_in; +#if OPENSSL_USE_IPV6 + struct sockaddr_in6 sa_in6; +#endif + }; + +#define BIO_RESOLV_INETONLY 0x01 +#define BIO_RESOLV_INET6ONLY 0x02 +#define BIO_RESOLV_LOCAL 0x04 + +int BIO_getaddrinfo(const char *hostname, const char *servname, + const struct addrinfo *hints, struct addrinfo **res); +void BIO_freeaddrinfo(struct addrinfo *ai); +int BIO_getnameinfo(const struct sockaddr *sa, size_t salen, + char *host, size_t hostlen, char *serv, size_t servlen, int flags); +int BIO_get_host_addr(char *host, union sa_storage *sa, int *sa_len, int local_query); int BIO_sock_error(int sock); int BIO_socket_ioctl(int fd, long type, void *arg); int BIO_socket_nbio(int fd,int mode); int BIO_get_port(const char *str, unsigned short *port_ptr); int BIO_get_host_ip(const char *str, unsigned char *ip); +int BIO_get_host_ip6(const char *str, unsigned char *ip, unsigned char mode); +int BIO_extract_addr(char *addr, char **host, char **port, int *is_inet6); int BIO_get_accept_socket(char *host_port,int mode); int BIO_accept(int sock,char **ip_port); int BIO_sock_init(void ); @@ -782,9 +845,14 @@ void ERR_load_BIO_strings(void); #define BIO_F_BIO_CALLBACK_CTRL 131 #define BIO_F_BIO_CTRL 103 #define BIO_F_BIO_GETHOSTBYNAME 120 +#define BIO_F_BIO_GETADDRINFO 133 +#define BIO_F_BIO_FREEADDRINFO 134 +#define BIO_F_BIO_GETNAMEINFO 135 #define BIO_F_BIO_GETS 104 #define BIO_F_BIO_GET_ACCEPT_SOCKET 105 #define BIO_F_BIO_GET_HOST_IP 106 +#define BIO_F_BIO_GET_HOST_ADDR 137 +#define BIO_F_BIO_GET_HOST_IP6 136 #define BIO_F_BIO_GET_PORT 107 #define BIO_F_BIO_MAKE_PAIR 121 #define BIO_F_BIO_NEW 108 @@ -814,6 +882,7 @@ void ERR_load_BIO_strings(void); #define BIO_R_ACCEPT_ERROR 100 #define BIO_R_BAD_FOPEN_MODE 101 #define BIO_R_BAD_HOSTNAME_LOOKUP 102 +#define BIO_R_BAD_ADDR_RLOOKUP 129 #define BIO_R_BROKEN_PIPE 124 #define BIO_R_CONNECT_ERROR 103 #define BIO_R_EOF_ON_MEMORY_BIO 127 @@ -840,6 +909,7 @@ void ERR_load_BIO_strings(void); #define BIO_R_UNSUPPORTED_METHOD 121 #define BIO_R_WRITE_TO_READ_ONLY_BIO 126 #define BIO_R_WSASTARTUP 122 +#define BIO_R_INET6_UNSUPPORTED 130 #ifdef __cplusplus } diff -r -pu -X diff-exclude openssl-1.0.1c/include/openssl/crypto.h gsoc/openssl-1.0.1c/include/openssl/crypto.h --- openssl-1.0.1c/include/openssl/crypto.h 2011-06-01 18:54:03.000000000 +0200 +++ gsoc/openssl-1.0.1c/include/openssl/crypto.h 2012-06-10 01:01:26.000000000 +0200 @@ -222,6 +222,7 @@ typedef struct openssl_item_st #define CRYPTO_LOCK_FIPS 39 #define CRYPTO_LOCK_FIPS2 40 #define CRYPTO_NUM_LOCKS 41 +#define CRYPTO_LOCK_GAI_STRERROR 42 #define CRYPTO_LOCK 1 #define CRYPTO_UNLOCK 2 diff -r -pu -X diff-exclude openssl-1.0.1c/include/openssl/err.h gsoc/openssl-1.0.1c/include/openssl/err.h --- openssl-1.0.1c/include/openssl/err.h 2011-06-06 13:49:35.000000000 +0200 +++ gsoc/openssl-1.0.1c/include/openssl/err.h 2012-06-26 01:41:21.000000000 +0200 @@ -258,6 +258,7 @@ typedef struct err_state_st #define SYS_F_WSASTARTUP 9 /* Winsock stuff */ #define SYS_F_OPENDIR 10 #define SYS_F_FREAD 11 +#define SYS_F_SETSOCKOPT 12 /* reasons */