os/ossrv/ssl/libcrypto/src/crypto/bio/bss_acpt.c
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
sl@0
     1
/* crypto/bio/bss_acpt.c */
sl@0
     2
/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
sl@0
     3
 * All rights reserved.
sl@0
     4
 *
sl@0
     5
 * This package is an SSL implementation written
sl@0
     6
 * by Eric Young (eay@cryptsoft.com).
sl@0
     7
 * The implementation was written so as to conform with Netscapes SSL.
sl@0
     8
 * 
sl@0
     9
 * This library is free for commercial and non-commercial use as long as
sl@0
    10
 * the following conditions are aheared to.  The following conditions
sl@0
    11
 * apply to all code found in this distribution, be it the RC4, RSA,
sl@0
    12
 * lhash, DES, etc., code; not just the SSL code.  The SSL documentation
sl@0
    13
 * included with this distribution is covered by the same copyright terms
sl@0
    14
 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
sl@0
    15
 * 
sl@0
    16
 * Copyright remains Eric Young's, and as such any Copyright notices in
sl@0
    17
 * the code are not to be removed.
sl@0
    18
 * If this package is used in a product, Eric Young should be given attribution
sl@0
    19
 * as the author of the parts of the library used.
sl@0
    20
 * This can be in the form of a textual message at program startup or
sl@0
    21
 * in documentation (online or textual) provided with the package.
sl@0
    22
 * 
sl@0
    23
 * Redistribution and use in source and binary forms, with or without
sl@0
    24
 * modification, are permitted provided that the following conditions
sl@0
    25
 * are met:
sl@0
    26
 * 1. Redistributions of source code must retain the copyright
sl@0
    27
 *    notice, this list of conditions and the following disclaimer.
sl@0
    28
 * 2. Redistributions in binary form must reproduce the above copyright
sl@0
    29
 *    notice, this list of conditions and the following disclaimer in the
sl@0
    30
 *    documentation and/or other materials provided with the distribution.
sl@0
    31
 * 3. All advertising materials mentioning features or use of this software
sl@0
    32
 *    must display the following acknowledgement:
sl@0
    33
 *    "This product includes cryptographic software written by
sl@0
    34
 *     Eric Young (eay@cryptsoft.com)"
sl@0
    35
 *    The word 'cryptographic' can be left out if the rouines from the library
sl@0
    36
 *    being used are not cryptographic related :-).
sl@0
    37
 * 4. If you include any Windows specific code (or a derivative thereof) from 
sl@0
    38
 *    the apps directory (application code) you must include an acknowledgement:
sl@0
    39
 *    "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
sl@0
    40
 * 
sl@0
    41
 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
sl@0
    42
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
sl@0
    43
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
sl@0
    44
 * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
sl@0
    45
 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
sl@0
    46
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
sl@0
    47
 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
sl@0
    48
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
sl@0
    49
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
sl@0
    50
 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
sl@0
    51
 * SUCH DAMAGE.
sl@0
    52
 * 
sl@0
    53
 * The licence and distribution terms for any publically available version or
sl@0
    54
 * derivative of this code cannot be changed.  i.e. this code cannot simply be
sl@0
    55
 * copied and put under another distribution licence
sl@0
    56
 * [including the GNU Public Licence.]
sl@0
    57
 */
sl@0
    58
 /*
sl@0
    59
 © Portions copyright (c) 2006 Nokia Corporation.  All rights reserved.
sl@0
    60
 */
sl@0
    61
sl@0
    62
sl@0
    63
#include <stdio.h>
sl@0
    64
#include <errno.h>
sl@0
    65
#define USE_SOCKETS
sl@0
    66
#include "cryptlib.h"
sl@0
    67
#include <openssl/bio.h>
sl@0
    68
#if (defined(SYMBIAN) && (defined(__WINSCW__) || defined(__WINS__)))
sl@0
    69
#include "libcrypto_wsd_macros.h"
sl@0
    70
#include "libcrypto_wsd.h"
sl@0
    71
#endif
sl@0
    72
sl@0
    73
sl@0
    74
#ifndef OPENSSL_NO_SOCK
sl@0
    75
sl@0
    76
#ifdef OPENSSL_SYS_WIN16
sl@0
    77
#define SOCKET_PROTOCOL 0 /* more microsoft stupidity */
sl@0
    78
#else
sl@0
    79
#define SOCKET_PROTOCOL IPPROTO_TCP
sl@0
    80
#endif
sl@0
    81
sl@0
    82
#if (defined(OPENSSL_SYS_VMS) && __VMS_VER < 70000000)
sl@0
    83
/* FIONBIO used as a switch to enable ioctl, and that isn't in VMS < 7.0 */
sl@0
    84
#undef FIONBIO
sl@0
    85
#endif
sl@0
    86
sl@0
    87
typedef struct bio_accept_st
sl@0
    88
	{
sl@0
    89
	int state;
sl@0
    90
	char *param_addr;
sl@0
    91
sl@0
    92
	int accept_sock;
sl@0
    93
	int accept_nbio;
sl@0
    94
sl@0
    95
	char *addr;
sl@0
    96
	int nbio;
sl@0
    97
	/* If 0, it means normal, if 1, do a connect on bind failure,
sl@0
    98
	 * and if there is no-one listening, bind with SO_REUSEADDR.
sl@0
    99
	 * If 2, always use SO_REUSEADDR. */
sl@0
   100
	int bind_mode;
sl@0
   101
	BIO *bio_chain;
sl@0
   102
	} BIO_ACCEPT;
sl@0
   103
sl@0
   104
static int acpt_write(BIO *h, const char *buf, int num);
sl@0
   105
static int acpt_read(BIO *h, char *buf, int size);
sl@0
   106
static int acpt_puts(BIO *h, const char *str);
sl@0
   107
static long acpt_ctrl(BIO *h, int cmd, long arg1, void *arg2);
sl@0
   108
static int acpt_new(BIO *h);
sl@0
   109
static int acpt_free(BIO *data);
sl@0
   110
static int acpt_state(BIO *b, BIO_ACCEPT *c);
sl@0
   111
static void acpt_close_socket(BIO *data);
sl@0
   112
BIO_ACCEPT *BIO_ACCEPT_new(void );
sl@0
   113
void BIO_ACCEPT_free(BIO_ACCEPT *a);
sl@0
   114
sl@0
   115
#define ACPT_S_BEFORE			1
sl@0
   116
#define ACPT_S_GET_ACCEPT_SOCKET	2
sl@0
   117
#define ACPT_S_OK			3
sl@0
   118
sl@0
   119
#ifndef EMULATOR
sl@0
   120
static BIO_METHOD methods_acceptp=
sl@0
   121
	{
sl@0
   122
	BIO_TYPE_ACCEPT,
sl@0
   123
	"socket accept",
sl@0
   124
	acpt_write,
sl@0
   125
	acpt_read,
sl@0
   126
	acpt_puts,
sl@0
   127
	NULL, /* connect_gets, */
sl@0
   128
	acpt_ctrl,
sl@0
   129
	acpt_new,
sl@0
   130
	acpt_free,
sl@0
   131
	NULL,
sl@0
   132
	};
sl@0
   133
#else
sl@0
   134
sl@0
   135
GET_STATIC_VAR_FROM_TLS(methods_acceptp,bss_acpt,BIO_METHOD)
sl@0
   136
#define methods_acceptp (*GET_WSD_VAR_NAME(methods_acceptp,bss_acpt,s)())
sl@0
   137
const BIO_METHOD temp_s_methods_acceptp=
sl@0
   138
	{
sl@0
   139
	BIO_TYPE_ACCEPT,
sl@0
   140
	"socket accept",
sl@0
   141
	acpt_write,
sl@0
   142
	acpt_read,
sl@0
   143
	acpt_puts,
sl@0
   144
	NULL, /* connect_gets, */
sl@0
   145
	acpt_ctrl,
sl@0
   146
	acpt_new,
sl@0
   147
	acpt_free,
sl@0
   148
	NULL,
sl@0
   149
	};
sl@0
   150
sl@0
   151
#endif	
sl@0
   152
	
sl@0
   153
sl@0
   154
EXPORT_C BIO_METHOD *BIO_s_accept(void)
sl@0
   155
	{
sl@0
   156
	return(&methods_acceptp);
sl@0
   157
	}
sl@0
   158
sl@0
   159
static int acpt_new(BIO *bi)
sl@0
   160
	{
sl@0
   161
	BIO_ACCEPT *ba;
sl@0
   162
sl@0
   163
	bi->init=0;
sl@0
   164
	bi->num=INVALID_SOCKET;
sl@0
   165
	bi->flags=0;
sl@0
   166
	if ((ba=BIO_ACCEPT_new()) == NULL)
sl@0
   167
		return(0);
sl@0
   168
	bi->ptr=(char *)ba;
sl@0
   169
	ba->state=ACPT_S_BEFORE;
sl@0
   170
	bi->shutdown=1;
sl@0
   171
	return(1);
sl@0
   172
	}
sl@0
   173
sl@0
   174
EXPORT_C BIO_ACCEPT *BIO_ACCEPT_new(void)
sl@0
   175
	{
sl@0
   176
	BIO_ACCEPT *ret;
sl@0
   177
sl@0
   178
	if ((ret=(BIO_ACCEPT *)OPENSSL_malloc(sizeof(BIO_ACCEPT))) == NULL)
sl@0
   179
		return(NULL);
sl@0
   180
sl@0
   181
	memset(ret,0,sizeof(BIO_ACCEPT));
sl@0
   182
	ret->accept_sock=INVALID_SOCKET;
sl@0
   183
	ret->bind_mode=BIO_BIND_NORMAL;
sl@0
   184
	return(ret);
sl@0
   185
	}
sl@0
   186
sl@0
   187
EXPORT_C void BIO_ACCEPT_free(BIO_ACCEPT *a)
sl@0
   188
	{
sl@0
   189
	if(a == NULL)
sl@0
   190
	    return;
sl@0
   191
sl@0
   192
	if (a->param_addr != NULL) OPENSSL_free(a->param_addr);
sl@0
   193
	if (a->addr != NULL) OPENSSL_free(a->addr);
sl@0
   194
	if (a->bio_chain != NULL) BIO_free(a->bio_chain);
sl@0
   195
	OPENSSL_free(a);
sl@0
   196
	}
sl@0
   197
sl@0
   198
static void acpt_close_socket(BIO *bio)
sl@0
   199
	{
sl@0
   200
	BIO_ACCEPT *c;
sl@0
   201
sl@0
   202
	c=(BIO_ACCEPT *)bio->ptr;
sl@0
   203
	if (c->accept_sock != INVALID_SOCKET)
sl@0
   204
		{
sl@0
   205
		shutdown(c->accept_sock,2);
sl@0
   206
		closesocket(c->accept_sock);
sl@0
   207
		c->accept_sock=INVALID_SOCKET;
sl@0
   208
		bio->num=INVALID_SOCKET;
sl@0
   209
		}
sl@0
   210
	}
sl@0
   211
sl@0
   212
static int acpt_free(BIO *a)
sl@0
   213
	{
sl@0
   214
	BIO_ACCEPT *data;
sl@0
   215
sl@0
   216
	if (a == NULL) return(0);
sl@0
   217
	data=(BIO_ACCEPT *)a->ptr;
sl@0
   218
	 
sl@0
   219
	if (a->shutdown)
sl@0
   220
		{
sl@0
   221
		acpt_close_socket(a);
sl@0
   222
		BIO_ACCEPT_free(data);
sl@0
   223
		a->ptr=NULL;
sl@0
   224
		a->flags=0;
sl@0
   225
		a->init=0;
sl@0
   226
		}
sl@0
   227
	return(1);
sl@0
   228
	}
sl@0
   229
	
sl@0
   230
static int acpt_state(BIO *b, BIO_ACCEPT *c)
sl@0
   231
	{
sl@0
   232
	BIO *bio=NULL,*dbio;
sl@0
   233
	int s= -1;
sl@0
   234
	int i;
sl@0
   235
sl@0
   236
again:
sl@0
   237
	switch (c->state)
sl@0
   238
		{
sl@0
   239
	case ACPT_S_BEFORE:
sl@0
   240
		if (c->param_addr == NULL)
sl@0
   241
			{
sl@0
   242
			BIOerr(BIO_F_ACPT_STATE,BIO_R_NO_ACCEPT_PORT_SPECIFIED);
sl@0
   243
			return(-1);
sl@0
   244
			}
sl@0
   245
		s=BIO_get_accept_socket(c->param_addr,c->bind_mode);
sl@0
   246
		if (s == INVALID_SOCKET)
sl@0
   247
			return(-1);
sl@0
   248
sl@0
   249
		if (c->accept_nbio)
sl@0
   250
			{
sl@0
   251
			if (!BIO_socket_nbio(s,1))
sl@0
   252
				{
sl@0
   253
				closesocket(s);
sl@0
   254
				BIOerr(BIO_F_ACPT_STATE,BIO_R_ERROR_SETTING_NBIO_ON_ACCEPT_SOCKET);
sl@0
   255
				return(-1);
sl@0
   256
				}
sl@0
   257
			}
sl@0
   258
		c->accept_sock=s;
sl@0
   259
		b->num=s;
sl@0
   260
		c->state=ACPT_S_GET_ACCEPT_SOCKET;
sl@0
   261
		return(1);
sl@0
   262
		/* break; */
sl@0
   263
	case ACPT_S_GET_ACCEPT_SOCKET:
sl@0
   264
		if (b->next_bio != NULL)
sl@0
   265
			{
sl@0
   266
			c->state=ACPT_S_OK;
sl@0
   267
			goto again;
sl@0
   268
			}
sl@0
   269
		BIO_clear_retry_flags(b);
sl@0
   270
		b->retry_reason=0;
sl@0
   271
		i=BIO_accept(c->accept_sock,&(c->addr));
sl@0
   272
sl@0
   273
		/* -2 return means we should retry */
sl@0
   274
		if(i == -2)
sl@0
   275
			{
sl@0
   276
			BIO_set_retry_special(b);
sl@0
   277
			b->retry_reason=BIO_RR_ACCEPT;
sl@0
   278
			return -1;
sl@0
   279
			}
sl@0
   280
sl@0
   281
		if (i < 0) return(i);
sl@0
   282
sl@0
   283
		bio=BIO_new_socket(i,BIO_CLOSE);
sl@0
   284
		if (bio == NULL) goto err;
sl@0
   285
sl@0
   286
		BIO_set_callback(bio,BIO_get_callback(b));
sl@0
   287
		BIO_set_callback_arg(bio,BIO_get_callback_arg(b));
sl@0
   288
sl@0
   289
		if (c->nbio)
sl@0
   290
			{
sl@0
   291
			if (!BIO_socket_nbio(i,1))
sl@0
   292
				{
sl@0
   293
				BIOerr(BIO_F_ACPT_STATE,BIO_R_ERROR_SETTING_NBIO_ON_ACCEPTED_SOCKET);
sl@0
   294
				goto err;
sl@0
   295
				}
sl@0
   296
			}
sl@0
   297
sl@0
   298
		/* If the accept BIO has an bio_chain, we dup it and
sl@0
   299
		 * put the new socket at the end. */
sl@0
   300
		if (c->bio_chain != NULL)
sl@0
   301
			{
sl@0
   302
			if ((dbio=BIO_dup_chain(c->bio_chain)) == NULL)
sl@0
   303
				goto err;
sl@0
   304
			if (!BIO_push(dbio,bio)) goto err;
sl@0
   305
			bio=dbio;
sl@0
   306
			}
sl@0
   307
		if (BIO_push(b,bio) == NULL) goto err;
sl@0
   308
sl@0
   309
		c->state=ACPT_S_OK;
sl@0
   310
		return(1);
sl@0
   311
err:
sl@0
   312
		if (bio != NULL)
sl@0
   313
			BIO_free(bio);
sl@0
   314
		else if (s >= 0)
sl@0
   315
			closesocket(s);
sl@0
   316
		return(0);
sl@0
   317
		/* break; */
sl@0
   318
	case ACPT_S_OK:
sl@0
   319
		if (b->next_bio == NULL)
sl@0
   320
			{
sl@0
   321
			c->state=ACPT_S_GET_ACCEPT_SOCKET;
sl@0
   322
			goto again;
sl@0
   323
			}
sl@0
   324
		return(1);
sl@0
   325
		/* break; */
sl@0
   326
	default:	
sl@0
   327
		return(0);
sl@0
   328
		/* break; */
sl@0
   329
		}
sl@0
   330
sl@0
   331
	}
sl@0
   332
sl@0
   333
static int acpt_read(BIO *b, char *out, int outl)
sl@0
   334
	{
sl@0
   335
	int ret=0;
sl@0
   336
	BIO_ACCEPT *data;
sl@0
   337
sl@0
   338
	BIO_clear_retry_flags(b);
sl@0
   339
	data=(BIO_ACCEPT *)b->ptr;
sl@0
   340
sl@0
   341
	while (b->next_bio == NULL)
sl@0
   342
		{
sl@0
   343
		ret=acpt_state(b,data);
sl@0
   344
		if (ret <= 0) return(ret);
sl@0
   345
		}
sl@0
   346
sl@0
   347
	ret=BIO_read(b->next_bio,out,outl);
sl@0
   348
	BIO_copy_next_retry(b);
sl@0
   349
	return(ret);
sl@0
   350
	}
sl@0
   351
sl@0
   352
static int acpt_write(BIO *b, const char *in, int inl)
sl@0
   353
	{
sl@0
   354
	int ret;
sl@0
   355
	BIO_ACCEPT *data;
sl@0
   356
sl@0
   357
	BIO_clear_retry_flags(b);
sl@0
   358
	data=(BIO_ACCEPT *)b->ptr;
sl@0
   359
sl@0
   360
	while (b->next_bio == NULL)
sl@0
   361
		{
sl@0
   362
		ret=acpt_state(b,data);
sl@0
   363
		if (ret <= 0) return(ret);
sl@0
   364
		}
sl@0
   365
sl@0
   366
	ret=BIO_write(b->next_bio,in,inl);
sl@0
   367
	BIO_copy_next_retry(b);
sl@0
   368
	return(ret);
sl@0
   369
	}
sl@0
   370
sl@0
   371
static long acpt_ctrl(BIO *b, int cmd, long num, void *ptr)
sl@0
   372
	{
sl@0
   373
	BIO *dbio;
sl@0
   374
	int *ip;
sl@0
   375
	long ret=1;
sl@0
   376
	BIO_ACCEPT *data;
sl@0
   377
	char **pp;
sl@0
   378
sl@0
   379
	data=(BIO_ACCEPT *)b->ptr;
sl@0
   380
sl@0
   381
	switch (cmd)
sl@0
   382
		{
sl@0
   383
	case BIO_CTRL_RESET:
sl@0
   384
		ret=0;
sl@0
   385
		data->state=ACPT_S_BEFORE;
sl@0
   386
		acpt_close_socket(b);
sl@0
   387
		b->flags=0;
sl@0
   388
		break;
sl@0
   389
	case BIO_C_DO_STATE_MACHINE:
sl@0
   390
		/* use this one to start the connection */
sl@0
   391
		ret=(long)acpt_state(b,data);
sl@0
   392
		break;
sl@0
   393
	case BIO_C_SET_ACCEPT:
sl@0
   394
		if (ptr != NULL)
sl@0
   395
			{
sl@0
   396
			if (num == 0)
sl@0
   397
				{
sl@0
   398
				b->init=1;
sl@0
   399
				if (data->param_addr != NULL)
sl@0
   400
					OPENSSL_free(data->param_addr);
sl@0
   401
				data->param_addr=BUF_strdup(ptr);
sl@0
   402
				}
sl@0
   403
			else if (num == 1)
sl@0
   404
				{
sl@0
   405
				data->accept_nbio=(ptr != NULL);
sl@0
   406
				}
sl@0
   407
			else if (num == 2)
sl@0
   408
				{
sl@0
   409
				if (data->bio_chain != NULL)
sl@0
   410
					BIO_free(data->bio_chain);
sl@0
   411
				data->bio_chain=(BIO *)ptr;
sl@0
   412
				}
sl@0
   413
			}
sl@0
   414
		break;
sl@0
   415
	case BIO_C_SET_NBIO:
sl@0
   416
		data->nbio=(int)num;
sl@0
   417
		break;
sl@0
   418
	case BIO_C_SET_FD:
sl@0
   419
		b->init=1;
sl@0
   420
		b->num= *((int *)ptr);
sl@0
   421
		data->accept_sock=b->num;
sl@0
   422
		data->state=ACPT_S_GET_ACCEPT_SOCKET;
sl@0
   423
		b->shutdown=(int)num;
sl@0
   424
		b->init=1;
sl@0
   425
		break;
sl@0
   426
	case BIO_C_GET_FD:
sl@0
   427
		if (b->init)
sl@0
   428
			{
sl@0
   429
			ip=(int *)ptr;
sl@0
   430
			if (ip != NULL)
sl@0
   431
				*ip=data->accept_sock;
sl@0
   432
			ret=data->accept_sock;
sl@0
   433
			}
sl@0
   434
		else
sl@0
   435
			ret= -1;
sl@0
   436
		break;
sl@0
   437
	case BIO_C_GET_ACCEPT:
sl@0
   438
		if (b->init)
sl@0
   439
			{
sl@0
   440
			if (ptr != NULL)
sl@0
   441
				{
sl@0
   442
				pp=(char **)ptr;
sl@0
   443
				*pp=data->param_addr;
sl@0
   444
				}
sl@0
   445
			else
sl@0
   446
				ret= -1;
sl@0
   447
			}
sl@0
   448
		else
sl@0
   449
			ret= -1;
sl@0
   450
		break;
sl@0
   451
	case BIO_CTRL_GET_CLOSE:
sl@0
   452
		ret=b->shutdown;
sl@0
   453
		break;
sl@0
   454
	case BIO_CTRL_SET_CLOSE:
sl@0
   455
		b->shutdown=(int)num;
sl@0
   456
		break;
sl@0
   457
	case BIO_CTRL_PENDING:
sl@0
   458
	case BIO_CTRL_WPENDING:
sl@0
   459
		ret=0;
sl@0
   460
		break;
sl@0
   461
	case BIO_CTRL_FLUSH:
sl@0
   462
		break;
sl@0
   463
	case BIO_C_SET_BIND_MODE:
sl@0
   464
		data->bind_mode=(int)num;
sl@0
   465
		break;
sl@0
   466
	case BIO_C_GET_BIND_MODE:
sl@0
   467
		ret=(long)data->bind_mode;
sl@0
   468
		break;
sl@0
   469
	case BIO_CTRL_DUP:
sl@0
   470
		dbio=(BIO *)ptr;
sl@0
   471
/*		if (data->param_port) EAY EAY
sl@0
   472
			BIO_set_port(dbio,data->param_port);
sl@0
   473
		if (data->param_hostname)
sl@0
   474
			BIO_set_hostname(dbio,data->param_hostname);
sl@0
   475
		BIO_set_nbio(dbio,data->nbio); */
sl@0
   476
		break;
sl@0
   477
sl@0
   478
	default:
sl@0
   479
		ret=0;
sl@0
   480
		break;
sl@0
   481
		}
sl@0
   482
	return(ret);
sl@0
   483
	}
sl@0
   484
sl@0
   485
static int acpt_puts(BIO *bp, const char *str)
sl@0
   486
	{
sl@0
   487
	int n,ret;
sl@0
   488
sl@0
   489
	n=strlen(str);
sl@0
   490
	ret=acpt_write(bp,str,n);
sl@0
   491
	return(ret);
sl@0
   492
	}
sl@0
   493
sl@0
   494
EXPORT_C BIO *BIO_new_accept(char *str)
sl@0
   495
	{
sl@0
   496
	BIO *ret;
sl@0
   497
sl@0
   498
	ret=BIO_new(BIO_s_accept());
sl@0
   499
	if (ret == NULL) return(NULL);
sl@0
   500
	if (BIO_set_accept_port(ret,str))
sl@0
   501
		return(ret);
sl@0
   502
	else
sl@0
   503
		{
sl@0
   504
		BIO_free(ret);
sl@0
   505
		return(NULL);
sl@0
   506
		}
sl@0
   507
	}
sl@0
   508
sl@0
   509
#endif