File: sa_compare.cpp

package info (click to toggle)
cubemap 1.3.2-1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 428 kB
  • sloc: cpp: 4,431; sh: 114; perl: 102; makefile: 60
file content (17 lines) | stat: -rw-r--r-- 437 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
#include "sa_compare.h"

#include <arpa/inet.h>
#include <assert.h>
#include <string.h>

bool Sockaddr6Compare::operator() (const sockaddr_in6 &a, const sockaddr_in6 &b) const
{
	assert(a.sin6_family == AF_INET6);
	assert(b.sin6_family == AF_INET6);
	int addr_cmp = memcmp(&a.sin6_addr, &b.sin6_addr, sizeof(a.sin6_addr));
	if (addr_cmp == 0) {
		return (ntohs(a.sin6_port) < ntohs(b.sin6_port));
	} else {
		return (addr_cmp < 0);
	}
}