From owner-svn-soc-all@FreeBSD.ORG Tue Jun 26 01:27:02 2012 Return-Path: Delivered-To: svn-soc-all@FreeBSD.org Received: from socsvn.FreeBSD.org (unknown [IPv6:2001:4f8:fff6::2f]) by hub.freebsd.org (Postfix) with SMTP id 92E3A106566C for ; Tue, 26 Jun 2012 01:27:00 +0000 (UTC) (envelope-from exxo@FreeBSD.org) Received: by socsvn.FreeBSD.org (sSMTP sendmail emulation); Tue, 26 Jun 2012 01:27:00 +0000 Date: Tue, 26 Jun 2012 01:27:00 +0000 From: exxo@FreeBSD.org To: svn-soc-all@FreeBSD.org MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Message-Id: <20120626012700.92E3A106566C@hub.freebsd.org> Cc: Subject: socsvn commit: r238313 - soc2012/exxo/patches X-BeenThere: svn-soc-all@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: SVN commit messages for the entire Summer of Code repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 26 Jun 2012 01:27:02 -0000 Author: exxo Date: Tue Jun 26 01:26:59 2012 New Revision: 238313 URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=238313 Log: Adding openssl current patch Added: soc2012/exxo/patches/openssl-1.0.1c.patch Added: soc2012/exxo/patches/openssl-1.0.1c.patch ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ soc2012/exxo/patches/openssl-1.0.1c.patch Tue Jun 26 01:26:59 2012 (r238313) @@ -0,0 +1,1601 @@ +diff -rpu -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 -rpu -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 -rpu -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-06-26 02:24:47.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,19 @@ 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)) ++ /* TODO ++ if (!extract_host_port(*(++argv),&host,NULL,&port)) */ + goto bad; + } + else if (strcmp(*argv,"-verify") == 0) +@@ -1252,10 +1269,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 -rpu -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 -rpu -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 -rpu -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-06-26 02:08:30.000000000 +0200 +@@ -113,21 +113,40 @@ static struct ghbn_cache_st + #endif + + static int get_ip(const char *str,unsigned char *ip); ++static int parse_ip(char *str, char **host, char **port, int *is_inet6); ++static int fill_addr(union sa_storage *sa, char *host, 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 +157,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 +541,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 +774,151 @@ static int get_ip(const char *str, unsig + return(1); + } + +-int BIO_get_accept_socket(char *host, int bind_mode) ++static int parse_ip(char *str, 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; ++ ++ *is_inet6 = 0; ++ if (*str == '\0') ++ return (0); ++ if (*str == '[' && (tmp = strchr(str + 1, ']'))) ++ { ++ h = str + 1; ++ *tmp++ = '\0'; ++ if (*tmp == ':') ++ p = tmp + 1; ++ else if (*tmp != '\0') ++ return (0); ++ *is_inet6 = 1; ++ } ++ else ++ { ++ if ((tmp = strchr(str, ':'))) + { +- p=e; ++ h = str; ++ *tmp++ = '\0'; ++ p = tmp; + } +- else if (*e == '/') ++ else if ((tmp = strchr(str, '/'))) + { +- *e='\0'; +- break; ++ if (*(tmp + 1) != '\0') ++ return (0); ++ p = str; ++ *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 = str; ++ } ++ 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, char *host, 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; *** DIFF OUTPUT TRUNCATED AT 1000 LINES ***