BIOerr(BIO_F_CONN_STATE,BIO_R_NO_HOSTHNAME_SPECIFIED);
BIOerr(BIO_F_CONN_STATE,BIO_R_NO_HOSTNAME_SPECIFIED);
static int conn_state(b,c)BIO *b;BIO_CONNECT *c;	{	int ret= -1,i;	unsigned long l;	char *p,*q;	int (*cb)()=NULL;	if (c->info_callback != NULL)		cb=c->info_callback;	for (;;)		{		switch (c->state)			{		case BIO_CONN_S_BEFORE:			p=c->param_hostname;			if (p == NULL)				{				BIOerr(BIO_F_CONN_STATE,BIO_R_NO_HOSTHNAME_SPECIFIED);				goto exit_loop;				}			for ( ; *p != '\0'; p++)				{				if ((*p == ':') || (*p == '/')) break;				}			i= *p;			if ((i == ':') || (i == '/'))				{				*(p++)='\0';				if (i == ':')					{					for (q=p; *q; q++)						if (*q == '/')							{							*q='\0';							break;							}					if (c->param_port != NULL)						Free(c->param_port);					c->param_port=BUF_strdup(p);					}				}			if (c->param_port == NULL)				{				BIOerr(BIO_F_CONN_STATE,BIO_R_NO_PORT_SPECIFIED);				ERR_add_error_data(2,"host=",c->param_hostname);				goto exit_loop;				}			c->state=BIO_CONN_S_GET_IP;			break;		case BIO_CONN_S_GET_IP:			if (BIO_get_host_ip(c->param_hostname,&(c->ip[0])) <= 0)				goto exit_loop;			c->state=BIO_CONN_S_GET_PORT;			break;		case BIO_CONN_S_GET_PORT:			if (c->param_port == NULL)				{				abort();				goto exit_loop;				}			else if (BIO_get_port(c->param_port,&c->port) <= 0)				goto exit_loop;			c->state=BIO_CONN_S_CREATE_SOCKET;			break;		case BIO_CONN_S_CREATE_SOCKET:			/* now setup address */			memset((char *)&c->them,0,sizeof(c->them));			c->them.sin_family=AF_INET;			c->them.sin_port=htons((unsigned short)c->port);			l=(unsigned long)				((unsigned long)c->ip[0]<<24L)|				((unsigned long)c->ip[1]<<16L)|				((unsigned long)c->ip[2]<< 8L)|				((unsigned long)c->ip[3]);			c->them.sin_addr.s_addr=htonl(l);			c->state=BIO_CONN_S_CREATE_SOCKET;			ret=socket(AF_INET,SOCK_STREAM,SOCKET_PROTOCOL);			if (ret == INVALID_SOCKET)				{				SYSerr(SYS_F_SOCKET,get_last_socket_error());				ERR_add_error_data(4,"host=",c->param_hostname,					":",c->param_port);				BIOerr(BIO_F_CONN_STATE,BIO_R_UNABLE_TO_CREATE_SOCKET);				goto exit_loop;				}			b->num=ret;			c->state=BIO_CONN_S_NBIO;			break;		case BIO_CONN_S_NBIO:			if (c->nbio)				{				if (!BIO_socket_nbio(b->num,1))					{					BIOerr(BIO_F_CONN_STATE,BIO_R_ERROR_SETTING_NBIO);					ERR_add_error_data(4,"host=",						c->param_hostname,						":",c->param_port);					goto exit_loop;					}				}			c->state=BIO_CONN_S_CONNECT;#ifdef SO_KEEPALIVE			i=1;			i=setsockopt(b->num,SOL_SOCKET,SO_KEEPALIVE,(char *)&i,sizeof(i));			if (i < 0)				{				SYSerr(SYS_F_SOCKET,get_last_socket_error());				ERR_add_error_data(4,"host=",c->param_hostname,					":",c->param_port);				BIOerr(BIO_F_CONN_STATE,BIO_R_KEEPALIVE);				goto exit_loop;				}#endif			break;		case BIO_CONN_S_CONNECT:			BIO_clear_retry_flags(b);			ret=connect(b->num,				(struct sockaddr *)&c->them,				sizeof(c->them));			b->retry_reason=0;			if (ret < 0)				{				if (BIO_sock_should_retry(ret))					{					BIO_set_retry_special(b);					c->state=BIO_CONN_S_BLOCKED_CONNECT;					b->retry_reason=BIO_RR_CONNECT;					}				else					{					SYSerr(SYS_F_CONNECT,get_last_socket_error());					ERR_add_error_data(4,"host=",						c->param_hostname,						":",c->param_port);					BIOerr(BIO_F_CONN_STATE,BIO_R_CONNECT_ERROR);					}				goto exit_loop;				}			else				c->state=BIO_CONN_S_OK;			break;		case BIO_CONN_S_BLOCKED_CONNECT:			i=BIO_sock_error(b->num);			if (i)				{				BIO_clear_retry_flags(b);				SYSerr(SYS_F_CONNECT,i);				ERR_add_error_data(4,"host=",					c->param_hostname,					":",c->param_port);				BIOerr(BIO_F_CONN_STATE,BIO_R_NBIO_CONNECT_ERROR);				ret=0;				goto exit_loop;				}			else				c->state=BIO_CONN_S_OK;			break;		case BIO_CONN_S_OK:			ret=1;			goto exit_loop;		default:			abort();			goto exit_loop;			}		if (cb != NULL)			{			if (!(ret=cb((BIO *)b,c->state,ret)))				goto end;			}		}	/* Loop does not exit */exit_loop:	if (cb != NULL)		ret=cb((BIO *)b,c->state,ret);end:	return(ret);	}