| 1 |
diff -up openssl-1.0.0-beta3/apps/s_apps.h.ipv6-apps openssl-1.0.0-beta3/apps/s_apps.h
|
| 2 |
--- openssl-1.0.0-beta3/apps/s_apps.h.ipv6-apps 2009-08-05 21:29:58.000000000 +0200
|
| 3 |
+++ openssl-1.0.0-beta3/apps/s_apps.h 2009-08-05 21:29:58.000000000 +0200
|
| 4 |
@@ -148,7 +148,7 @@ typedef fd_mask fd_set;
|
| 5 |
#define PORT_STR "4433"
|
| 6 |
#define PROTOCOL "tcp"
|
| 7 |
|
| 8 |
-int do_server(int port, int type, int *ret, int (*cb) (char *hostname, int s, unsigned char *context), unsigned char *context);
|
| 9 |
+int do_server(char *port, int type, int *ret, int (*cb) (char *hostname, int s, unsigned char *context), unsigned char *context);
|
| 10 |
#ifdef HEADER_X509_H
|
| 11 |
int MS_CALLBACK verify_callback(int ok, X509_STORE_CTX *ctx);
|
| 12 |
#endif
|
| 13 |
@@ -156,10 +156,9 @@ int MS_CALLBACK verify_callback(int ok,
|
| 14 |
int set_cert_stuff(SSL_CTX *ctx, char *cert_file, char *key_file);
|
| 15 |
int set_cert_key_stuff(SSL_CTX *ctx, X509 *cert, EVP_PKEY *key);
|
| 16 |
#endif
|
| 17 |
-int init_client(int *sock, char *server, int port, int type);
|
| 18 |
+int init_client(int *sock, char *server, char *port, int type);
|
| 19 |
int should_retry(int i);
|
| 20 |
-int extract_port(char *str, short *port_ptr);
|
| 21 |
-int extract_host_port(char *str,char **host_ptr,unsigned char *ip,short *p);
|
| 22 |
+int extract_host_port(char *str,char **host_ptr,char **port_ptr);
|
| 23 |
|
| 24 |
long MS_CALLBACK bio_dump_callback(BIO *bio, int cmd, const char *argp,
|
| 25 |
int argi, long argl, long ret);
|
| 26 |
diff -up openssl-1.0.0-beta3/apps/s_client.c.ipv6-apps openssl-1.0.0-beta3/apps/s_client.c
|
| 27 |
--- openssl-1.0.0-beta3/apps/s_client.c.ipv6-apps 2009-08-05 21:29:58.000000000 +0200
|
| 28 |
+++ openssl-1.0.0-beta3/apps/s_client.c 2009-08-05 22:33:44.000000000 +0200
|
| 29 |
@@ -388,7 +388,7 @@ int MAIN(int argc, char **argv)
|
| 30 |
int cbuf_len,cbuf_off;
|
| 31 |
int sbuf_len,sbuf_off;
|
| 32 |
fd_set readfds,writefds;
|
| 33 |
- short port=PORT;
|
| 34 |
+ char *port_str = PORT_STR;
|
| 35 |
int full_log=1;
|
| 36 |
char *host=SSL_HOST_NAME;
|
| 37 |
char *cert_file=NULL,*key_file=NULL;
|
| 38 |
@@ -486,13 +486,12 @@ int MAIN(int argc, char **argv)
|
| 39 |
else if (strcmp(*argv,"-port") == 0)
|
| 40 |
{
|
| 41 |
if (--argc < 1) goto bad;
|
| 42 |
- port=atoi(*(++argv));
|
| 43 |
- if (port == 0) goto bad;
|
| 44 |
+ port_str= *(++argv);
|
| 45 |
}
|
| 46 |
else if (strcmp(*argv,"-connect") == 0)
|
| 47 |
{
|
| 48 |
if (--argc < 1) goto bad;
|
| 49 |
- if (!extract_host_port(*(++argv),&host,NULL,&port))
|
| 50 |
+ if (!extract_host_port(*(++argv),&host,&port_str))
|
| 51 |
goto bad;
|
| 52 |
}
|
| 53 |
else if (strcmp(*argv,"-verify") == 0)
|
| 54 |
@@ -956,7 +955,7 @@ bad:
|
| 55 |
|
| 56 |
re_start:
|
| 57 |
|
| 58 |
- if (init_client(&s,host,port,socket_type) == 0)
|
| 59 |
+ if (init_client(&s,host,port_str,socket_type) == 0)
|
| 60 |
{
|
| 61 |
BIO_printf(bio_err,"connect:errno=%d\n",get_last_socket_error());
|
| 62 |
SHUTDOWN(s);
|
| 63 |
diff -up openssl-1.0.0-beta3/apps/s_server.c.ipv6-apps openssl-1.0.0-beta3/apps/s_server.c
|
| 64 |
--- openssl-1.0.0-beta3/apps/s_server.c.ipv6-apps 2009-08-05 21:29:58.000000000 +0200
|
| 65 |
+++ openssl-1.0.0-beta3/apps/s_server.c 2009-08-05 21:29:58.000000000 +0200
|
| 66 |
@@ -837,7 +837,7 @@ int MAIN(int argc, char *argv[])
|
| 67 |
{
|
| 68 |
X509_VERIFY_PARAM *vpm = NULL;
|
| 69 |
int badarg = 0;
|
| 70 |
- short port=PORT;
|
| 71 |
+ char *port_str = PORT_STR;
|
| 72 |
char *CApath=NULL,*CAfile=NULL;
|
| 73 |
unsigned char *context = NULL;
|
| 74 |
char *dhfile = NULL;
|
| 75 |
@@ -907,8 +907,7 @@ int MAIN(int argc, char *argv[])
|
| 76 |
(strcmp(*argv,"-accept") == 0))
|
| 77 |
{
|
| 78 |
if (--argc < 1) goto bad;
|
| 79 |
- if (!extract_port(*(++argv),&port))
|
| 80 |
- goto bad;
|
| 81 |
+ port_str= *(++argv);
|
| 82 |
}
|
| 83 |
else if (strcmp(*argv,"-verify") == 0)
|
| 84 |
{
|
| 85 |
@@ -1685,9 +1684,9 @@ bad:
|
| 86 |
BIO_printf(bio_s_out,"ACCEPT\n");
|
| 87 |
(void)BIO_flush(bio_s_out);
|
| 88 |
if (www)
|
| 89 |
- do_server(port,socket_type,&accept_socket,www_body, context);
|
| 90 |
+ do_server(port_str,socket_type,&accept_socket,www_body, context);
|
| 91 |
else
|
| 92 |
- do_server(port,socket_type,&accept_socket,sv_body, context);
|
| 93 |
+ do_server(port_str,socket_type,&accept_socket,sv_body, context);
|
| 94 |
print_stats(bio_s_out,ctx);
|
| 95 |
ret=0;
|
| 96 |
end:
|
| 97 |
diff -up openssl-1.0.0-beta3/apps/s_socket.c.ipv6-apps openssl-1.0.0-beta3/apps/s_socket.c
|
| 98 |
--- openssl-1.0.0-beta3/apps/s_socket.c.ipv6-apps 2008-11-12 04:57:47.000000000 +0100
|
| 99 |
+++ openssl-1.0.0-beta3/apps/s_socket.c 2009-08-05 21:29:58.000000000 +0200
|
| 100 |
@@ -96,9 +96,7 @@ static struct hostent *GetHostByName(cha
|
| 101 |
static void ssl_sock_cleanup(void);
|
| 102 |
#endif
|
| 103 |
static int ssl_sock_init(void);
|
| 104 |
-static int init_client_ip(int *sock,unsigned char ip[4], int port, int type);
|
| 105 |
-static int init_server(int *sock, int port, int type);
|
| 106 |
-static int init_server_long(int *sock, int port,char *ip, int type);
|
| 107 |
+static int init_server(int *sock, char *port, int type);
|
| 108 |
static int do_accept(int acc_sock, int *sock, char **host);
|
| 109 |
static int host_ip(char *str, unsigned char ip[4]);
|
| 110 |
|
| 111 |
@@ -228,58 +226,70 @@ static int ssl_sock_init(void)
|
| 112 |
return(1);
|
| 113 |
}
|
| 114 |
|
| 115 |
-int init_client(int *sock, char *host, int port, int type)
|
| 116 |
+int init_client(int *sock, char *host, char *port, int type)
|
| 117 |
{
|
| 118 |
- unsigned char ip[4];
|
| 119 |
-
|
| 120 |
- if (!host_ip(host,&(ip[0])))
|
| 121 |
- {
|
| 122 |
- return(0);
|
| 123 |
- }
|
| 124 |
- return(init_client_ip(sock,ip,port,type));
|
| 125 |
- }
|
| 126 |
-
|
| 127 |
-static int init_client_ip(int *sock, unsigned char ip[4], int port, int type)
|
| 128 |
- {
|
| 129 |
- unsigned long addr;
|
| 130 |
- struct sockaddr_in them;
|
| 131 |
- int s,i;
|
| 132 |
+ struct addrinfo *res, *res0, hints;
|
| 133 |
+ char * failed_call = NULL;
|
| 134 |
+ int s;
|
| 135 |
+ int e;
|
| 136 |
|
| 137 |
if (!ssl_sock_init()) return(0);
|
| 138 |
|
| 139 |
- memset((char *)&them,0,sizeof(them));
|
| 140 |
- them.sin_family=AF_INET;
|
| 141 |
- them.sin_port=htons((unsigned short)port);
|
| 142 |
- addr=(unsigned long)
|
| 143 |
- ((unsigned long)ip[0]<<24L)|
|
| 144 |
- ((unsigned long)ip[1]<<16L)|
|
| 145 |
- ((unsigned long)ip[2]<< 8L)|
|
| 146 |
- ((unsigned long)ip[3]);
|
| 147 |
- them.sin_addr.s_addr=htonl(addr);
|
| 148 |
-
|
| 149 |
- if (type == SOCK_STREAM)
|
| 150 |
- s=socket(AF_INET,SOCK_STREAM,SOCKET_PROTOCOL);
|
| 151 |
- else /* ( type == SOCK_DGRAM) */
|
| 152 |
- s=socket(AF_INET,SOCK_DGRAM,IPPROTO_UDP);
|
| 153 |
-
|
| 154 |
- if (s == INVALID_SOCKET) { perror("socket"); return(0); }
|
| 155 |
+ memset(&hints, '\0', sizeof(hints));
|
| 156 |
+ hints.ai_socktype = type;
|
| 157 |
+ hints.ai_flags = AI_ADDRCONFIG;
|
| 158 |
+
|
| 159 |
+ e = getaddrinfo(host, port, &hints, &res);
|
| 160 |
+ if (e)
|
| 161 |
+ {
|
| 162 |
+ fprintf(stderr, "getaddrinfo: %s\n", gai_strerror(e));
|
| 163 |
+ if (e == EAI_SYSTEM)
|
| 164 |
+ perror("getaddrinfo");
|
| 165 |
+ return (0);
|
| 166 |
+ }
|
| 167 |
|
| 168 |
+ res0 = res;
|
| 169 |
+ while (res)
|
| 170 |
+ {
|
| 171 |
+ s = socket(res->ai_family, res->ai_socktype, res->ai_protocol);
|
| 172 |
+ if (s == INVALID_SOCKET)
|
| 173 |
+ {
|
| 174 |
+ failed_call = "socket";
|
| 175 |
+ goto nextres;
|
| 176 |
+ }
|
| 177 |
#if defined(SO_KEEPALIVE) && !defined(OPENSSL_SYS_MPE)
|
| 178 |
if (type == SOCK_STREAM)
|
| 179 |
{
|
| 180 |
- i=0;
|
| 181 |
- i=setsockopt(s,SOL_SOCKET,SO_KEEPALIVE,(char *)&i,sizeof(i));
|
| 182 |
- if (i < 0) { perror("keepalive"); return(0); }
|
| 183 |
+ int i=0;
|
| 184 |
+ i=setsockopt(s,SOL_SOCKET,SO_KEEPALIVE,
|
| 185 |
+ (char *)&i,sizeof(i));
|
| 186 |
+ if (i < 0) {
|
| 187 |
+ failed_call = "keepalive";
|
| 188 |
+ goto nextres;
|
| 189 |
+ }
|
| 190 |
}
|
| 191 |
#endif
|
| 192 |
-
|
| 193 |
- if (connect(s,(struct sockaddr *)&them,sizeof(them)) == -1)
|
| 194 |
- { closesocket(s); perror("connect"); return(0); }
|
| 195 |
+ if (connect(s,(struct sockaddr *)res->ai_addr,
|
| 196 |
+ res->ai_addrlen) == 0)
|
| 197 |
+ {
|
| 198 |
+ freeaddrinfo(res0);
|
| 199 |
*sock=s;
|
| 200 |
return(1);
|
| 201 |
}
|
| 202 |
|
| 203 |
-int do_server(int port, int type, int *ret, int (*cb)(char *hostname, int s, unsigned char *context), unsigned char *context)
|
| 204 |
+ failed_call = "socket";
|
| 205 |
+nextres:
|
| 206 |
+ if (s != INVALID_SOCKET)
|
| 207 |
+ close(s);
|
| 208 |
+ res = res->ai_next;
|
| 209 |
+ }
|
| 210 |
+ freeaddrinfo(res0);
|
| 211 |
+
|
| 212 |
+ perror(failed_call);
|
| 213 |
+ return(0);
|
| 214 |
+ }
|
| 215 |
+
|
| 216 |
+int do_server(char *port, int type, int *ret, int (*cb)(char *hostname, int s, unsigned char *context), unsigned char *context)
|
| 217 |
{
|
| 218 |
int sock;
|
| 219 |
char *name = NULL;
|
| 220 |
@@ -317,33 +327,38 @@ int do_server(int port, int type, int *r
|
| 221 |
}
|
| 222 |
}
|
| 223 |
|
| 224 |
-static int init_server_long(int *sock, int port, char *ip, int type)
|
| 225 |
+static int init_server(int *sock, char *port, int type)
|
| 226 |
{
|
| 227 |
- int ret=0;
|
| 228 |
- struct sockaddr_in server;
|
| 229 |
- int s= -1,i;
|
| 230 |
+ struct addrinfo *res, *res0, hints;
|
| 231 |
+ char * failed_call = NULL;
|
| 232 |
+ char port_name[8];
|
| 233 |
+ int s;
|
| 234 |
+ int e;
|
| 235 |
|
| 236 |
if (!ssl_sock_init()) return(0);
|
| 237 |
|
| 238 |
- memset((char *)&server,0,sizeof(server));
|
| 239 |
- server.sin_family=AF_INET;
|
| 240 |
- server.sin_port=htons((unsigned short)port);
|
| 241 |
- if (ip == NULL)
|
| 242 |
- server.sin_addr.s_addr=INADDR_ANY;
|
| 243 |
- else
|
| 244 |
-/* Added for T3E, address-of fails on bit field (beckman@acl.lanl.gov) */
|
| 245 |
-#ifndef BIT_FIELD_LIMITS
|
| 246 |
- memcpy(&server.sin_addr.s_addr,ip,4);
|
| 247 |
-#else
|
| 248 |
- memcpy(&server.sin_addr,ip,4);
|
| 249 |
-#endif
|
| 250 |
+ memset(&hints, '\0', sizeof(hints));
|
| 251 |
+ hints.ai_socktype = type;
|
| 252 |
+ hints.ai_flags = AI_PASSIVE | AI_ADDRCONFIG;
|
| 253 |
|
| 254 |
- if (type == SOCK_STREAM)
|
| 255 |
- s=socket(AF_INET,SOCK_STREAM,SOCKET_PROTOCOL);
|
| 256 |
- else /* type == SOCK_DGRAM */
|
| 257 |
- s=socket(AF_INET, SOCK_DGRAM,IPPROTO_UDP);
|
| 258 |
+ e = getaddrinfo(NULL, port, &hints, &res);
|
| 259 |
+ if (e)
|
| 260 |
+ {
|
| 261 |
+ fprintf(stderr, "getaddrinfo: %s\n", gai_strerror(e));
|
| 262 |
+ if (e == EAI_SYSTEM)
|
| 263 |
+ perror("getaddrinfo");
|
| 264 |
+ return (0);
|
| 265 |
+ }
|
| 266 |
|
| 267 |
- if (s == INVALID_SOCKET) goto err;
|
| 268 |
+ res0 = res;
|
| 269 |
+ while (res)
|
| 270 |
+ {
|
| 271 |
+ s = socket(res->ai_family, res->ai_socktype, res->ai_protocol);
|
| 272 |
+ if (s == INVALID_SOCKET)
|
| 273 |
+ {
|
| 274 |
+ failed_call = "socket";
|
| 275 |
+ goto nextres;
|
| 276 |
+ }
|
| 277 |
#if defined SOL_SOCKET && defined SO_REUSEADDR
|
| 278 |
{
|
| 279 |
int j = 1;
|
| 280 |
@@ -351,36 +366,39 @@ static int init_server_long(int *sock, i
|
| 281 |
(void *) &j, sizeof j);
|
| 282 |
}
|
| 283 |
#endif
|
| 284 |
- if (bind(s,(struct sockaddr *)&server,sizeof(server)) == -1)
|
| 285 |
+
|
| 286 |
+ if (bind(s,(struct sockaddr *)res->ai_addr, res->ai_addrlen) == -1)
|
| 287 |
{
|
| 288 |
-#ifndef OPENSSL_SYS_WINDOWS
|
| 289 |
- perror("bind");
|
| 290 |
-#endif
|
| 291 |
- goto err;
|
| 292 |
+ failed_call = "bind";
|
| 293 |
+ goto nextres;
|
| 294 |
}
|
| 295 |
- /* Make it 128 for linux */
|
| 296 |
- if (type==SOCK_STREAM && listen(s,128) == -1) goto err;
|
| 297 |
- i=0;
|
| 298 |
- *sock=s;
|
| 299 |
- ret=1;
|
| 300 |
-err:
|
| 301 |
- if ((ret == 0) && (s != -1))
|
| 302 |
+ if (type==SOCK_STREAM && listen(s,128) == -1)
|
| 303 |
{
|
| 304 |
- SHUTDOWN(s);
|
| 305 |
+ failed_call = "listen";
|
| 306 |
+ goto nextres;
|
| 307 |
}
|
| 308 |
- return(ret);
|
| 309 |
+
|
| 310 |
+ *sock=s;
|
| 311 |
+ return(1);
|
| 312 |
+
|
| 313 |
+nextres:
|
| 314 |
+ if (s != INVALID_SOCKET)
|
| 315 |
+ close(s);
|
| 316 |
+ res = res->ai_next;
|
| 317 |
}
|
| 318 |
+ freeaddrinfo(res0);
|
| 319 |
|
| 320 |
-static int init_server(int *sock, int port, int type)
|
| 321 |
- {
|
| 322 |
- return(init_server_long(sock, port, NULL, type));
|
| 323 |
+ if (s == INVALID_SOCKET) { perror("socket"); return(0); }
|
| 324 |
+
|
| 325 |
+ perror(failed_call);
|
| 326 |
+ return(0);
|
| 327 |
}
|
| 328 |
|
| 329 |
static int do_accept(int acc_sock, int *sock, char **host)
|
| 330 |
{
|
| 331 |
- int ret,i;
|
| 332 |
- struct hostent *h1,*h2;
|
| 333 |
- static struct sockaddr_in from;
|
| 334 |
+ static struct sockaddr_storage from;
|
| 335 |
+ char buffer[NI_MAXHOST];
|
| 336 |
+ int ret;
|
| 337 |
int len;
|
| 338 |
/* struct linger ling; */
|
| 339 |
|
| 340 |
@@ -425,137 +443,62 @@ redoit:
|
| 341 |
if (i < 0) { perror("keepalive"); return(0); }
|
| 342 |
*/
|
| 343 |
|
| 344 |
- if (host == NULL) goto end;
|
| 345 |
-#ifndef BIT_FIELD_LIMITS
|
| 346 |
- /* I should use WSAAsyncGetHostByName() under windows */
|
| 347 |
- h1=gethostbyaddr((char *)&from.sin_addr.s_addr,
|
| 348 |
- sizeof(from.sin_addr.s_addr),AF_INET);
|
| 349 |
-#else
|
| 350 |
- h1=gethostbyaddr((char *)&from.sin_addr,
|
| 351 |
- sizeof(struct in_addr),AF_INET);
|
| 352 |
-#endif
|
| 353 |
- if (h1 == NULL)
|
| 354 |
+ if (host == NULL)
|
| 355 |
{
|
| 356 |
- BIO_printf(bio_err,"bad gethostbyaddr\n");
|
| 357 |
- *host=NULL;
|
| 358 |
- /* return(0); */
|
| 359 |
- }
|
| 360 |
- else
|
| 361 |
- {
|
| 362 |
- if ((*host=(char *)OPENSSL_malloc(strlen(h1->h_name)+1)) == NULL)
|
| 363 |
- {
|
| 364 |
- perror("OPENSSL_malloc");
|
| 365 |
+ *sock=ret;
|
| 366 |
return(0);
|
| 367 |
}
|
| 368 |
- BUF_strlcpy(*host,h1->h_name,strlen(h1->h_name)+1);
|
| 369 |
|
| 370 |
- h2=GetHostByName(*host);
|
| 371 |
- if (h2 == NULL)
|
| 372 |
+ if (getnameinfo((struct sockaddr *)&from, sizeof(from),
|
| 373 |
+ buffer, sizeof(buffer),
|
| 374 |
+ NULL, 0, 0))
|
| 375 |
{
|
| 376 |
- BIO_printf(bio_err,"gethostbyname failure\n");
|
| 377 |
+ BIO_printf(bio_err,"getnameinfo failed\n");
|
| 378 |
+ *host=NULL;
|
| 379 |
return(0);
|
| 380 |
}
|
| 381 |
- i=0;
|
| 382 |
- if (h2->h_addrtype != AF_INET)
|
| 383 |
+ else
|
| 384 |
{
|
| 385 |
- BIO_printf(bio_err,"gethostbyname addr is not AF_INET\n");
|
| 386 |
+ if ((*host=(char *)OPENSSL_malloc(strlen(buffer)+1)) == NULL)
|
| 387 |
+ {
|
| 388 |
+ perror("OPENSSL_malloc");
|
| 389 |
return(0);
|
| 390 |
}
|
| 391 |
- }
|
| 392 |
-end:
|
| 393 |
+ strcpy(*host, buffer);
|
| 394 |
*sock=ret;
|
| 395 |
return(1);
|
| 396 |
}
|
| 397 |
+ }
|
| 398 |
|
| 399 |
-int extract_host_port(char *str, char **host_ptr, unsigned char *ip,
|
| 400 |
- short *port_ptr)
|
| 401 |
+int extract_host_port(char *str, char **host_ptr,
|
| 402 |
+ char **port_ptr)
|
| 403 |
{
|
| 404 |
- char *h,*p;
|
| 405 |
+ char *h,*p,*x;
|
| 406 |
|
| 407 |
- h=str;
|
| 408 |
- p=strchr(str,':');
|
| 409 |
+ x=h=str;
|
| 410 |
+ if (*h == '[')
|
| 411 |
+ {
|
| 412 |
+ h++;
|
| 413 |
+ p=strchr(h,']');
|
| 414 |
if (p == NULL)
|
| 415 |
{
|
| 416 |
- BIO_printf(bio_err,"no port defined\n");
|
| 417 |
+ BIO_printf(bio_err,"no ending bracket for IPv6 address\n");
|
| 418 |
return(0);
|
| 419 |
}
|
| 420 |
*(p++)='\0';
|
| 421 |
-
|
| 422 |
- if ((ip != NULL) && !host_ip(str,ip))
|
| 423 |
- goto err;
|
| 424 |
- if (host_ptr != NULL) *host_ptr=h;
|
| 425 |
-
|
| 426 |
- if (!extract_port(p,port_ptr))
|
| 427 |
- goto err;
|
| 428 |
- return(1);
|
| 429 |
-err:
|
| 430 |
- return(0);
|
| 431 |
+ x = p;
|
| 432 |
}
|
| 433 |
-
|
| 434 |
-static int host_ip(char *str, unsigned char ip[4])
|
| 435 |
- {
|
| 436 |
- unsigned int in[4];
|
| 437 |
- int i;
|
| 438 |
-
|
| 439 |
- if (sscanf(str,"%u.%u.%u.%u",&(in[0]),&(in[1]),&(in[2]),&(in[3])) == 4)
|
| 440 |
- {
|
| 441 |
- for (i=0; i<4; i++)
|
| 442 |
- if (in[i] > 255)
|
| 443 |
- {
|
| 444 |
- BIO_printf(bio_err,"invalid IP address\n");
|
| 445 |
- goto err;
|
| 446 |
- }
|
| 447 |
- ip[0]=in[0];
|
| 448 |
- ip[1]=in[1];
|
| 449 |
- ip[2]=in[2];
|
| 450 |
- ip[3]=in[3];
|
| 451 |
- }
|
| 452 |
- else
|
| 453 |
- { /* do a gethostbyname */
|
| 454 |
- struct hostent *he;
|
| 455 |
-
|
| 456 |
- if (!ssl_sock_init()) return(0);
|
| 457 |
-
|
| 458 |
- he=GetHostByName(str);
|
| 459 |
- if (he == NULL)
|
| 460 |
- {
|
| 461 |
- BIO_printf(bio_err,"gethostbyname failure\n");
|
| 462 |
- goto err;
|
| 463 |
- }
|
| 464 |
- /* cast to short because of win16 winsock definition */
|
| 465 |
- if ((short)he->h_addrtype != AF_INET)
|
| 466 |
+ p=strchr(x,':');
|
| 467 |
+ if (p == NULL)
|
| 468 |
{
|
| 469 |
- BIO_printf(bio_err,"gethostbyname addr is not AF_INET\n");
|
| 470 |
- return(0);
|
| 471 |
- }
|
| 472 |
- ip[0]=he->h_addr_list[0][0];
|
| 473 |
- ip[1]=he->h_addr_list[0][1];
|
| 474 |
- ip[2]=he->h_addr_list[0][2];
|
| 475 |
- ip[3]=he->h_addr_list[0][3];
|
| 476 |
- }
|
| 477 |
- return(1);
|
| 478 |
-err:
|
| 479 |
+ BIO_printf(bio_err,"no port defined\n");
|
| 480 |
return(0);
|
| 481 |
}
|
| 482 |
+ *(p++)='\0';
|
| 483 |
|
| 484 |
-int extract_port(char *str, short *port_ptr)
|
| 485 |
- {
|
| 486 |
- int i;
|
| 487 |
- struct servent *s;
|
| 488 |
+ if (host_ptr != NULL) *host_ptr=h;
|
| 489 |
+ if (port_ptr != NULL) *port_ptr=p;
|
| 490 |
|
| 491 |
- i=atoi(str);
|
| 492 |
- if (i != 0)
|
| 493 |
- *port_ptr=(unsigned short)i;
|
| 494 |
- else
|
| 495 |
- {
|
| 496 |
- s=getservbyname(str,"tcp");
|
| 497 |
- if (s == NULL)
|
| 498 |
- {
|
| 499 |
- BIO_printf(bio_err,"getservbyname failure for %s\n",str);
|
| 500 |
- return(0);
|
| 501 |
- }
|
| 502 |
- *port_ptr=ntohs((unsigned short)s->s_port);
|
| 503 |
- }
|
| 504 |
return(1);
|
| 505 |
}
|
| 506 |
|