From: RĂ©mi Denis-Courmont Date: Sat, 10 Feb 2007 12:18:05 +0000 (+0000) Subject: net_GetPort() returns network-byte order port number from an address X-Git-Tag: 0.9.0-test0~8669 X-Git-Url: https://git.sesse.net/?a=commitdiff_plain;h=4c858d7e9c751951907ea9525692368f4d484957;p=vlc net_GetPort() returns network-byte order port number from an address --- diff --git a/include/vlc_network.h b/include/vlc_network.h index 946960d5be..bece596243 100644 --- a/include/vlc_network.h +++ b/include/vlc_network.h @@ -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