-/*
- * Address handling utilities
- */
-
-int
-addr_get_port(nsm_address *addr)
-{
- switch (((struct sockaddr *) addr)->sa_family) {
- case AF_INET:
- return ntohs(((struct sockaddr_in *) addr)->sin_port);
- case AF_INET6:
- return ntohs(((struct sockaddr_in6 *) addr)->sin6_port);
- }
- return 0;
-}
-
-static void
-addr_set_port(nsm_address *addr, int port)
-{
- switch (((struct sockaddr *) addr)->sa_family) {
- case AF_INET:
- ((struct sockaddr_in *) addr)->sin_port = htons(port);
- break;
- case AF_INET6:
- ((struct sockaddr_in6 *) addr)->sin6_port = htons(port);
- }
-}
-
-static int
-host_lookup(int af, const char *name, nsm_address *addr)
-{
- struct addrinfo hints, *ai;
- int okay = 0;
-
- memset(&hints, 0, sizeof(hints));
- hints.ai_family = af;
-
- if (getaddrinfo(name, NULL, &hints, &ai) != 0)
- return 0;
-
- if (ai->ai_addrlen < sizeof(*addr)) {
- memcpy(addr, ai->ai_addr, ai->ai_addrlen);
- okay = 1;
- }
-
- freeaddrinfo(ai);
- return okay;
-}
-