sock: replace sockaddr with sockaddr_storage

sockaddr structure may be insufficient to hold IPv6 address. Replace it
with sockaddr_storage structure.

Fixes #153.
This commit is contained in:
Dmitry Podgorny
2020-03-31 16:17:26 +03:00
parent c92fc849e7
commit 20c039fdb8

View File

@@ -212,17 +212,18 @@ int sock_is_recoverable(const int error)
int sock_connect_error(const sock_t sock) int sock_connect_error(const sock_t sock)
{ {
struct sockaddr sa; struct sockaddr_storage ss;
struct sockaddr *sa = (struct sockaddr *)&ss;
socklen_t len; socklen_t len;
char temp; char temp;
memset(&sa, 0, sizeof(sa)); memset(&ss, 0, sizeof(ss));
sa.sa_family = AF_UNSPEC; len = sizeof(ss);
len = sizeof(sa); sa->sa_family = AF_UNSPEC;
/* we don't actually care about the peer name, we're just checking if /* we don't actually care about the peer name, we're just checking if
* we're connected or not */ * we're connected or not */
if (getpeername(sock, &sa, &len) == 0) { if (getpeername(sock, sa, &len) == 0) {
return 0; return 0;
} }