I mean, which fields of struct sockaddr should I compare when I check whether two struct sockaddr\'s have the same ip address and port number? And what
First you need to check the family (IPv4, IPv6, or other). Then you can cast each sockaddr to the appropriate "derived" type like sockaddr_in. See how Apple does it here: http://www.opensource.apple.com/source/postfix/postfix-197/postfix/src/util/sock_addr.c