[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: Remote IP for inetd "daemon"



The problem is the redirect.
When redirecting, the prog doesn't
get peername anymore. I first thought
the redirect to the logfile didn't work.
If you add an else strement to the prog
you see where the problem is:

#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <stdio.h>

int main (int argc, char *argv[])
{
  struct sockaddr_in name;
  int namelen = sizeof(name);
  char *temp_domain;

  if (getpeername((int) 1,
        (struct sockaddr *) & name, (socklen_t *) &
namelen) == 0) {
    if ((temp_domain = (char *) inet_ntoa(name.sin_addr)))
      printf ("%s\n", temp_domain);
  }
  else
  {
      printf ("getpeername: Oops!\n");
  }
}




Robert Waldner <r.waldner@xsoft.at> 19 Sep 2001, at 10:05:

>
> On Tue, 18 Sep 2001 09:55:06 PDT, "Jeremy C. Reed" writes:
> >On Tue, 18 Sep 2001, Marcel Hicking wrote: > >> I have a
> script invoked via inetd. >> How can I let the script know
> of the IP of the client >> connecting (remote IP)? >> I need
> to do some additional security checks not >> possible with
> hosts.access|deny >> >> Any hints? > >getpeername(2) is the
> C library function to get the remote IP. This works >for me:
> > <snip> > >Then compile it with "gcc -o getpeername
> getpeername.c". Then use the >getpeername executable in your
> script.
>
> Hmm, this doesn´t work for me. If I invoke it via
> inetd.conf:
> sunrpc stream tcp nowait nobody /usr/local/bin/test.sh
> test.sh
>
> test.sh:
> #!/bin/bash
> /usr/local/bin/getpeername >>/tmp/peer.ip
> exit
>
> only a \n is logged to the file (so permissions et al are ok
> ;-) ).
>
> However, if I do
> inetd.conf:
> sunrpc stream tcp nowait nobody /usr/local/bin/getpeername
> getpeername
>
> waldner@st:~$ telnet ka 111
> Trying 4.3.2.1...
> Connected to ka.
> Escape character is '^]'.
> 1.2.3.4Connection closed by foreign host.
>
> (IPs obfuscated)
>
> What am I doing wrong?

--
   __
 .´  `.
 : :' !  Enjoy
 `. `´  Debian/GNU Linux
   `-



Reply to: