-/*
- look up the name associated with the ip
- address `addr'
-*/
-char *hostlookup(unsigned long addr)
-{
- char *name;
- struct hostent *host = NULL;
- struct in_addr in;
-cp
- in.s_addr = addr;
-
- host = gethostbyaddr((char *)&in, sizeof(in), AF_INET);
-
- if(host)
- {
- name = xmalloc(strlen(host->h_name)+20);
- sprintf(name, "%s (%s)", host->h_name, inet_ntoa(in));
- }
- else
- {
- name = xmalloc(20);
- sprintf(name, "%s", inet_ntoa(in));
- }
-cp
- return name;
+int sockaddrcmp(const sockaddr_t *a, const sockaddr_t *b) {
+ int result;
+
+ result = a->sa.sa_family - b->sa.sa_family;
+
+ if(result)
+ return result;
+
+ switch (a->sa.sa_family) {
+ case AF_UNSPEC:
+ return 0;
+
+ case AF_UNKNOWN:
+ result = strcmp(a->unknown.address, b->unknown.address);
+
+ if(result)
+ return result;
+
+ return strcmp(a->unknown.port, b->unknown.port);
+
+ case AF_INET:
+ result = memcmp(&a->in.sin_addr, &b->in.sin_addr, sizeof a->in.sin_addr);
+
+ if(result)
+ return result;
+
+ return memcmp(&a->in.sin_port, &b->in.sin_port, sizeof a->in.sin_port);
+
+ case AF_INET6:
+ result = memcmp(&a->in6.sin6_addr, &b->in6.sin6_addr, sizeof a->in6.sin6_addr);
+
+ if(result)
+ return result;
+
+ return memcmp(&a->in6.sin6_port, &b->in6.sin6_port, sizeof a->in6.sin6_port);
+
+ default:
+ logger(DEBUG_ALWAYS, LOG_ERR, "sockaddrcmp() was called with unknown address family %d, exitting!",
+ a->sa.sa_family);
+ abort();
+ }