Merge from vendor branch KAME:
[pkgsrc.git] / japanese / skkfep / patches / patch-bb
1 $NetBSD$
2
3 --- connserv.c.orig     Tue Jul  7 00:31:16 1998
4 +++ connserv.c  Fri Dec 24 00:25:24 1999
5 @@ -40,8 +40,33 @@
6         struct hostent *entry;
7         struct servent *serv;
8         struct protoent *proto;
9 -       int a1,a2,a3,a4;
10         char *hostname;
11 +#ifdef SKK_CONF                /* use skk.conf */
12 +       FILE *conffp;
13 +       char line[128];
14 +       char hostbuf[128];
15 +       char *confhost = NULL;
16 +       int confport = 0;
17 +
18 +       if ((conffp = fopen(SKK_CONF, "r")) != NULL) {
19 +               char *p, *data;
20 +
21 +               while (fgets(line, sizeof line, conffp) != NULL) {
22 +                       if ((p = strchr(line, '#')) != NULL)
23 +                               *p = '\0';
24 +                       if ((p = strtok(line, ": \t\n")) == NULL)
25 +                               continue;
26 +                       if ((data = strtok((char *) NULL, " \t\n")) == NULL)
27 +                               continue;
28 +                       if (!strcmp(p, "skkserv_host")) {
29 +                               strcpy(hostbuf, data);
30 +                               confhost = hostbuf;
31 +                       } else if (!strcmp(p, "skkserv_port")) {
32 +                               confport = atoi(data);
33 +                       }
34 +               }
35 +       }
36 +#endif
37  
38         serv = getservbyname(SKK_SERVICENAME,"tcp");
39         fillzero((char*)&hostaddr,sizeof(struct sockaddr_in));
40 @@ -56,27 +81,27 @@
41         if (SKKServerHost)
42                 hostname = SKKServerHost;
43         else if ((hostname = getenv("SKKSERVER")) == NULL) {
44 +#ifdef SKK_CONF
45 +               if ((hostname = confhost) == NULL)
46 +#endif
47  #ifdef SKK_SERVER_HOST
48                 hostname = SKK_SERVER_HOST;
49  #else
50                 return -1;
51  #endif
52         }
53 -       if ('0' <= *hostname && *hostname <= '9') {
54 -               if (sscanf(hostname,"%d.%d.%d.%d",&a1,&a2,&a3,&a4) != 4) {
55 -                       return -1;
56 -               }
57 -               a1 = (a1<<24)|(a2<<16)|(a3<<8)|a4;
58 -               hostaddr.sin_addr.s_addr = htonl(a1);
59 -       }
60 -       else {
61 +       if ((hostaddr.sin_addr.s_addr = inet_addr(hostname)) == INADDR_NONE) {
62                 if ((entry = gethostbyname(hostname)) == NULL) {
63                         return -1;
64                 }
65                 bincopy(entry->h_addr, &hostaddr.sin_addr, entry->h_length);
66         }
67          hostaddr.sin_family = AF_INET;
68 -       hostaddr.sin_port = serv ? serv->s_port : htons(SKK_PORT_NUMBER);
69 +       hostaddr.sin_port =
70 +#ifdef SKK_CONF
71 +               confport ? htons(confport) :
72 +#endif
73 +               serv ? serv->s_port : htons(SKK_PORT_NUMBER);
74         if (connect(sock,(struct sockaddr *)&hostaddr,sizeof(struct sockaddr_in)) < 0) {
75                 return -1;
76         }