if (have_hostname_in_open)
if (have_hostname_in_open) {
x11_input_open(int payload_len){	int remote_channel, display_number, sock, newch;	const char *display;	struct sockaddr_in sin;	char buf[1024], *cp, *remote_host;	struct hostent *hp;	int remote_len;	/* Get remote channel number. */	remote_channel = packet_get_int();	/* Get remote originator name. */	if (have_hostname_in_open)		remote_host = packet_get_string(&remote_len);	else		remote_host = xstrdup("unknown (remote did not supply name)");	debug("Received X11 open request.");	packet_integrity_check(payload_len, 4 + 4 + remote_len, SSH_SMSG_X11_OPEN);	/* Try to open a socket for the local X server. */	display = getenv("DISPLAY");	if (!display) {		error("DISPLAY not set.");		goto fail;	}	/*	 * Now we decode the value of the DISPLAY variable and make a	 * connection to the real X server.	 */	/*	 * Check if it is a unix domain socket.  Unix domain displays are in	 * one of the following formats: unix:d[.s], :d[.s], ::d[.s]	 */	if (strncmp(display, "unix:", 5) == 0 ||	    display[0] == ':') {		/* Connect to the unix domain socket. */		if (sscanf(strrchr(display, ':') + 1, "%d", &display_number) != 1) {			error("Could not parse display number from DISPLAY: %.100s",			      display);			goto fail;		}		/* Create a socket. */		sock = connect_local_xsocket(display_number);		if (sock < 0)			goto fail;		/* OK, we now have a connection to the display. */		goto success;	}	/*	 * Connect to an inet socket.  The DISPLAY value is supposedly	 * hostname:d[.s], where hostname may also be numeric IP address.	 */	strncpy(buf, display, sizeof(buf));	buf[sizeof(buf) - 1] = 0;	cp = strchr(buf, ':');	if (!cp) {		error("Could not find ':' in DISPLAY: %.100s", display);		goto fail;	}	*cp = 0;	/* buf now contains the host name.  But first we parse the display number. */	if (sscanf(cp + 1, "%d", &display_number) != 1) {		error("Could not parse display number from DISPLAY: %.100s",		      display);		goto fail;	}	/* Try to parse the host name as a numeric IP address. */	memset(&sin, 0, sizeof(sin));	sin.sin_addr.s_addr = inet_addr(buf);	if ((sin.sin_addr.s_addr & 0xffffffff) != 0xffffffff) {		/* It was a valid numeric host address. */		sin.sin_family = AF_INET;	} else {		/* Not a numeric IP address. */		/* Look up the host address from the name servers. */		hp = gethostbyname(buf);		if (!hp) {			error("%.100s: unknown host.", buf);			goto fail;		}		if (!hp->h_addr_list[0]) {			error("%.100s: host has no IP address.", buf);			goto fail;		}		sin.sin_family = hp->h_addrtype;		memcpy(&sin.sin_addr, hp->h_addr_list[0],		       sizeof(sin.sin_addr));	}	/* Set port number. */	sin.sin_port = htons(6000 + display_number);	/* Create a socket. */	sock = socket(sin.sin_family, SOCK_STREAM, 0);	if (sock < 0) {		error("socket: %.100s", strerror(errno));		goto fail;	}	/* Connect it to the display. */	if (connect(sock, (struct sockaddr *) & sin, sizeof(sin)) < 0) {		error("connect %.100s:%d: %.100s", buf, 6000 + display_number,		      strerror(errno));		close(sock);		goto fail;	}success:	/* We have successfully obtained a connection to the real X display. */	/* Allocate a channel for this connection. */	if (x11_saved_proto == NULL)		newch = channel_allocate(SSH_CHANNEL_OPEN, sock, remote_host);	else		newch = channel_allocate(SSH_CHANNEL_X11_OPEN, sock, remote_host);	channels[newch].remote_id = remote_channel;	/* Send a confirmation to the remote host. */	packet_start(SSH_MSG_CHANNEL_OPEN_CONFIRMATION);	packet_put_int(remote_channel);	packet_put_int(newch);	packet_send();	return;fail:	/* Send refusal to the remote host. */	packet_start(SSH_MSG_CHANNEL_OPEN_FAILURE);	packet_put_int(remote_channel);	packet_send();}