socket-util: introduce port argument in sockaddr_port()

sockaddr_port() either returns a >= 0 port number or a negative errno.
This works for AF_INET and AF_INET6 because port ranges are only 16-bit.

In AF_VSOCK ports are 32-bit so an int cannot represent all port number
and negative errnos.  Separate the port and the return code.
This commit is contained in:
Stefan Hajnoczi
2017-01-10 15:29:04 +00:00
parent 4e0399e69b
commit 882ac6e769
3 changed files with 8 additions and 7 deletions
+1 -1
View File
@@ -100,7 +100,7 @@ const char* socket_address_get_path(const SocketAddress *a);
bool socket_ipv6_is_supported(void);
int sockaddr_port(const struct sockaddr *_sa) _pure_;
int sockaddr_port(const struct sockaddr *_sa, unsigned *port) _pure_;
int sockaddr_pretty(const struct sockaddr *_sa, socklen_t salen, bool translate_ipv6, bool include_port, char **ret);
int getpeername_pretty(int fd, bool include_port, char **ret);