I've found a solution that others may want to try. It is a script named 'psrelated' contained within the Network Security Toolkit from http://nst.sourceforge.net/nst/. This script only exists in CVS at this time, so you'll need to check it out anonymously, and build the package to get the script.
Here's the documentation of the script: http://nst.sourceforge.net/nst/docs/scripts/psrelated.html Used from within the Xvnc desktop, it will give you the process ID of the Xvnc you spawned through xinetd. Note that this same script works for X as well. You can then look in /proc/<Xvncprocid>/environ file, and extract the REMOTE_HOST environment variable from that file, which is the client IP of the VNC Client. Note that the variables in /proc/<Xvncprocid>/environ are NULL delimited, so you'll probably need a C program to parse out the variable. Following is an example of one I've created: #include <stdio.h> #include <stdlib.h> FILE *in; char fname[256]; void usage(char *s) { printf("%s Usage:\n", s); printf("\t%s <procid> <varname>\n"); printf("\t\t<procid> is the task id of the task to parse the environment for.\n"); printf("\t\t<varname> is the variable name to search for.\n"); exit(1); } void scanit(FILE *in, char *srch) { char buf[1024]; char *s; int c; s=buf; while ( (c=fgetc(in)) != EOF) { *s++=c; if (c == 0) { if (strncmp(srch, buf, strlen(srch)) == 0) { printf("%s\n", buf); fclose(in); exit(0); } s=buf; } } } int main(int argc, char *argv[]) { if (argc != 3) usage(argv[0]); sprintf(fname, "/proc/%s/environ", argv[1]); if ( (in=fopen(fname, "r")) == NULL) { printf("Error opening %s\n", fname); exit(1); } scanit(in, argv[2]); fclose(in); } Thanks for the help, and hope this helps others. > -----Original Message----- > From: Jinu Mathew Joy [mailto:[EMAIL PROTECTED] > Sent: Monday, January 23, 2006 9:32 PM > To: Tim Underwood; [email protected] > Subject: RE: Client IP address when using Xvnc with -inetd > > 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
