Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion pjlib-util/include/pjlib-util/dns_server.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@ typedef struct pj_dns_server pj_dns_server;
* registered to.
* @param af Address family of the server socket (valid values
* are pj_AF_INET() for IPv4 and pj_AF_INET6() for IPv6).
* @param port The UDP port to listen.
* @param port The UDP port to listen. Specify zero to bind to any
* port.
* @param flags Flags, currently must be zero.
* @param p_srv Pointer to receive the DNS server instance.
*
Expand All @@ -65,6 +66,17 @@ PJ_DECL(pj_status_t) pj_dns_server_create(pj_pool_factory *pf,
unsigned flags,
pj_dns_server **p_srv);

/**
* Get the DNS server address
*
* @param srv The DNS server instance.
* @param addr It will be filled with the server's bound address.
*
* @return PJ_SUCCESS on success or the appropriate error code.
*/
PJ_DECL(pj_status_t) pj_dns_server_get_addr(pj_dns_server *srv,
pj_sockaddr *bound_addr);

/**
* Destroy DNS server instance.
*
Expand Down
13 changes: 12 additions & 1 deletion pjlib-util/src/pjlib-util/dns_server.c
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ struct pj_dns_server
pj_pool_t *pool;
pj_pool_factory *pf;
pj_activesock_t *asock;
pj_sockaddr bound_addr;
pj_ioqueue_op_key_t send_key;
struct rr rr_list;
};
Expand Down Expand Up @@ -97,7 +98,8 @@ PJ_DEF(pj_status_t) pj_dns_server_create( pj_pool_factory *pf,
pj_activesock_cfg_default(&sock_cfg);

status = pj_activesock_create_udp(pool, &sock_addr, &sock_cfg, ioqueue,
&sock_cb, srv, &srv->asock, NULL);
&sock_cb, srv, &srv->asock,
&srv->bound_addr);
if (status != PJ_SUCCESS)
goto on_error;

Expand All @@ -116,6 +118,15 @@ PJ_DEF(pj_status_t) pj_dns_server_create( pj_pool_factory *pf,
}


PJ_DEF(pj_status_t) pj_dns_server_get_addr(pj_dns_server *srv,
pj_sockaddr *bound_addr)
{
PJ_ASSERT_RETURN(srv && bound_addr, PJ_EINVAL);
pj_memcpy(bound_addr, &srv->bound_addr, sizeof(*bound_addr));
return PJ_SUCCESS;
}


PJ_DEF(pj_status_t) pj_dns_server_destroy(pj_dns_server *srv)
{
PJ_ASSERT_RETURN(srv, PJ_EINVAL);
Expand Down