Commit c5f33ba0 authored by David Lawrence's avatar David Lawrence
Browse files

added isc_sockaddr_getport

parent 7ce7f319
...@@ -83,6 +83,12 @@ isc_sockaddr_setport(isc_sockaddr_t *sockaddr, in_port_t port); ...@@ -83,6 +83,12 @@ isc_sockaddr_setport(isc_sockaddr_t *sockaddr, in_port_t port);
* Set the port of 'sockaddr' to '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_result_t
isc_sockaddr_totext(const isc_sockaddr_t *sockaddr, isc_buffer_t *target); 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) { ...@@ -337,3 +337,21 @@ isc_sockaddr_setport(isc_sockaddr_t *sockaddr, in_port_t port) {
FATAL_ERROR(__FILE__, __LINE__, "unknown address family"); 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);
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment