int sz = sizeof(timeout);
if (getsockopt(b->num, SOL_SOCKET, SO_RCVTIMEO,
(void *)&timeout, &sz) < 0) {
- perror("getsockopt");
+ ERR_raise_data(ERR_LIB_SYS, get_last_socket_error(),
+ "calling getsockopt()");
} else {
data->socket_timeout.tv_sec = timeout / 1000;
data->socket_timeout.tv_usec = (timeout % 1000) * 1000;
# else
socklen_t sz = sizeof(data->socket_timeout);
if (getsockopt(b->num, SOL_SOCKET, SO_RCVTIMEO,
- &(data->socket_timeout), &sz) < 0) {
- perror("getsockopt");
- } else
+ &(data->socket_timeout), &sz) < 0)
+ ERR_raise_data(ERR_LIB_SYS, get_last_socket_error(),
+ "calling getsockopt()");
+ else
OPENSSL_assert(sz <= sizeof(data->socket_timeout));
# endif
# ifdef OPENSSL_SYS_WINDOWS
timeout = timeleft.tv_sec * 1000 + timeleft.tv_usec / 1000;
if (setsockopt(b->num, SOL_SOCKET, SO_RCVTIMEO,
- (void *)&timeout, sizeof(timeout)) < 0) {
- perror("setsockopt");
- }
+ (void *)&timeout, sizeof(timeout)) < 0)
+ ERR_raise_data(ERR_LIB_SYS, get_last_socket_error(),
+ "calling setsockopt()");
# else
if (setsockopt(b->num, SOL_SOCKET, SO_RCVTIMEO, &timeleft,
- sizeof(struct timeval)) < 0) {
- perror("setsockopt");
- }
+ sizeof(struct timeval)) < 0)
+ ERR_raise_data(ERR_LIB_SYS, get_last_socket_error(),
+ "calling setsockopt()");
# endif
}
}
int timeout = data->socket_timeout.tv_sec * 1000 +
data->socket_timeout.tv_usec / 1000;
if (setsockopt(b->num, SOL_SOCKET, SO_RCVTIMEO,
- (void *)&timeout, sizeof(timeout)) < 0) {
- perror("setsockopt");
- }
+ (void *)&timeout, sizeof(timeout)) < 0)
+ ERR_raise_data(ERR_LIB_SYS, get_last_socket_error(),
+ "calling setsockopt()");
# else
- if (setsockopt
- (b->num, SOL_SOCKET, SO_RCVTIMEO, &(data->socket_timeout),
- sizeof(struct timeval)) < 0) {
- perror("setsockopt");
- }
+ if (setsockopt(b->num, SOL_SOCKET, SO_RCVTIMEO,
+ &(data->socket_timeout), sizeof(struct timeval)) < 0)
+ ERR_raise_data(ERR_LIB_SYS, get_last_socket_error(),
+ "calling setsockopt()");
# endif
}
# endif
sockopt_val = IP_PMTUDISC_DO;
if ((ret = setsockopt(b->num, IPPROTO_IP, IP_MTU_DISCOVER,
&sockopt_val, sizeof(sockopt_val))) < 0)
- perror("setsockopt");
+ ERR_raise_data(ERR_LIB_SYS, get_last_socket_error(),
+ "calling setsockopt()");
break;
# if OPENSSL_USE_IPV6 && defined(IPV6_MTU_DISCOVER) && defined(IPV6_PMTUDISC_DO)
case AF_INET6:
sockopt_val = IPV6_PMTUDISC_DO;
if ((ret = setsockopt(b->num, IPPROTO_IPV6, IPV6_MTU_DISCOVER,
&sockopt_val, sizeof(sockopt_val))) < 0)
- perror("setsockopt");
+ ERR_raise_data(ERR_LIB_SYS, get_last_socket_error(),
+ "calling setsockopt()");
break;
# endif
default:
{
struct timeval *tv = (struct timeval *)ptr;
int timeout = tv->tv_sec * 1000 + tv->tv_usec / 1000;
- if (setsockopt(b->num, SOL_SOCKET, SO_RCVTIMEO,
- (void *)&timeout, sizeof(timeout)) < 0) {
- perror("setsockopt");
- ret = -1;
- }
+ if ((ret = setsockopt(b->num, SOL_SOCKET, SO_RCVTIMEO,
+ (void *)&timeout, sizeof(timeout))) < 0)
+ ERR_raise_data(ERR_LIB_SYS, get_last_socket_error(),
+ "calling setsockopt()");
}
# else
- if (setsockopt(b->num, SOL_SOCKET, SO_RCVTIMEO, ptr,
- sizeof(struct timeval)) < 0) {
- perror("setsockopt");
- ret = -1;
- }
+ if ((ret = setsockopt(b->num, SOL_SOCKET, SO_RCVTIMEO, ptr,
+ sizeof(struct timeval))) < 0)
+ ERR_raise_data(ERR_LIB_SYS, get_last_socket_error(),
+ "calling setsockopt()");
# endif
break;
case BIO_CTRL_DGRAM_GET_RECV_TIMEOUT:
struct timeval *tv = (struct timeval *)ptr;
sz = sizeof(timeout);
- if (getsockopt(b->num, SOL_SOCKET, SO_RCVTIMEO,
- (void *)&timeout, &sz) < 0) {
- perror("getsockopt");
- ret = -1;
+ if ((ret = getsockopt(b->num, SOL_SOCKET, SO_RCVTIMEO,
+ (void *)&timeout, &sz)) < 0) {
+ ERR_raise_data(ERR_LIB_SYS, get_last_socket_error(),
+ "calling getsockopt()");
} else {
tv->tv_sec = timeout / 1000;
tv->tv_usec = (timeout % 1000) * 1000;
}
# else
socklen_t sz = sizeof(struct timeval);
- if (getsockopt(b->num, SOL_SOCKET, SO_RCVTIMEO,
- ptr, &sz) < 0) {
- perror("getsockopt");
- ret = -1;
+ if ((ret = getsockopt(b->num, SOL_SOCKET, SO_RCVTIMEO,
+ ptr, &sz)) < 0) {
+ ERR_raise_data(ERR_LIB_SYS, get_last_socket_error(),
+ "calling getsockopt()");
} else {
OPENSSL_assert(sz <= sizeof(struct timeval));
ret = (int)sz;
{
struct timeval *tv = (struct timeval *)ptr;
int timeout = tv->tv_sec * 1000 + tv->tv_usec / 1000;
- if (setsockopt(b->num, SOL_SOCKET, SO_SNDTIMEO,
- (void *)&timeout, sizeof(timeout)) < 0) {
- perror("setsockopt");
- ret = -1;
- }
+
+ if ((ret = setsockopt(b->num, SOL_SOCKET, SO_SNDTIMEO,
+ (void *)&timeout, sizeof(timeout))) < 0)
+ ERR_raise_data(ERR_LIB_SYS, get_last_socket_error(),
+ "calling setsockopt()");
}
# else
- if (setsockopt(b->num, SOL_SOCKET, SO_SNDTIMEO, ptr,
- sizeof(struct timeval)) < 0) {
- perror("setsockopt");
- ret = -1;
- }
+ if ((ret = setsockopt(b->num, SOL_SOCKET, SO_SNDTIMEO, ptr,
+ sizeof(struct timeval))) < 0)
+ ERR_raise_data(ERR_LIB_SYS, get_last_socket_error(),
+ "calling setsockopt()");
# endif
break;
case BIO_CTRL_DGRAM_GET_SEND_TIMEOUT:
struct timeval *tv = (struct timeval *)ptr;
sz = sizeof(timeout);
- if (getsockopt(b->num, SOL_SOCKET, SO_SNDTIMEO,
- (void *)&timeout, &sz) < 0) {
- perror("getsockopt");
- ret = -1;
+ if ((ret = getsockopt(b->num, SOL_SOCKET, SO_SNDTIMEO,
+ (void *)&timeout, &sz)) < 0) {
+ ERR_raise_data(ERR_LIB_SYS, get_last_socket_error(),
+ "calling getsockopt()");
} else {
tv->tv_sec = timeout / 1000;
tv->tv_usec = (timeout % 1000) * 1000;
}
# else
socklen_t sz = sizeof(struct timeval);
- if (getsockopt(b->num, SOL_SOCKET, SO_SNDTIMEO,
- ptr, &sz) < 0) {
- perror("getsockopt");
- ret = -1;
+
+ if ((ret = getsockopt(b->num, SOL_SOCKET, SO_SNDTIMEO,
+ ptr, &sz)) < 0) {
+ ERR_raise_data(ERR_LIB_SYS, get_last_socket_error(),
+ "calling getsockopt()");
} else {
OPENSSL_assert(sz <= sizeof(struct timeval));
ret = (int)sz;
case AF_INET:
# if defined(IP_DONTFRAG)
if ((ret = setsockopt(b->num, IPPROTO_IP, IP_DONTFRAG,
- &sockopt_val, sizeof(sockopt_val))) < 0) {
- perror("setsockopt");
- ret = -1;
- }
+ &sockopt_val, sizeof(sockopt_val))) < 0)
+ ERR_raise_data(ERR_LIB_SYS, get_last_socket_error(),
+ "calling setsockopt()");
# elif defined(OPENSSL_SYS_LINUX) && defined(IP_MTU_DISCOVER) && defined (IP_PMTUDISC_PROBE)
if ((sockopt_val = num ? IP_PMTUDISC_PROBE : IP_PMTUDISC_DONT),
(ret = setsockopt(b->num, IPPROTO_IP, IP_MTU_DISCOVER,
- &sockopt_val, sizeof(sockopt_val))) < 0) {
- perror("setsockopt");
- ret = -1;
- }
+ &sockopt_val, sizeof(sockopt_val))) < 0)
+ ERR_raise_data(ERR_LIB_SYS, get_last_socket_error(),
+ "calling setsockopt()");
# elif defined(OPENSSL_SYS_WINDOWS) && defined(IP_DONTFRAGMENT)
if ((ret = setsockopt(b->num, IPPROTO_IP, IP_DONTFRAGMENT,
(const char *)&sockopt_val,
- sizeof(sockopt_val))) < 0) {
- perror("setsockopt");
- ret = -1;
- }
+ sizeof(sockopt_val))) < 0)
+ ERR_raise_data(ERR_LIB_SYS, get_last_socket_error(),
+ "calling setsockopt()");
# else
ret = -1;
# endif
# if defined(IPV6_DONTFRAG)
if ((ret = setsockopt(b->num, IPPROTO_IPV6, IPV6_DONTFRAG,
(const void *)&sockopt_val,
- sizeof(sockopt_val))) < 0) {
- perror("setsockopt");
- ret = -1;
- }
+ sizeof(sockopt_val))) < 0)
+ ERR_raise_data(ERR_LIB_SYS, get_last_socket_error(),
+ "calling setsockopt()");
+
# elif defined(OPENSSL_SYS_LINUX) && defined(IPV6_MTUDISCOVER)
if ((sockopt_val = num ? IP_PMTUDISC_PROBE : IP_PMTUDISC_DONT),
(ret = setsockopt(b->num, IPPROTO_IPV6, IPV6_MTU_DISCOVER,
- &sockopt_val, sizeof(sockopt_val))) < 0) {
- perror("setsockopt");
- ret = -1;
- }
+ &sockopt_val, sizeof(sockopt_val))) < 0)
+ ERR_raise_data(ERR_LIB_SYS, get_last_socket_error(),
+ "calling setsockopt()");
# else
ret = -1;
# endif
ret = 0;
break;
}
+ /* Normalize if error */
+ if (ret < 0)
+ ret = -1;
return ret;
}
t->tv_usec = ((int)(now_ul % 10000000)) / 10;
# else
if (gettimeofday(t, NULL) < 0)
- perror("gettimeofday");
+ ERR_raise_data(ERR_LIB_SYS, errno,
+ "calling gettimeofday");
+
# endif
}