Address/port number comparison If you want to touch AF dependent members of sockaddr_* convert to text format by getnameinfo(), compare as strings. If you allow to touch AF dependent members nothing should be changed, although you should specify all possible cases. if (sa1->sa_len != sa2->sa_len) return 0; /* different */ if (getnameinfo(sa1, sa1->sa_len, h1, sizeof(h1), NULL, 0, NI_NUMERICHOST) != 0) return -1; /* error */ if (getnameinfo(sa2, sa2->sa_len, h2, sizeof(h2), NULL, 0, NI_NUMERICHOST) != 0) return -1; /* error */ if (strcmp(h1, h2) == 0) return 1; /* same */ else return 0; /* different */