- if (al == NULL)
- {
- logprintf (LOG_NOTQUIET,
- _("Unable to convert `%s' to a bind address. Reverting to ANY.\n"),
- opt.bind_address);
- }
- else
- bind_address_resolved = 1;
+/* Get the data of SA, specifically the IP address and the port. If
+ you're not interested in one or the other information, pass NULL as
+ the pointer. */
+
+void
+sockaddr_get_data (const struct sockaddr *sa, ip_address *ip, int *port)
+{
+ switch (sa->sa_family)
+ {
+ case AF_INET:
+ {
+ struct sockaddr_in *sin = (struct sockaddr_in *)sa;
+ if (ip)
+ {
+ ip->type = IPV4_ADDRESS;
+ ADDRESS_IPV4_IN_ADDR (ip) = sin->sin_addr;
+ }
+ if (port)
+ *port = ntohs (sin->sin_port);
+ break;
+ }
+#ifdef ENABLE_IPV6
+ case AF_INET6:
+ {
+ struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *)sa;
+ if (ip)
+ {
+ ip->type = IPV6_ADDRESS;
+ ADDRESS_IPV6_IN6_ADDR (ip) = sin6->sin6_addr;
+#ifdef HAVE_SOCKADDR_IN6_SCOPE_ID
+ ADDRESS_IPV6_SCOPE (ip) = sin6->sin6_scope_id;
+#endif
+ }
+ if (port)
+ *port = ntohs (sin6->sin6_port);
+ break;
+ }
+#endif
+ default:
+ abort ();