ftp.nice.ch/peanuts/GeneralData/Usenet/news/1989/CSN-89.tar.gz#/comp-sys-next/1989/May-Jun/NetInfo-problem

This is NetInfo-problem in view mode; [Up]


Date: Sun 30-May-1989 17:07:20 From: Unknown Subject: NetInfo problem (and kludged solution) I've been trying to figure out, for the last two weeks or so, why I can't send out any mail. Turns out that niload, when I load a hosts file, is taking the *last* entry for hosts that have duplicate entries, meaning that it's finding a bogus entry for my mailhost. In other words, it overwrites any entries that it loads in with subsequent entries for the same host. Blech. A kludge of a solution is to reverse the lines of the hosts file before you feed it to niload. A better solution would depend on being able to muck with niload. Here's a cheap way to reverse the lines in the file. Compile the code included here into rcat, and then do the following: # rev /etc/hosts > /tmp/blurfle # rcat /tmp/blurfle > hosts.rev # niload hosts . < hosts.rev # rm blurfle You could, of course, do the same thing with an awk script, but then it would have to read the whole thing into memory at the same time. Of course, niload takes a v e r y l o n g t i m e to run, so any effiency gained here probably won't matter much... Here's rcat.c: ----- cut here ----- #include <stdio.h> #define BufSize 4096 /* * rcat * * Reverses a text file. Can be used in conjunction with rev to * reverse the lines in a file (the first shall be last...). * * Copyright 1989, Scott Deerwester. This code may be freely used, * hacked, used for kitty litter... provide that this notice * accompanies all copies (except for copies used for kitty litter :-) */ char buf[BufSize], rbuf[BufSize]; main (int argc, char *argv[]) { register i; FILE *fp; if (argc == 1) reverse (stdin); else for (i = 1; i < argc; i++) { if ((fp = fopen (argv[i], "r")) == NULL) { fprintf (stderr, "Can't open %s\n", argv[i]); continue; } reverse (fp); fclose (fp); } exit (0); } reverse (FILE *fp) { register j; long fsize; fseek (fp, 0L, 2); fsize = ftell (fp); for (j = fsize / BufSize; j >= 0; j--) { register n, k; fseek (fp, (long) j * BufSize, 0); if ((n = fread (buf, 1, BufSize, fp)) <= 0) { fprintf (stderr, "Read error at block %d\n", j); break; } /* * The last line in the file is a newline. Don't print it. */ if (n < BufSize) n--; for (k = 0; k < n; k++) { rbuf[n - k - 1] = buf[k]; } fwrite (rbuf, n, 1, stdout); } /* * We *do*, on the other hand, want to end the first line with a * newline. Tack one on. */ putchar ('\n'); } ------- How might I avoid going through all of this if I can connect to a name server? I've been hesitant to mess with it, not really understanding the innards of NetInfo. ------- Scott Deerwester | Internet: scott@tira.uchicago.edu C* {for,of,in} Information S* | Phone: 312-702-6948 University of Chicago | Scott Deerwester | Internet: scott@tira.uchicago.edu C* {for,of,in} Information S* | Phone: 312-702-6948 University of Chicago | >From: scott@sage.uchicago.edu (Scott Deerwester)
Date: Sun 30-May-1989 17:07:20 From: Unknown Subject: NetInfo problem (and kludged solution) I've been trying to figure out, for the last two weeks or so, why I can't send out any mail. Turns out that niload, when I load a hosts file, is taking the *last* entry for hosts that have duplicate entries, meaning that it's finding a bogus entry for my mailhost. In other words, it overwrites any entries that it loads in with subsequent entries for the same host. Blech. A kludge of a solution is to reverse the lines of the hosts file before you feed it to niload. A better solution would depend on being able to muck with niload. Here's a cheap way to reverse the lines in the file. Compile the code included here into rcat, and then do the following: # rev /etc/hosts > /tmp/blurfle # rcat /tmp/blurfle > hosts.rev # niload hosts . < hosts.rev # rm blurfle You could, of course, do the same thing with an awk script, but then it would have to read the whole thing into memory at the same time. Of course, niload takes a v e r y l o n g t i m e to run, so any effiency gained here probably won't matter much... Here's rcat.c: ----- cut here ----- #include <stdio.h> #define BufSize 4096 /* * rcat * * Reverses a text file. Can be used in conjunction with rev to * reverse the lines in a file (the first shall be last...). * * Copyright 1989, Scott Deerwester. This code may be freely used, * hacked, used for kitty litter... provide that this notice * accompanies all copies (except for copies used for kitty litter :-) */ char buf[BufSize], rbuf[BufSize]; main (int argc, char *argv[]) { register i; FILE *fp; if (argc == 1) reverse (stdin); else for (i = 1; i < argc; i++) { if ((fp = fopen (argv[i], "r")) == NULL) { fprintf (stderr, "Can't open %s\n", argv[i]); continue; } reverse (fp); fclose (fp); } exit (0); } reverse (FILE *fp) { register j; long fsize; fseek (fp, 0L, 2); fsize = ftell (fp); for (j = fsize / BufSize; j >= 0; j--) { register n, k; fseek (fp, (long) j * BufSize, 0); if ((n = fread (buf, 1, BufSize, fp)) <= 0) { fprintf (stderr, "Read error at block %d\n", j); break; } /* * The last line in the file is a newline. Don't print it. */ if (n < BufSize) n--; for (k = 0; k < n; k++) { rbuf[n - k - 1] = buf[k]; } fwrite (rbuf, n, 1, stdout); } /* * We *do*, on the other hand, want to end the first line with a * newline. Tack one on. */ putchar ('\n'); } ------- How might I avoid going through all of this if I can connect to a name server? I've been hesitant to mess with it, not really understanding the innards of NetInfo. ------- Scott Deerwester | Internet: scott@tira.uchicago.edu C* {for,of,in} Information S* | Phone: 312-702-6948 University of Chicago | Scott Deerwester | Internet: scott@tira.uchicago.edu C* {for,of,in} Information S* | Phone: 312-702-6948 University of Chicago | >From: fqoj@vax5.CIT.CORNELL.EDU

These are the contents of the former NiCE NeXT User Group NeXTSTEP/OpenStep software archive, currently hosted by Marcel Waldvogel and Netfuture.ch.