You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@apr.apache.org by Damir Dezeljin <pr...@mbss.org> on 2003/01/16 08:29:36 UTC
apr_sockaddr_port_get() problem
Hi.
I have to estabilish a network connection from one machine to the
other one when I get a request trough a control connection. So I have to
bind a socket on a random free port and let know the 'client' on which
port the socket (the server) is listening for incomming connection.
So I construct an apr_sockaddr_t structure and specify 0 as port number
(to let the kernel coose the port on which to list {I don't test this on
windows, but on Linux it works fine}):
apr_sockaddr_port_set(addr_p, 0); // I should use APR_UNSPEC
Then I call:
apr_bind(sock_p, addr_p);
apr_listen(sock_p, 1);
This works fine (I check it with netstat to get a port number and then try
to connect to this port).
The problem is that
apr_sockaddr_port_get(&port, addr_p);
say that the 0 is the port of the *addr_p structure. This is ok, because I
set the port to 0 above, but how can I get the 'real' port now?
10x and regards,
Dezo
Re: apr_sockaddr_port_get() problem
Posted by Damir Dezeljin <pr...@mbss.org>.
Sorry for the previous posting ... I solve my problem by constructing a
new address structure with
apr_socket_addr_get()
and then get the prot from the new address structure.
Regards,
Dezo