On Fri, Oct 25, 2002 at 09:07:57AM +0100, Damir Dezeljin wrote:
> Hi.
>
> I writen an daemon which is executed in inetd (part of the code is below).
> I have problems getting remote IP address ajd remote port. I use:
> apr_socket_addr_get(&addr_local, APR_LOCAL, apr_sock);
> to get local address and port, and
> apr_socket_addr_get(&addr_local, APR_LOCAL, apr_sock);
> to get the remote one, but this doesn't work (I get 0.0.0.0 for the IP and
> port 0).
From looking at how Apache2 gets the ip address:
char *remote_ipaddr;
apr_socket_addr_get(&addr_remote, APR_REMOTE, apr_stdout);
apr_sockaddr_ip_get(&remote_ipaddr, addr_remote);
> Any sugestion in welcome.
>
> Part of my code:
>
> ----
> int main(int argc, char *argv[]) {
> apr_pool_t *pool;
> apr_status_t rv;
> apr_socket_t *apr_stdin=NULL, *apr_stdout=NULL;
> int os_stdin=0, os_stdout=1;
> char *ip_ptr=NULL;
> apr_sockaddr_t *addr_local;
> apr_sockaddr_t *addr_remote;
>
> apr_port_t port;
>
> /* Initialize APR library and set the APR cleanup fuction as exit
> function */
> apr_initialize();
> atexit(apr_terminate);
>
> /* Create the main APR memory pool */
> rv = apr_pool_create(&pool, NULL);
>
> /* Construct APR sockets - for read in and for write to */
> rv = apr_os_sock_put(&apr_stdin, (apr_os_sock_t *) &os_stdin, pool);
> rv = apr_os_sock_put(&apr_stdout, (apr_os_sock_t *) &os_stdout, pool);
>
> /* Construct local and remote address structure */
> rv = apr_socket_addr_get(&addr_local, APR_LOCAL, apr_stdin);
> rv = apr_socket_addr_get(&addr_remote, APR_REMOTE, apr_stdout); // <=
> this doesn't work
>
> ...
>
> /* Adress and port of the client and the connection was accepted on */
> rv = apr_sockaddr_ip_get(&ip_ptr, addr_remote);
> rv = apr_sockaddr_port_get(&port, addr_remote);
> fprintf(log_FILE, "Connection from: %s:%d", ip_ptr, (int) port);
>
> ...
> ----
>
> Regards,
> Dezo
--
Thomas Eibner <http://thomas.eibner.dk/> DnsZone <http://dnszone.org/>
mod_pointer <http://stderr.net/mod_pointer> <http://photos.eibner.dk/>
!(C)<http://copywrong.dk/> <http://apachegallery.dk/>
Putting the HEST in .COM <http://www.hestdesign.com/>