gochatai/pachi_py/pachi/network.c
/* Opens a new connection to the given port name, which must
 * contain a host name. Returns the open file descriptor,
 * or -1 if the open fails. */
Opens a new connection to the given port name, which must
contain a host name. Returns the open file descriptor,
or -1 if the open fails.
Opens a new connection to the given port name which must contain a host name . Returns the open file descriptor or - 1 if the open fails .
static int
open_client_connection(char *port_name)
{
	char hostname[BSIZE];
	strncpy(hostname, port_name, sizeof(hostname));
	char *port = strchr(hostname, ':');
	assert(port);
	*port++ = '\0';
	struct hostent *host = gethostbyname(hostname);
	if (!host)
		return -1;
	int sock = socket(AF_INET, SOCK_STREAM, 0);
	if (sock == -1)
		die("socket");
	struct sockaddr_in sin;
	memcpy(&sin.sin_addr.s_addr, host->h_addr, host->h_length);
	sin.sin_family = AF_INET;
	sin.sin_port = htons(atoi(port));
	if (connect(sock, (struct sockaddr *)&sin, sizeof(sin)) < 0) {
		close(sock);
		return -1;
	}
	return sock;
}
static int open_client_connection ( char * port_name ) { char hostname [ BSIZE ] ; strncpy ( hostname , port_name , sizeof ( hostname ) ) ; char * port = strchr ( hostname , ' ' ) ; assert ( port ) ; * port ++ = ' \0 ' ; struct hostent * host = gethostbyname ( hostname ) ; if ( ! host ) return -1 ; int sock = socket ( AF_INET , SOCK_STREAM , 0 ) ; if ( sock == -1 ) die ( " " ) ; struct sockaddr_in sin ; memcpy ( & sin . sin_addr . s_addr , host -> h_addr , host -> h_length ) ; sin . sin_family = AF_INET ; sin . sin_port = htons ( atoi ( port ) ) ; if ( connect ( sock , ( struct sockaddr * ) & sin , sizeof ( sin ) ) < 0 ) { close ( sock ) ; return -1 ; } return sock ; }
Opens a new connection to the given port name, which must
 contain a host name.
Opens a new connection to the given port name which must contain a host name .