if (have_hostname_in_open)
if (have_hostname_in_open) {
channel_input_port_open(int payload_len){	int remote_channel, sock, newch, host_port, i;	struct sockaddr_in sin;	char *host, *originator_string;	struct hostent *hp;	int host_len, originator_len;	/* Get remote channel number. */	remote_channel = packet_get_int();	/* Get host name to connect to. */	host = packet_get_string(&host_len);	/* Get port to connect to. */	host_port = packet_get_int();	/* Get remote originator name. */	if (have_hostname_in_open)		originator_string = packet_get_string(&originator_len);	else		originator_string = xstrdup("unknown (remote did not supply name)");	packet_integrity_check(payload_len,			       4 + 4 + host_len + 4 + 4 + originator_len,			       SSH_MSG_PORT_OPEN);	/* Check if opening that port is permitted. */	if (!all_opens_permitted) {		/* Go trough all permitted ports. */		for (i = 0; i < num_permitted_opens; i++)			if (permitted_opens[i].port == host_port &&			    strcmp(permitted_opens[i].host, host) == 0)				break;		/* Check if we found the requested port among those permitted. */		if (i >= num_permitted_opens) {			/* The port is not permitted. */			log("Received request to connect to %.100s:%d, but the request was denied.",			    host, host_port);			packet_start(SSH_MSG_CHANNEL_OPEN_FAILURE);			packet_put_int(remote_channel);			packet_send();		}	}	memset(&sin, 0, sizeof(sin));	sin.sin_addr.s_addr = inet_addr(host);	if ((sin.sin_addr.s_addr & 0xffffffff) != 0xffffffff) {		/* It was a valid numeric host address. */		sin.sin_family = AF_INET;	} else {		/* Look up the host address from the name servers. */		hp = gethostbyname(host);		if (!hp) {			error("%.100s: unknown host.", host);			goto fail;		}		if (!hp->h_addr_list[0]) {			error("%.100s: host has no IP address.", host);			goto fail;		}		sin.sin_family = hp->h_addrtype;		memcpy(&sin.sin_addr, hp->h_addr_list[0],		       sizeof(sin.sin_addr));	}	sin.sin_port = htons(host_port);	/* Create the socket. */	sock = socket(sin.sin_family, SOCK_STREAM, 0);	if (sock < 0) {		error("socket: %.100s", strerror(errno));		goto fail;	}	/* Connect to the host/port. */	if (connect(sock, (struct sockaddr *) & sin, sizeof(sin)) < 0) {		error("connect %.100s:%d: %.100s", host, host_port,		      strerror(errno));		close(sock);		goto fail;	}	/* Successful connection. */	/* Allocate a channel for this connection. */	newch = channel_allocate(SSH_CHANNEL_OPEN, sock, originator_string);	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();	/* Free the argument string. */	xfree(host);	return;fail:	/* Free the argument string. */	xfree(host);	/* Send refusal to the remote host. */	packet_start(SSH_MSG_CHANNEL_OPEN_FAILURE);	packet_put_int(remote_channel);	packet_send();}