int rc; char *saddr_ip_str = NULL; int saddr_len, saddr_port; struct sockaddr_in saddr;
int rc, hport; char *ip_str = NULL; ClientData *cd = (ClientData *) client->clientData;
static int run_user_command(char *cmd, rfbClientPtr client) {	char *dpystr = DisplayString(dpy);	static char *display_env = NULL;	static char env_rfb_client_id[100];	static char env_rfb_client_ip[100];	static char env_rfb_client_port[100];	static char env_rfb_server_ip[100];	static char env_rfb_server_port[100];	static char env_rfb_x11vnc_pid[100];	static char env_rfb_client_count[100];	char *addr = client->host;	int rc;	char *saddr_ip_str = NULL;	int saddr_len, saddr_port;	struct sockaddr_in saddr;	if (addr == NULL || addr[0] == '\0') {		addr = "unknown-host";	}	/* set RFB_CLIENT_ID to semi unique id for command to use */	sprintf(env_rfb_client_id, "RFB_CLIENT_ID=%p", (void *) client);	putenv(env_rfb_client_id);	/* set RFB_CLIENT_IP to IP addr for command to use */	sprintf(env_rfb_client_ip, "RFB_CLIENT_IP=%s", addr);	putenv(env_rfb_client_ip);	/* set RFB_X11VNC_PID to our pid for command to use */	sprintf(env_rfb_x11vnc_pid, "RFB_X11VNC_PID=%d", (int) getpid());	putenv(env_rfb_x11vnc_pid);	/* set RFB_CLIENT_PORT to peer port for command to use */	saddr_len = sizeof(saddr);	memset(&saddr, 0, sizeof(saddr));	saddr_port = -1;	if (!getpeername(client->sock, (struct sockaddr *)&saddr, &saddr_len)) {		saddr_port = ntohs(saddr.sin_port);	}	sprintf(env_rfb_client_port, "RFB_CLIENT_PORT=%d", saddr_port);	putenv(env_rfb_client_port);	/* 	 * now do RFB_SERVER_IP and RFB_SERVER_PORT (i.e. us!)	 * This will establish a 5-tuple (including tcp) the external	 * program can potentially use to work out the virtual circuit	 * for this connection.	 */	saddr_len = sizeof(saddr);	memset(&saddr, 0, sizeof(saddr));	saddr_port = -1;	saddr_ip_str = "unknown";	if (!getsockname(client->sock, (struct sockaddr *)&saddr, &saddr_len)) {		saddr_port = ntohs(saddr.sin_port);#ifdef LIBVNCSERVER_HAVE_NETINET_IN_H		saddr_ip_str = inet_ntoa(saddr.sin_addr);#endif	}	sprintf(env_rfb_server_ip, "RFB_SERVER_IP=%s", saddr_ip_str);	putenv(env_rfb_server_ip);	sprintf(env_rfb_server_port, "RFB_SERVER_PORT=%d", saddr_port);	putenv(env_rfb_server_port);	/* 	 * Better set DISPLAY to the one we are polling, if they	 * want something trickier, they can handle on their own	 * via environment, etc.  XXX really should save/restore old.	 */	if (display_env == NULL) {		display_env = (char *) malloc(strlen(dpystr)+10);	}	sprintf(display_env, "DISPLAY=%s", dpystr);	putenv(display_env);	/*	 * work out the number of clients (have to use client_count	 * since there is deadlock in rfbGetClientIterator) 	 */	sprintf(env_rfb_client_count, "RFB_CLIENT_COUNT=%d", client_count);	putenv(env_rfb_client_count);	rfbLog("running command:\n");	rfbLog("  %s\n", cmd);	rc = system(cmd);	if (rc >= 256) {		rc = rc/256;	}	rfbLog("command returned: %d\n", rc);	return rc;}