* Copyright (c) 1983 Regents of the University of California.
* All rights reserved. The Berkeley software License Agreement
* specifies the terms and conditions for redistribution.
"@(#) Copyright (c) 1980 Regents of the University of California.\n\
static char sccsid
[] = "@(#)mkhosts.c 5.1 (Berkeley) %G%";
register struct hostent
*hp
;
register char *cp
, *tp
, **sp
;
int verbose
= 0, entries
= 0, maxlen
= 0, error
= 0;
char tempname
[BUFSIZ
], newname
[BUFSIZ
];
if (argc
> 1 && strcmp(argv
[1], "-v") == 0) {
fprintf(stderr
, "usage: mkhosts [ -v ] file\n");
if (access(argv
[1], R_OK
) < 0) {
sprintf(tempname
, "%s.new", argv
[1]);
dp
= dbm_open(tempname
, O_WRONLY
|O_CREAT
|O_EXCL
, 0644);
fprintf(stderr
, "dbm_open failed: ");
while (hp
= gethostent()) {
for (sp
= hp
->h_aliases
; *sp
; sp
++) {
bcopy((char *)&naliases
, (char *)nap
, sizeof(int));
bcopy((char *)&hp
->h_addrtype
, cp
, sizeof (int));
bcopy((char *)&hp
->h_length
, cp
, sizeof (int));
bcopy(hp
->h_addr
, cp
, hp
->h_length
);
content
.dsize
= cp
- buf
;
printf("store %s, %d aliases\n", hp
->h_name
, naliases
);
key
.dsize
= strlen(hp
->h_name
);
if (dbm_store(dp
, key
, content
, DBM_INSERT
) < 0) {
for (sp
= hp
->h_aliases
; *sp
; sp
++) {
if (dbm_store(dp
, key
, content
, DBM_INSERT
) < 0) {
key
.dsize
= hp
->h_length
;
if (dbm_store(dp
, key
, content
, DBM_INSERT
) < 0) {
perror("dbm_store host address");
sprintf(tempname
, "%s.new.pag", argv
[1]);
sprintf(newname
, "%s.pag", argv
[1]);
if (rename(tempname
, newname
) < 0) {
sprintf(tempname
, "%s.new.dir", argv
[1]);
sprintf(newname
, "%s.dir", argv
[1]);
if (rename(tempname
, newname
) < 0) {
printf("%d host entries, maximum length %d\n", entries
, maxlen
);
sprintf(tempname
, "%s.new.pag", argv
[1]);
sprintf(tempname
, "%s.new.dir", argv
[1]);