apr-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Damir Dezeljin <program...@mbss.org>
Subject apr_sockaddr_port_get() problem
Date Thu, 16 Jan 2003 07:29:36 GMT

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,

View raw message