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>
14 #include <sys/types.h>
18 #include <sys/socket.h>
19 #include <netinet/in.h>
26 struct bc_config *bc_globalConfig;
30 TrimLine(char *abuffer, afs_int32 *aport)
36 sscanf(abuffer, "%s %u", garb, aport);
37 while ((tc = *abuffer)) {
49 bc_open(struct bc_config *aconfig, char *aname, char *aext, char *amode)
54 strcpy(tpath, aconfig->path);
59 tf = fopen(tpath, amode);
64 bc_InitConfig(char *apath)
66 register struct bc_config *tb;
68 /* initialize global config structure */
69 tb = (struct bc_config *)malloc(sizeof(struct bc_config));
74 memset(tb, 0, sizeof(struct bc_config));
75 tb->path = (char *)malloc(strlen(apath) + 1);
81 strcpy(tb->path, apath);
83 /* now read the important config files; no file means empty list during system init */
89 HostAdd(struct bc_hostEntry **alist, char *aname, afs_int32 aport)
91 register struct bc_hostEntry **tlast, *tentry;
94 /* check that the host address is real */
95 th = gethostbyname(aname);
99 /* check if this guy is already in the list */
100 for (tentry = *alist; tentry; tentry = tentry->next)
101 if (tentry->portOffset == aport)
104 /* add this guy to the end of the list */
106 for (tentry = *tlast; tentry; tlast = &tentry->next, tentry = *tlast);
108 /* tlast now points to the next pointer (or head pointer) we should overwrite */
109 tentry = (struct bc_hostEntry *)malloc(sizeof(struct bc_hostEntry));
110 memset(tentry, 0, sizeof(*tentry));
111 tentry->name = (char *)malloc(strlen(aname) + 1);
112 strcpy(tentry->name, aname);
114 tentry->next = (struct bc_hostEntry *)0;
115 tentry->addr.sin_family = AF_INET;
116 memcpy(&tentry->addr.sin_addr.s_addr, th->h_addr, sizeof(afs_int32));
117 tentry->addr.sin_port = 0;
118 #ifdef STRUCT_SOCKADDR_HAS_SA_LEN
119 tentry->addr.sin_len = sizeof(struct sockaddr_in);
121 tentry->portOffset = aport;
126 HostDelete(struct bc_hostEntry **alist, char *aname, afs_int32 aport)
128 register struct bc_hostEntry **tlast, *tentry;
130 /* find guy to zap */
132 for (tentry = *tlast; tentry; tlast = &tentry->next, tentry = *tlast)
133 if (strcmp(tentry->name, aname) == 0 && (aport == tentry->portOffset))
136 return ENOENT; /* failed to find it */
138 /* otherwise delete the entry from the list and free appropriate structures */
139 *tlast = tentry->next;
146 bc_AddTapeHost(struct bc_config *aconfig, char *aname, afs_int32 aport)
148 register afs_int32 code;
150 code = HostAdd(&aconfig->tapeHosts, aname, aport);
156 bc_DeleteTapeHost(struct bc_config *aconfig, char *aname, afs_int32 aport)
158 register afs_int32 code;
160 code = HostDelete(&aconfig->tapeHosts, aname, aport);