lib: Add a trivial sockunion_get_port helper function
diff --git a/lib/sockunion.c b/lib/sockunion.c
index 4a22c63..8e0ec24 100644
--- a/lib/sockunion.c
+++ b/lib/sockunion.c
@@ -632,6 +632,21 @@
   return NULL;
 }
 
+unsigned short
+sockunion_get_port (const union sockunion *su)
+{
+  switch (sockunion_family (su))
+    {
+    case AF_INET:
+      return ntohs(su->sin.sin_port);
+#ifdef HAVE_IPV6
+    case AF_INET6:
+      return ntohs(su->sin6.sin6_port);
+#endif /* HAVE_IPV6 */
+    }
+  return 0;
+}
+
 void
 sockunion_set(union sockunion *su, int family, const u_char *addr, size_t bytes)
 {