DTLS IO and cookie callbacks are IPv4/IPv6 agnostic.
This commit is contained in:
parent
420ca9e6e3
commit
7b04b7ab84
21
src/io.c
21
src/io.c
@ -352,7 +352,7 @@ int EmbedReceiveFrom(CYASSL *ssl, char *buf, int sz, void *ctx)
|
||||
int err;
|
||||
int sd = dtlsCtx->fd;
|
||||
int dtls_timeout = CyaSSL_dtls_get_current_timeout(ssl);
|
||||
struct sockaddr_in6 peer;
|
||||
struct sockaddr_storage peer;
|
||||
XSOCKLENT peerSz = sizeof(peer);
|
||||
|
||||
CYASSL_ENTER("EmbedReceiveFrom()");
|
||||
@ -471,34 +471,21 @@ int EmbedSendTo(CYASSL* ssl, char *buf, int sz, void *ctx)
|
||||
int EmbedGenerateCookie(CYASSL* ssl, byte *buf, int sz, void *ctx)
|
||||
{
|
||||
int sd = ssl->wfd;
|
||||
struct sockaddr_in6 peer;
|
||||
struct sockaddr_storage peer;
|
||||
XSOCKLENT peerSz = sizeof(peer);
|
||||
Sha sha;
|
||||
byte digest[SHA_DIGEST_SIZE];
|
||||
|
||||
(void)ctx;
|
||||
|
||||
XMEMSET(&peer, 0, sizeof(peer));
|
||||
if (getpeername(sd, (struct sockaddr*)&peer, &peerSz) != 0) {
|
||||
CYASSL_MSG("getpeername failed in EmbedGenerateCookie");
|
||||
return GEN_COOKIE_E;
|
||||
}
|
||||
|
||||
InitSha(&sha);
|
||||
|
||||
if (peer.sin6_family == AF_INET6) {
|
||||
ShaUpdate(&sha, (byte*)&peer.sin6_port, sizeof(peer.sin6_port));
|
||||
ShaUpdate(&sha, (byte*)&peer.sin6_addr, sizeof(peer.sin6_addr));
|
||||
}
|
||||
else if (peer.sin6_family == AF_INET) {
|
||||
struct sockaddr_in *s = (struct sockaddr_in*)&peer;
|
||||
ShaUpdate(&sha, (byte*)&s->sin_port, sizeof(s->sin_port));
|
||||
ShaUpdate(&sha, (byte*)&s->sin_addr, sizeof(s->sin_addr));
|
||||
}
|
||||
else {
|
||||
CYASSL_MSG("peer sin_family unknown type in EmbedGenerateCookie");
|
||||
return GEN_COOKIE_E;
|
||||
}
|
||||
|
||||
ShaUpdate(&sha, (byte*)&peer, peerSz);
|
||||
ShaFinal(&sha, digest);
|
||||
|
||||
if (sz > SHA_DIGEST_SIZE)
|
||||
|
Loading…
Reference in New Issue
Block a user