]> git.sesse.net Git - vlc/commitdiff
net_GetPort() returns network-byte order port number from an address
authorRémi Denis-Courmont <rem@videolan.org>
Sat, 10 Feb 2007 12:18:05 +0000 (12:18 +0000)
committerRémi Denis-Courmont <rem@videolan.org>
Sat, 10 Feb 2007 12:18:05 +0000 (12:18 +0000)
include/vlc_network.h

index 946960d5beed00f95150343e551c0e31f429fcf0..bece596243b2b556c8eaca4f17c5eb9fc71e80ca 100644 (file)
@@ -317,6 +317,20 @@ static inline int net_GetPeerAddress( int fd, char *address, int *port )
         ? VLC_EGENERIC : 0;
 }
 
+static inline uint16_t net_GetPort (const struct sockaddr *addr)
+{
+    switch (addr->sa_family)
+    {
+#ifdef AF_INET6
+        case AF_INET6:
+            return ((const struct sockaddr_in6 *)addr)->sin6_port;
+#endif
+        case AF_INET:
+            return ((const struct sockaddr_in *)addr)->sin_port;
+    }
+    return 0;
+}
+
 # ifdef __cplusplus
 }
 # endif