Comparing address/port number If you want to be pedant... getnameinfo(), then compare string If you just want to support IPv4/v6 switch-case and typecast But we can't support address families we don't know about if (sa1->sa_len != sa2->sa_len) return 0; if (getnameinfo(sa1, sa1->sa_len, h1, sizeof(h1), NULL, 0, NI_NUMERICHOST), 0) != 0) return 0; if (getnameinfo(sa2, sa2->sa_len, h2, sizeof(h2), NULL, 0, NI_NUMERICHOST), 0) != 0) return 0; if (strcmp(h1, h2) == 0) return 1; else return 0;