mirror of
https://gitlab.isc.org/isc-projects/bind9
synced 2025-08-31 06:25:31 +00:00
added isc_sockaddr_getport
This commit is contained in:
@@ -83,6 +83,12 @@ isc_sockaddr_setport(isc_sockaddr_t *sockaddr, in_port_t port);
|
||||
* Set the port of 'sockaddr' to 'port'.
|
||||
*/
|
||||
|
||||
in_port_t
|
||||
isc_sockaddr_getport(isc_sockaddr_t *sockaddr);
|
||||
/*
|
||||
* Get the port stored in 'sockaddr'.
|
||||
*/
|
||||
|
||||
isc_result_t
|
||||
isc_sockaddr_totext(const isc_sockaddr_t *sockaddr, isc_buffer_t *target);
|
||||
/*
|
||||
|
@@ -337,3 +337,21 @@ isc_sockaddr_setport(isc_sockaddr_t *sockaddr, in_port_t port) {
|
||||
FATAL_ERROR(__FILE__, __LINE__, "unknown address family");
|
||||
}
|
||||
}
|
||||
|
||||
in_port_t
|
||||
isc_sockaddr_getport(isc_sockaddr_t *sockaddr) {
|
||||
in_port_t port = 0;
|
||||
|
||||
switch (sockaddr->type.sa.sa_family) {
|
||||
case AF_INET:
|
||||
port = ntohs(sockaddr->type.sin.sin_port);
|
||||
break;
|
||||
case AF_INET6:
|
||||
port = ntohs(sockaddr->type.sin6.sin6_port);
|
||||
break;
|
||||
default:
|
||||
FATAL_ERROR(__FILE__, __LINE__, "unknown address family");
|
||||
}
|
||||
|
||||
return (port);
|
||||
}
|
||||
|
Reference in New Issue
Block a user