bio_sock.c and bss_dgram.c: update from HEAD.
PR: 2069
This commit is contained in:
parent
3e8e12a6b6
commit
e4572e5210
@ -822,7 +822,8 @@ int BIO_accept(int sock, char **addr)
|
|||||||
if (sizeof(sa.len.i)!=sizeof(sa.len.s) && sa.len.i==0)
|
if (sizeof(sa.len.i)!=sizeof(sa.len.s) && sa.len.i==0)
|
||||||
{
|
{
|
||||||
OPENSSL_assert(sa.len.s<=sizeof(sa.from));
|
OPENSSL_assert(sa.len.s<=sizeof(sa.from));
|
||||||
sa.len.i = (unsigned int)sa.len.s;
|
sa.len.i = (int)sa.len.s;
|
||||||
|
/* use sa.len.i from this point */
|
||||||
}
|
}
|
||||||
if (ret == INVALID_SOCKET)
|
if (ret == INVALID_SOCKET)
|
||||||
{
|
{
|
||||||
|
@ -108,11 +108,13 @@ static BIO_METHOD methods_dgramp=
|
|||||||
|
|
||||||
typedef struct bio_dgram_data_st
|
typedef struct bio_dgram_data_st
|
||||||
{
|
{
|
||||||
|
union {
|
||||||
|
struct sockaddr sa;
|
||||||
|
struct sockaddr_in sa_in;
|
||||||
#if OPENSSL_USE_IPV6
|
#if OPENSSL_USE_IPV6
|
||||||
struct sockaddr_storage peer;
|
struct sockaddr_in6 sa_in6;
|
||||||
#else
|
|
||||||
struct sockaddr_in peer;
|
|
||||||
#endif
|
#endif
|
||||||
|
} peer;
|
||||||
unsigned int connected;
|
unsigned int connected;
|
||||||
unsigned int _errno;
|
unsigned int _errno;
|
||||||
unsigned int mtu;
|
unsigned int mtu;
|
||||||
@ -278,28 +280,38 @@ static int dgram_read(BIO *b, char *out, int outl)
|
|||||||
int ret=0;
|
int ret=0;
|
||||||
bio_dgram_data *data = (bio_dgram_data *)b->ptr;
|
bio_dgram_data *data = (bio_dgram_data *)b->ptr;
|
||||||
|
|
||||||
|
struct {
|
||||||
|
/*
|
||||||
|
* See commentary in b_sock.c. <appro>
|
||||||
|
*/
|
||||||
|
union { size_t s; int i; } len;
|
||||||
|
union {
|
||||||
|
struct sockaddr sa;
|
||||||
|
struct sockaddr_in sa_in;
|
||||||
#if OPENSSL_USE_IPV6
|
#if OPENSSL_USE_IPV6
|
||||||
struct sockaddr_storage peer;
|
struct sockaddr_in6 sa_in6;
|
||||||
#else
|
|
||||||
struct sockaddr_in peer;
|
|
||||||
#endif
|
#endif
|
||||||
int peerlen = sizeof(peer);
|
} peer;
|
||||||
|
} sa;
|
||||||
|
|
||||||
|
sa.len.s=0;
|
||||||
|
sa.len.i=sizeof(sa.peer);
|
||||||
|
|
||||||
if (out != NULL)
|
if (out != NULL)
|
||||||
{
|
{
|
||||||
clear_socket_error();
|
clear_socket_error();
|
||||||
memset(&peer, 0x00, peerlen);
|
memset(&sa.peer, 0x00, sizeof(sa.peer));
|
||||||
/* Last arg in recvfrom is signed on some platforms and
|
|
||||||
* unsigned on others. It is of type socklen_t on some
|
|
||||||
* but this is not universal. Cast to (void *) to avoid
|
|
||||||
* compiler warnings.
|
|
||||||
*/
|
|
||||||
dgram_adjust_rcv_timeout(b);
|
dgram_adjust_rcv_timeout(b);
|
||||||
ret=recvfrom(b->num,out,outl,0,(struct sockaddr *)&peer,(void *)&peerlen);
|
ret=recvfrom(b->num,out,outl,0,&sa.peer.sa,(void *)&sa.len);
|
||||||
|
if (sizeof(sa.len.i)!=sizeof(sa.len.s) && sa.len.i==0)
|
||||||
|
{
|
||||||
|
OPENSSL_assert(sa.len.s<=sizeof(sa.peer));
|
||||||
|
sa.len.i = (int)sa.len.s;
|
||||||
|
}
|
||||||
dgram_reset_rcv_timeout(b);
|
dgram_reset_rcv_timeout(b);
|
||||||
|
|
||||||
if ( ! data->connected && ret >= 0)
|
if ( ! data->connected && ret >= 0)
|
||||||
BIO_ctrl(b, BIO_CTRL_DGRAM_SET_PEER, 0, &peer);
|
BIO_ctrl(b, BIO_CTRL_DGRAM_SET_PEER, 0, &sa.peer);
|
||||||
|
|
||||||
BIO_clear_retry_flags(b);
|
BIO_clear_retry_flags(b);
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
@ -323,25 +335,10 @@ static int dgram_write(BIO *b, const char *in, int inl)
|
|||||||
if ( data->connected )
|
if ( data->connected )
|
||||||
ret=writesocket(b->num,in,inl);
|
ret=writesocket(b->num,in,inl);
|
||||||
else
|
else
|
||||||
#if OPENSSL_USE_IPV6
|
|
||||||
if (data->peer.ss_family == AF_INET)
|
|
||||||
#if defined(NETWARE_CLIB) && defined(NETWARE_BSDSOCK)
|
#if defined(NETWARE_CLIB) && defined(NETWARE_BSDSOCK)
|
||||||
ret=sendto(b->num, (char *)in, inl, 0, (const struct sockaddr *)&data->peer, sizeof(struct sockaddr_in));
|
ret=sendto(b->num, (char *)in, inl, 0, &data->peer.sa, sizeof(data->peer));
|
||||||
#else
|
#else
|
||||||
ret=sendto(b->num, in, inl, 0, (const struct sockaddr *)&data->peer, sizeof(struct sockaddr_in));
|
ret=sendto(b->num, in, inl, 0, &data->peer.sa, sizeof(data->peer));
|
||||||
#endif
|
|
||||||
else
|
|
||||||
#if defined(NETWARE_CLIB) && defined(NETWARE_BSDSOCK)
|
|
||||||
ret=sendto(b->num, (char *)in, inl, 0, (const struct sockaddr *)&data->peer, sizeof(struct sockaddr_in6));
|
|
||||||
#else
|
|
||||||
ret=sendto(b->num, in, inl, 0, (const struct sockaddr *)&data->peer, sizeof(struct sockaddr_in6));
|
|
||||||
#endif
|
|
||||||
#else
|
|
||||||
#if defined(NETWARE_CLIB) && defined(NETWARE_BSDSOCK)
|
|
||||||
ret=sendto(b->num, (char *)in, inl, 0, (const struct sockaddr *)&data->peer, sizeof(struct sockaddr_in));
|
|
||||||
#else
|
|
||||||
ret=sendto(b->num, in, inl, 0, (const struct sockaddr *)&data->peer, sizeof(struct sockaddr_in));
|
|
||||||
#endif
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
BIO_clear_retry_flags(b);
|
BIO_clear_retry_flags(b);
|
||||||
@ -428,11 +425,20 @@ static long dgram_ctrl(BIO *b, int cmd, long num, void *ptr)
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
#endif
|
#endif
|
||||||
|
switch (to->sa_family)
|
||||||
|
{
|
||||||
|
case AF_INET:
|
||||||
|
memcpy(&data->peer,to,sizeof(data->peer.sa_in));
|
||||||
|
break;
|
||||||
#if OPENSSL_USE_IPV6
|
#if OPENSSL_USE_IPV6
|
||||||
memcpy(&(data->peer),to, sizeof(struct sockaddr_storage));
|
case AF_INET6:
|
||||||
#else
|
memcpy(&data->peer,to,sizeof(data->peer.sa_in6));
|
||||||
memcpy(&(data->peer),to, sizeof(struct sockaddr_in));
|
break;
|
||||||
#endif
|
#endif
|
||||||
|
default:
|
||||||
|
memcpy(&data->peer,to,sizeof(data->peer.sa));
|
||||||
|
break;
|
||||||
|
}
|
||||||
#if 0
|
#if 0
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
@ -537,41 +543,60 @@ static long dgram_ctrl(BIO *b, int cmd, long num, void *ptr)
|
|||||||
if ( to != NULL)
|
if ( to != NULL)
|
||||||
{
|
{
|
||||||
data->connected = 1;
|
data->connected = 1;
|
||||||
|
switch (to->sa_family)
|
||||||
|
{
|
||||||
|
case AF_INET:
|
||||||
|
memcpy(&data->peer,to,sizeof(data->peer.sa_in));
|
||||||
|
break;
|
||||||
#if OPENSSL_USE_IPV6
|
#if OPENSSL_USE_IPV6
|
||||||
memcpy(&(data->peer),to, sizeof(struct sockaddr_storage));
|
case AF_INET6:
|
||||||
#else
|
memcpy(&data->peer,to,sizeof(data->peer.sa_in6));
|
||||||
memcpy(&(data->peer),to, sizeof(struct sockaddr_in));
|
break;
|
||||||
#endif
|
#endif
|
||||||
|
default:
|
||||||
|
memcpy(&data->peer,to,sizeof(data->peer.sa));
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
data->connected = 0;
|
data->connected = 0;
|
||||||
#if OPENSSL_USE_IPV6
|
memset(&(data->peer), 0x00, sizeof(data->peer));
|
||||||
memset(&(data->peer), 0x00, sizeof(struct sockaddr_storage));
|
|
||||||
#else
|
|
||||||
memset(&(data->peer), 0x00, sizeof(struct sockaddr_in));
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case BIO_CTRL_DGRAM_GET_PEER:
|
case BIO_CTRL_DGRAM_GET_PEER:
|
||||||
to = (struct sockaddr *) ptr;
|
to = (struct sockaddr *) ptr;
|
||||||
|
switch (to->sa_family)
|
||||||
|
{
|
||||||
|
case AF_INET:
|
||||||
|
memcpy(to,&data->peer,(ret=sizeof(data->peer.sa_in)));
|
||||||
|
break;
|
||||||
#if OPENSSL_USE_IPV6
|
#if OPENSSL_USE_IPV6
|
||||||
memcpy(to, &(data->peer), sizeof(struct sockaddr_storage));
|
case AF_INET6:
|
||||||
ret = sizeof(struct sockaddr_storage);
|
memcpy(to,&data->peer,(ret=sizeof(data->peer.sa_in6)));
|
||||||
#else
|
break;
|
||||||
memcpy(to, &(data->peer), sizeof(struct sockaddr_in));
|
|
||||||
ret = sizeof(struct sockaddr_in);
|
|
||||||
#endif
|
#endif
|
||||||
|
default:
|
||||||
|
memcpy(to,&data->peer,(ret=sizeof(data->peer.sa)));
|
||||||
|
break;
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
case BIO_CTRL_DGRAM_SET_PEER:
|
case BIO_CTRL_DGRAM_SET_PEER:
|
||||||
to = (struct sockaddr *) ptr;
|
to = (struct sockaddr *) ptr;
|
||||||
|
switch (to->sa_family)
|
||||||
|
{
|
||||||
|
case AF_INET:
|
||||||
|
memcpy(&data->peer,to,sizeof(data->peer.sa_in));
|
||||||
|
break;
|
||||||
#if OPENSSL_USE_IPV6
|
#if OPENSSL_USE_IPV6
|
||||||
memcpy(&(data->peer), to, sizeof(struct sockaddr_storage));
|
case AF_INET6:
|
||||||
#else
|
memcpy(&data->peer,to,sizeof(data->peer.sa_in6));
|
||||||
memcpy(&(data->peer), to, sizeof(struct sockaddr_in));
|
break;
|
||||||
#endif
|
#endif
|
||||||
|
default:
|
||||||
|
memcpy(&data->peer,to,sizeof(data->peer.sa));
|
||||||
|
break;
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
case BIO_CTRL_DGRAM_SET_NEXT_TIMEOUT:
|
case BIO_CTRL_DGRAM_SET_NEXT_TIMEOUT:
|
||||||
memcpy(&(data->next_timeout), ptr, sizeof(struct timeval));
|
memcpy(&(data->next_timeout), ptr, sizeof(struct timeval));
|
||||||
|
Loading…
Reference in New Issue
Block a user