summaryrefslogtreecommitdiff
path: root/japanese/skkfep/patches/patch-bb
blob: d3310515a3c7a26d56713d46e9643d3f182a17c7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
$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;
 	}