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>
17 struct bc_config
*bc_globalConfig
;
21 TrimLine(char *abuffer
, afs_int32
*aport
)
27 sscanf(abuffer
, "%s %u", garb
, aport
);
28 while ((tc
= *abuffer
)) {
40 bc_open(struct bc_config
*aconfig
, char *aname
, char *aext
, char *amode
)
45 strcpy(tpath
, aconfig
->path
);
50 tf
= fopen(tpath
, amode
);
55 bc_InitConfig(char *apath
)
59 /* initialize global config structure */
60 tb
= calloc(1, sizeof(struct bc_config
));
65 tb
->path
= strdup(apath
);
71 /* now read the important config files; no file means empty list during system init */
77 HostAdd(struct bc_hostEntry
**alist
, char *aname
, afs_int32 aport
)
79 struct bc_hostEntry
**tlast
, *tentry
;
82 /* check that the host address is real */
83 th
= gethostbyname(aname
);
87 /* check if this guy is already in the list */
88 for (tentry
= *alist
; tentry
; tentry
= tentry
->next
)
89 if (tentry
->portOffset
== aport
)
92 /* add this guy to the end of the list */
94 for (tentry
= *tlast
; tentry
; tlast
= &tentry
->next
, tentry
= *tlast
);
96 /* tlast now points to the next pointer (or head pointer) we should overwrite */
97 tentry
= calloc(1, sizeof(struct bc_hostEntry
));
98 tentry
->name
= strdup(aname
);
100 tentry
->next
= (struct bc_hostEntry
*)0;
101 tentry
->addr
.sin_family
= AF_INET
;
102 memcpy(&tentry
->addr
.sin_addr
.s_addr
, th
->h_addr
, sizeof(afs_int32
));
103 tentry
->addr
.sin_port
= 0;
104 #ifdef STRUCT_SOCKADDR_HAS_SA_LEN
105 tentry
->addr
.sin_len
= sizeof(struct sockaddr_in
);
107 tentry
->portOffset
= aport
;
112 HostDelete(struct bc_hostEntry
**alist
, char *aname
, afs_int32 aport
)
114 struct bc_hostEntry
**tlast
, *tentry
;
116 /* find guy to zap */
118 for (tentry
= *tlast
; tentry
; tlast
= &tentry
->next
, tentry
= *tlast
)
119 if (strcmp(tentry
->name
, aname
) == 0 && (aport
== tentry
->portOffset
))
122 return ENOENT
; /* failed to find it */
124 /* otherwise delete the entry from the list and free appropriate structures */
125 *tlast
= tentry
->next
;
132 bc_AddTapeHost(struct bc_config
*aconfig
, char *aname
, afs_int32 aport
)
136 code
= HostAdd(&aconfig
->tapeHosts
, aname
, aport
);
142 bc_DeleteTapeHost(struct bc_config
*aconfig
, char *aname
, afs_int32 aport
)
146 code
= HostDelete(&aconfig
->tapeHosts
, aname
, aport
);