Skip to content

Commit

Permalink
sock: replace sockaddr with sockaddr_storage
Browse files Browse the repository at this point in the history
sockaddr structure may be insufficient to hold IPv6 address. Replace it
with sockaddr_storage structure.

Fixes #153.
  • Loading branch information
pasis committed Mar 31, 2020
1 parent c92fc84 commit 20c039f
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions src/sock.c
Expand Up @@ -212,17 +212,18 @@ int sock_is_recoverable(const int error)

int sock_connect_error(const sock_t sock)
{
struct sockaddr sa;
struct sockaddr_storage ss;
struct sockaddr *sa = (struct sockaddr *)&ss;
socklen_t len;
char temp;

memset(&sa, 0, sizeof(sa));
sa.sa_family = AF_UNSPEC;
len = sizeof(sa);
memset(&ss, 0, sizeof(ss));
len = sizeof(ss);
sa->sa_family = AF_UNSPEC;

/* we don't actually care about the peer name, we're just checking if
* we're connected or not */
if (getpeername(sock, &sa, &len) == 0) {
if (getpeername(sock, sa, &len) == 0) {
return 0;
}

Expand Down

0 comments on commit 20c039f

Please sign in to comment.