apr-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Damir Dezeljin <program...@nib.si>
Subject How to get remote (client) address,...
Date Fri, 25 Oct 2002 08:07:57 GMT
Hi.

I writen an daemon which is executed in inetd (part of the code is below).
I have problems getting remote IP address and 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).

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


Mime
View raw message