Return-Path: Delivered-To: apmail-apr-dev-archive@apr.apache.org Received: (qmail 87020 invoked by uid 500); 25 Oct 2002 12:04:32 -0000 Mailing-List: contact dev-help@apr.apache.org; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: Delivered-To: mailing list dev@apr.apache.org Delivered-To: moderator for dev@apr.apache.org Received: (qmail 80835 invoked from network); 25 Oct 2002 11:57:19 -0000 Date: Fri, 25 Oct 2002 06:59:38 -0500 From: Thomas Eibner To: dev@apr.apache.org Subject: Re: How to get remote (client) address,... Message-ID: <20021025115937.GK30978@pasiphae.stderr.net> References: Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable In-Reply-To: User-Agent: Mutt/1.4i Organisation: Stderr.Net - coming soon with an error near you X-Spam-Rating: daedalus.apache.org 1.6.2 0/1000/N On Fri, Oct 25, 2002 at 09:07:57AM +0100, Damir Dezeljin wrote: > Hi. >=20 > 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). =46rom 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. >=20 > Part of my code: >=20 > ---- > int main(int argc, char *argv[]) { > apr_pool_t *pool; > apr_status_t rv; > apr_socket_t *apr_stdin=3DNULL, *apr_stdout=3DNULL; > int os_stdin=3D0, os_stdout=3D1; > char *ip_ptr=3DNULL; > apr_sockaddr_t *addr_local; > apr_sockaddr_t *addr_remote; >=20 > apr_port_t port; >=20 > /* Initialize APR library and set the APR cleanup fuction as exit > function */ > apr_initialize(); > atexit(apr_terminate); >=20 > /* Create the main APR memory pool */ > rv =3D apr_pool_create(&pool, NULL); >=20 > /* Construct APR sockets - for read in and for write to */ > rv =3D apr_os_sock_put(&apr_stdin, (apr_os_sock_t *) &os_stdin, pool); > rv =3D apr_os_sock_put(&apr_stdout, (apr_os_sock_t *) &os_stdout, poo= l); >=20 > /* Construct local and remote address structure */ > rv =3D apr_socket_addr_get(&addr_local, APR_LOCAL, apr_stdin); > rv =3D apr_socket_addr_get(&addr_remote, APR_REMOTE, apr_stdout); // = <=3D > this doesn't work >=20 > ... >=20 > /* Adress and port of the client and the connection was accepted on */ > rv =3D apr_sockaddr_ip_get(&ip_ptr, addr_remote); > rv =3D apr_sockaddr_port_get(&port, addr_remote); > fprintf(log_FILE, "Connection from: %s:%d", ip_ptr, (int) port); >=20 > ... > ---- >=20 > Regards, > Dezo --=20 Thomas Eibner DnsZone mod_pointer !(C) Putting the HEST in .COM