{
unsigned char *buffer, result[EVP_MAX_MD_SIZE];
unsigned int length, resultlength;
-#if OPENSSL_USE_IPV6
union {
- struct sockaddr_storage ss;
- struct sockaddr_in6 s6;
+ struct sockaddr sa;
struct sockaddr_in s4;
- } peer;
-#else
- struct sockaddr_in peer;
+#if OPENSSL_USE_IPV6
+ struct sockaddr_in6 s6;
#endif
+ } peer;
/* Initialize a random secret */
if (!cookie_initialized)
(void)BIO_dgram_get_peer(SSL_get_rbio(ssl), &peer);
/* Create buffer with peer's address and port */
-#if OPENSSL_USE_IPV6
length = 0;
- switch (peer.ss.ss_family)
+ switch (peer.sa.sa_family)
{
case AF_INET:
length += sizeof(struct in_addr);
length += sizeof(peer.s4.sin_port);
break;
+#if OPENSSL_USE_IPV6
case AF_INET6:
length += sizeof(struct in6_addr);
length += sizeof(peer.s6.sin6_port);
break;
+#endif
default:
OPENSSL_assert(0);
break;
}
-#else
- length = sizeof(peer.sin_addr);
- length += sizeof(peer.sin_port);
-#endif
buffer = OPENSSL_malloc(length);
if (buffer == NULL)
return 0;
}
-#if OPENSSL_USE_IPV6
- switch (peer.ss.ss_family)
+ switch (peer.sa.sa_family)
{
case AF_INET:
memcpy(buffer,
&peer.s4.sin_addr,
sizeof(struct in_addr));
break;
+#if OPENSSL_USE_IPV6
case AF_INET6:
memcpy(buffer,
&peer.s6.sin6_port,
&peer.s6.sin6_addr,
sizeof(struct in6_addr));
break;
+#endif
default:
OPENSSL_assert(0);
break;
}
-#else
- memcpy(buffer, &peer.sin_port, sizeof(peer.sin_port));
- memcpy(buffer + sizeof(peer.sin_port), &peer.sin_addr, sizeof(peer.sin_addr));
-#endif
/* Calculate HMAC of buffer using the secret */
HMAC(EVP_sha1(), cookie_secret, COOKIE_SECRET_LENGTH,
{
unsigned char *buffer, result[EVP_MAX_MD_SIZE];
unsigned int length, resultlength;
-#if OPENSSL_USE_IPV6
union {
- struct sockaddr_storage ss;
- struct sockaddr_in6 s6;
+ struct sockaddr sa;
struct sockaddr_in s4;
- } peer;
-#else
- struct sockaddr_in peer;
+#if OPENSSL_USE_IPV6
+ struct sockaddr_in6 s6;
#endif
+ } peer;
/* If secret isn't initialized yet, the cookie can't be valid */
if (!cookie_initialized)
(void)BIO_dgram_get_peer(SSL_get_rbio(ssl), &peer);
/* Create buffer with peer's address and port */
-#if OPENSSL_USE_IPV6
length = 0;
- switch (peer.ss.ss_family)
+ switch (peer.sa.sa_family)
{
case AF_INET:
length += sizeof(struct in_addr);
length += sizeof(peer.s4.sin_port);
break;
+#if OPENSSL_USE_IPV6
case AF_INET6:
length += sizeof(struct in6_addr);
length += sizeof(peer.s6.sin6_port);
break;
+#endif
default:
OPENSSL_assert(0);
break;
}
-#else
- length = sizeof(peer.sin_addr);
- length += sizeof(peer.sin_port);
-#endif
buffer = OPENSSL_malloc(length);
if (buffer == NULL)
return 0;
}
-#if OPENSSL_USE_IPV6
- switch (peer.ss.ss_family)
+ switch (peer.sa.sa_family)
{
case AF_INET:
memcpy(buffer,
&peer.s4.sin_addr,
sizeof(struct in_addr));
break;
+#if OPENSSL_USE_IPV6
case AF_INET6:
memcpy(buffer,
&peer.s6.sin6_port,
&peer.s6.sin6_addr,
sizeof(struct in6_addr));
break;
+#endif
default:
OPENSSL_assert(0);
break;
}
-#else
- memcpy(buffer, &peer.sin_port, sizeof(peer.sin_port));
- memcpy(buffer + sizeof(peer.sin_port), &peer.sin_addr, sizeof(peer.sin_addr));
-#endif
/* Calculate HMAC of buffer using the secret */
HMAC(EVP_sha1(), cookie_secret, COOKIE_SECRET_LENGTH,
#endif
#ifdef OPENSSL_SYS_LINUX
socklen_t addr_len;
- struct sockaddr_storage addr;
+ union {
+ struct sockaddr sa;
+ struct sockaddr_in s4;
+#if OPENSSL_USE_IPV6
+ struct sockaddr_in6 s6;
+#endif
+ } addr;
#endif
data = (bio_dgram_data *)b->ptr;
/* (Linux)kernel sets DF bit on outgoing IP packets */
case BIO_CTRL_DGRAM_MTU_DISCOVER:
#ifdef OPENSSL_SYS_LINUX
- addr_len = (socklen_t)sizeof(struct sockaddr_storage);
- memset((void *)&addr, 0, sizeof(struct sockaddr_storage));
- if (getsockname(b->num, (void *)&addr, &addr_len) < 0)
+ addr_len = (socklen_t)sizeof(addr);
+ memset((void *)&addr, 0, sizeof(addr));
+ if (getsockname(b->num, &addr.sa, &addr_len) < 0)
{
ret = 0;
break;
}
sockopt_len = sizeof(sockopt_val);
- switch (addr.ss_family)
+ switch (addr.sa.sa_family)
{
case AF_INET:
sockopt_val = IP_PMTUDISC_DO;
&sockopt_val, sizeof(sockopt_val))) < 0)
perror("setsockopt");
break;
-#if OPENSSL_USE_IPV6
+#if OPENSSL_USE_IPV6 && defined(IPV6_MTU_DISCOVER)
case AF_INET6:
sockopt_val = IPV6_PMTUDISC_DO;
if ((ret = setsockopt(b->num, IPPROTO_IPV6, IPV6_MTU_DISCOVER,
#endif
case BIO_CTRL_DGRAM_QUERY_MTU:
#ifdef OPENSSL_SYS_LINUX
- addr_len = (socklen_t)sizeof(struct sockaddr_storage);
- memset((void *)&addr, 0, sizeof(struct sockaddr_storage));
- if (getsockname(b->num, (void *)&addr, &addr_len) < 0)
+ addr_len = (socklen_t)sizeof(addr);
+ memset((void *)&addr, 0, sizeof(addr));
+ if (getsockname(b->num, &addr.sa, &addr_len) < 0)
{
ret = 0;
break;
}
sockopt_len = sizeof(sockopt_val);
- switch (addr.ss_family)
+ switch (addr.sa.sa_family)
{
case AF_INET:
if ((ret = getsockopt(b->num, IPPROTO_IP, IP_MTU, (void *)&sockopt_val,
ret = data->mtu;
}
break;
-#if OPENSSL_USE_IPV6
+#if OPENSSL_USE_IPV6 && defined(IPV6_MTU)
case AF_INET6:
if ((ret = getsockopt(b->num, IPPROTO_IPV6, IPV6_MTU, (void *)&sockopt_val,
&sockopt_len)) < 0 || sockopt_val < 0)