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>
27 struct bc_config *bc_globalConfig;
31 TrimLine(char *abuffer, afs_int32 *aport)
37 sscanf(abuffer, "%s %u", garb, aport);
38 while ((tc = *abuffer)) {
50 bc_open(struct bc_config *aconfig, char *aname, char *aext, char *amode)
55 strcpy(tpath, aconfig->path);
60 tf = fopen(tpath, amode);
65 bc_InitConfig(char *apath)
69 /* initialize global config structure */
70 tb = (struct bc_config *)malloc(sizeof(struct bc_config));
75 memset(tb, 0, sizeof(struct bc_config));
76 tb->path = (char *)malloc(strlen(apath) + 1);
82 strcpy(tb->path, apath);
84 /* now read the important config files; no file means empty list during system init */
90 HostAdd(struct bc_hostEntry **alist, char *aname, afs_int32 aport)
92 struct bc_hostEntry **tlast, *tentry;
95 /* check that the host address is real */
96 th = gethostbyname(aname);
100 /* check if this guy is already in the list */
101 for (tentry = *alist; tentry; tentry = tentry->next)
102 if (tentry->portOffset == aport)
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;
127 HostDelete(struct bc_hostEntry **alist, char *aname, afs_int32 aport)
129 struct bc_hostEntry **tlast, *tentry;
131 /* find guy to zap */
133 for (tentry = *tlast; tentry; tlast = &tentry->next, tentry = *tlast)
134 if (strcmp(tentry->name, aname) == 0 && (aport == tentry->portOffset))
137 return ENOENT; /* failed to find it */
139 /* otherwise delete the entry from the list and free appropriate structures */
140 *tlast = tentry->next;
147 bc_AddTapeHost(struct bc_config *aconfig, char *aname, afs_int32 aport)
151 code = HostAdd(&aconfig->tapeHosts, aname, aport);
157 bc_DeleteTapeHost(struct bc_config *aconfig, char *aname, afs_int32 aport)
161 code = HostDelete(&aconfig->tapeHosts, aname, aport);