Hi,

You are right you have to include the get_viewer_ipaddress() function
in Xvnc source code.
In Xvnc source call get_viewer_ipaddress() once connection is
established, do call it only 
when -inetd flag is set (this is because we are passing 0 to
getpeername()).

Never do a printf() in the function below. As I told u before in -inetd
mode stdout, stdin
and stderr are mapped to socket descriptor. Hence the strings in
printf() would be directed to 
VNCViewer and you would find the connection getting dropped with a
"Invalid Protocol" message..
Instead use rfbLog() to log messages into VNC log file.

Thanks,
-Jinu 
 
>>> "Tim Underwood" <[EMAIL PROTECTED]> 01/23/06 8:05 pm >>> 
Using your suggestion, I've created the following program:


#include <linux/socket.h>
#include <linux/in.h>
#include <errno.h>
#include <stdio.h>



char* get_viewer_ipaddress()
{
        struct sockaddr_in s;
        char *client_ip = NULL;
        int len, ret_val;

        if(client_ip == NULL)
        {
                memset(&s,0,sizeof(s));
                len = sizeof(s);
                s.sin_family = AF_INET;

                /*
                 * when launched from inetd, stdin, stdout and stderr
                 * are mapped to sd. Hence passing 0 to getpeername
                 */
                ret_val = getpeername(0, (struct sockaddr *)&s, &len);
                if(!ret_val)
                {
                        client_ip = (char *)inet_ntoa(s.sin_addr);
                        printf("Inf: retrieved client IP address %s\n",
client_ip);
                }
                else
                {
                        client_ip = NULL;
                        printf("Err: could not retrieve client IP
address, error=%d\n", errno);
                }
        }

        return client_ip;
}


int main(int argc, char *argv[])
{
    get_viewer_ipaddress();
    return(0);
}


However, when I run this within an xterm running in a VNC desktop, I
get
an error, ENOTSOCK (88), indicating the handle is not a socket. 
Hence,
I am assuming this would need to be added to the Xvnc source, and
determined from within Xvnc?

> ----- Original Message-----
> From: Jinu Mathew Joy [mailto:[EMAIL PROTECTED] 
> Sent: Sunday, January 22, 2006 9:46 PM
> To: Tim Underwood; vnc- [EMAIL PROTECTED]
> Subject: Re: Client IP address when using Xvnc with - inetd
> 
> You would use - inetd option when running Xvnc from xinetd. 
> Say you have configured the xinetd process to listen for 
> connections on behalf of Xvnc on port xxxx. 
> As soon as a request arrives on the configured port xxxx, 
> xinetd forks off Xvnc and maps the stdin, stdout and stderr 
> to the socket descriptor.
> 
> What it means is now on if you do a printf() the string would 
> be directed to the client(vncviewer) and not stdout. Since 
> stdout is mapped to the socket descriptor and this stage.
> 
> Hence if you want the client IP, all you would do is the following..

> 
> char* get_viewer_ipaddress()
> {
>       struct sockaddr_in s;
>       char *client_ip = NULL;
>       int len, ret_val;
> 
>       if(client_ip == NULL)
>       {
>               memset(&s,0,sizeof(s));
>               len = sizeof(s);
>               s.sin_family = AF_INET;
> 
>               /*
>                * when launched from inetd, stdin, stdout and stderr
>                * are mapped to sd. Hence passing 0 to getpeername
>                */
>               ret_val = getpeername(0, (struct sockaddr *)&s, &len);
>               if(!ret_val)
>               {
>                       client_ip = (char *)inet_ntoa(s.sin_addr);
>                       DEV_LOG("Inf: retrieved client IP 
> address %s\n", client_ip);
>               }
>               else
>               {
>                       client_ip = NULL;
>                       DEV_LOG("Err: could not retrieve client 
> IP address\n");
>               }
>       }
> 
>       return client_ip;
> }
> 
> let me know if that helps.. 
> 
> - Jinu
> 
> 
> 
> >>> "Tim Underwood" <[EMAIL PROTECTED]> 01/21/06 1:58 AM >>>
> How can I determine a client's IP address, when they connect 
> to a server running Xvnc with the - inetd option?
> 
> Can't use $DISPLAY, since it's the server's address, and I 
> don't find anything identifiable that can be used to get back 
> to the client. 
> Can't
> even find anything via the process chain to get from a 
> running application back to the Xvnc process (xterm's run 
> within the VNC client eventually show their parent as "init" 
> or process id 1, never going back to the Xvnc process I know 
> is the one I started).
> 
> I need to do this for some customized settings for terminals 
> attaching to our server (printers, etc.), and identifying 
> them for other purposes.
> 
> Any ideas?
> _______________________________________________
> VNC- List mailing list
> VNC- [EMAIL PROTECTED]
> To remove yourself from the list visit:
> http://www.realvnc.com/mailman/listinfo/vnc- list
_______________________________________________
VNC- List mailing list
VNC- [EMAIL PROTECTED]
To remove yourself from the list visit:
http://www.realvnc.com/mailman/listinfo/vnc- list
_______________________________________________
VNC-List mailing list
[email protected]
To remove yourself from the list visit:
http://www.realvnc.com/mailman/listinfo/vnc-list

Reply via email to