2 * Copyright 2000, International Business Machines Corporation and others.
5 * This software has been released under the terms of the IBM Public
6 * License. For details, see the LICENSE file in the top-level source
7 * directory or online at http://www.openafs.org/dl/license10.html
10 #include <afsconfig.h>
11 #include <afs/param.h>
15 #include <sys/types.h>
19 #include <sys/socket.h>
20 #include <netinet/in.h>
28 struct bc_config *bc_globalConfig;
30 static TrimLine(abuffer,aport)
32 register char *abuffer; {
37 sscanf(abuffer,"%s %u",garb,aport);
38 while(tc = *abuffer) {
48 FILE *bc_open(aconfig, aname, aext, amode)
49 register struct bc_config *aconfig;
56 strcpy(tpath, aconfig->path);
59 if (aext) strcat(tpath, aext);
60 tf = fopen(tpath, amode);
67 register struct bc_config *tb;
68 register struct bc_hostEntry *the;
70 /* initialize global config structure */
71 tb = (struct bc_config *) malloc(sizeof(struct bc_config));
72 if (!tb) return(BC_NOMEM);
75 memset(tb, 0, sizeof(struct bc_config));
76 tb->path = (char *) malloc(strlen(apath)+1);
83 strcpy(tb->path, apath);
85 /* now read the important config files; no file means empty list during system init */
90 static HostAdd(alist, aname,aport)
91 struct bc_hostEntry **alist;
94 register struct bc_hostEntry **tlast, *tentry;
97 /* check that the host address is real */
98 th = gethostbyname(aname);
101 /* check if this guy is already in the list */
102 for(tentry = *alist; tentry; tentry=tentry->next)
103 if (tentry->portOffset == aport) return EEXIST;
105 /* add this guy to the end of the list */
107 for(tentry = *tlast; tentry; tlast = &tentry->next, tentry = *tlast);
109 /* tlast now points to the next pointer (or head pointer) we should overwrite */
110 tentry = (struct bc_hostEntry *) malloc(sizeof(struct bc_hostEntry));
111 memset(tentry, 0, sizeof(*tentry));
112 tentry->name = (char *) malloc(strlen(aname)+1);
113 strcpy(tentry->name, aname);
115 tentry->next = (struct bc_hostEntry *) 0;
116 tentry->addr.sin_family = AF_INET;
117 memcpy(&tentry->addr.sin_addr.s_addr, th->h_addr, sizeof(afs_int32));
118 tentry->addr.sin_port = 0;
119 #ifdef STRUCT_SOCKADDR_HAS_SA_LEN
120 tentry->addr.sin_len = sizeof(struct sockaddr_in);
122 tentry->portOffset = aport;
126 static HostDelete(alist, aname,aport)
127 struct bc_hostEntry **alist;
130 register struct bc_hostEntry **tlast, *tentry;
132 /* find guy to zap */
134 for(tentry = *tlast; tentry; tlast = &tentry->next, tentry = *tlast)
135 if (strcmp(tentry->name, aname) == 0 && (aport == tentry->portOffset))
137 if (!tentry) return ENOENT; /* failed to find it */
139 /* otherwise delete the entry from the list and free appropriate structures */
140 *tlast = tentry->next;
146 bc_AddTapeHost(aconfig, aname,aport)
147 struct bc_config *aconfig;
150 register afs_int32 code;
152 code = HostAdd(&aconfig->tapeHosts, aname,aport);
157 bc_DeleteTapeHost(aconfig, aname, aport)
158 struct bc_config *aconfig;
161 register afs_int32 code;
163 code = HostDelete(&aconfig->tapeHosts, aname, aport);