$NetBSD: patch-bb,v 1.1.1.1 1999/12/24 03:21:10 itohy Exp $ --- connserv.c.orig Tue Jul 7 00:31:16 1998 +++ connserv.c Fri Dec 24 00:25:24 1999 @@ -40,8 +40,33 @@ struct hostent *entry; struct servent *serv; struct protoent *proto; - int a1,a2,a3,a4; char *hostname; +#ifdef SKK_CONF /* use skk.conf */ + FILE *conffp; + char line[128]; + char hostbuf[128]; + char *confhost = NULL; + int confport = 0; + + if ((conffp = fopen(SKK_CONF, "r")) != NULL) { + char *p, *data; + + while (fgets(line, sizeof line, conffp) != NULL) { + if ((p = strchr(line, '#')) != NULL) + *p = '\0'; + if ((p = strtok(line, ": \t\n")) == NULL) + continue; + if ((data = strtok((char *) NULL, " \t\n")) == NULL) + continue; + if (!strcmp(p, "skkserv_host")) { + strcpy(hostbuf, data); + confhost = hostbuf; + } else if (!strcmp(p, "skkserv_port")) { + confport = atoi(data); + } + } + } +#endif serv = getservbyname(SKK_SERVICENAME,"tcp"); fillzero((char*)&hostaddr,sizeof(struct sockaddr_in)); @@ -56,27 +81,27 @@ if (SKKServerHost) hostname = SKKServerHost; else if ((hostname = getenv("SKKSERVER")) == NULL) { +#ifdef SKK_CONF + if ((hostname = confhost) == NULL) +#endif #ifdef SKK_SERVER_HOST hostname = SKK_SERVER_HOST; #else return -1; #endif } - if ('0' <= *hostname && *hostname <= '9') { - if (sscanf(hostname,"%d.%d.%d.%d",&a1,&a2,&a3,&a4) != 4) { - return -1; - } - a1 = (a1<<24)|(a2<<16)|(a3<<8)|a4; - hostaddr.sin_addr.s_addr = htonl(a1); - } - else { + if ((hostaddr.sin_addr.s_addr = inet_addr(hostname)) == INADDR_NONE) { if ((entry = gethostbyname(hostname)) == NULL) { return -1; } bincopy(entry->h_addr, &hostaddr.sin_addr, entry->h_length); } hostaddr.sin_family = AF_INET; - hostaddr.sin_port = serv ? serv->s_port : htons(SKK_PORT_NUMBER); + hostaddr.sin_port = +#ifdef SKK_CONF + confport ? htons(confport) : +#endif + serv ? serv->s_port : htons(SKK_PORT_NUMBER); if (connect(sock,(struct sockaddr *)&hostaddr,sizeof(struct sockaddr_in)) < 0) { return -1; }