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)
 {
diff --git a/lib/sockunion.h b/lib/sockunion.h
index b91c571..3613073 100644
--- a/lib/sockunion.h
+++ b/lib/sockunion.h
@@ -94,6 +94,7 @@
 extern size_t family2addrsize(int family);
 extern size_t sockunion_get_addrlen(const union sockunion *);
 extern const u_char *sockunion_get_addr(const union sockunion *);
+extern unsigned short sockunion_get_port (const union sockunion *);
 extern void sockunion_set(union sockunion *, int family, const u_char *addr, size_t bytes);
 
 extern union sockunion *sockunion_str2su (const char *str);