+/*
+ * Address handling utilities
+ */
+
+static unsigned short smn_get_port(const struct sockaddr *sap)
+{
+ switch (sap->sa_family) {
+ case AF_INET:
+ return ntohs(((struct sockaddr_in *)sap)->sin_port);
+ case AF_INET6:
+ return ntohs(((struct sockaddr_in6 *)sap)->sin6_port);
+ }
+ return 0;
+}
+
+static void smn_set_port(struct sockaddr *sap, const unsigned short port)
+{
+ switch (sap->sa_family) {
+ case AF_INET:
+ ((struct sockaddr_in *)sap)->sin_port = htons(port);
+ break;
+ case AF_INET6:
+ ((struct sockaddr_in6 *)sap)->sin6_port = htons(port);
+ break;
+ }
+}
+
+static struct addrinfo *smn_lookup(const sa_family_t family, const char *name)
+{
+ struct addrinfo *ai, hint = {
+ .ai_family = family,
+ .ai_protocol = IPPROTO_UDP,
+ };
+
+ if (getaddrinfo(name, NULL, &hint, &ai) != 0)
+ return NULL;
+
+ return ai;
+}
+
+static void smn_forget_host(struct nsm_host *host)
+{
+ unlink(host->path);
+ free(host->path);
+ free(host->name);
+ if (host->ai)
+ freeaddrinfo(host->ai);
+
+ free(host);
+}
+