projects
/
unix-history
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
tags
|
clone url
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
make it look like kernel driver
[unix-history]
/
usr
/
src
/
old
/
gettable
/
gettable.c
diff --git
a/usr/src/old/gettable/gettable.c
b/usr/src/old/gettable/gettable.c
index
825936f
..
f4b90a8
100644
(file)
--- a/
usr/src/old/gettable/gettable.c
+++ b/
usr/src/old/gettable/gettable.c
@@
-1,6
+1,12
@@
+/*
+ * Copyright (c) 1983 Regents of the University of California.
+ * All rights reserved. The Berkeley software License Agreement
+ * specifies the terms and conditions for redistribution.
+ */
+
#ifndef lint
#ifndef lint
-static char sccsid[] = "@(#)gettable.c
4.4
(Berkeley) %G%";
-#endif
+static char sccsid[] = "@(#)gettable.c
5.2
(Berkeley) %G%";
+#endif
not lint
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/types.h>
#include <sys/socket.h>
@@
-28,11
+34,12
@@
main(argc, argv)
int s;
register len;
register FILE *sfi, *sfo, *hf;
int s;
register len;
register FILE *sfi, *sfo, *hf;
- register char *p;
char *host;
register struct hostent *hp;
struct servent *sp;
int version = 0;
char *host;
register struct hostent *hp;
struct servent *sp;
int version = 0;
+ int beginseen = 0;
+ int endseen = 0;
argv++, argc--;
if (**argv == '-') {
argv++, argc--;
if (**argv == '-') {
@@
-62,18
+69,18
@@
main(argc, argv)
if (argc > 0)
outfile = *argv;
sin.sin_family = hp->h_addrtype;
if (argc > 0)
outfile = *argv;
sin.sin_family = hp->h_addrtype;
- s = socket(hp->h_addrtype, SOCK_STREAM, 0
, 0
);
+ s = socket(hp->h_addrtype, SOCK_STREAM, 0);
if (s < 0) {
perror("gettable: socket");
exit(4);
}
if (s < 0) {
perror("gettable: socket");
exit(4);
}
- if (bind(s, &sin, sizeof (sin)
, 0
) < 0) {
+ if (bind(s, &sin, sizeof (sin)) < 0) {
perror("gettable: bind");
exit(5);
}
perror("gettable: bind");
exit(5);
}
- bcopy(hp->h_addr, &sin.sin_addr, hp->h_length);
+ bcopy(hp->h_addr,
(char *)
&sin.sin_addr, hp->h_length);
sin.sin_port = sp->s_port;
sin.sin_port = sp->s_port;
- if (connect(s, &sin, sizeof (sin)
, 0
) < 0) {
+ if (connect(s, &sin, sizeof (sin)) < 0) {
perror("gettable: connect");
exit(6);
}
perror("gettable: connect");
exit(6);
}
@@
-96,20
+103,44
@@
main(argc, argv)
while (fgets(buf, sizeof(buf), sfi) != NULL) {
len = strlen(buf);
buf[len-2] = '\0';
while (fgets(buf, sizeof(buf), sfi) != NULL) {
len = strlen(buf);
buf[len-2] = '\0';
- if (equaln(buf, "BEGIN", 5) || equaln(buf, "END", 3)) {
+ if (!version && equaln(buf, "BEGIN", 5)) {
+ if (beginseen || endseen) {
+ fprintf(stderr,
+ "gettable: BEGIN sequence error\n");
+ exit(90);
+ }
+ beginseen++;
continue;
}
continue;
}
- if (equaln(buf, "ERR", 3)) {
- fprintf(stderr, "gettable: hostnames error: %s", buf);
+ if (!version && equaln(buf, "END", 3)) {
+ if (!beginseen || endseen) {
+ fprintf(stderr,
+ "gettable: END sequence error\n");
+ exit(91);
+ }
+ endseen++;
continue;
}
continue;
}
+ if (equaln(buf, "ERR", 3)) {
+ fprintf(stderr,
+ "gettable: hostname service error: %s", buf);
+ exit(92);
+ }
fprintf(hf, "%s\n", buf);
}
fclose(hf);
fprintf(hf, "%s\n", buf);
}
fclose(hf);
- if (version)
- fprintf(stderr, "Version number received.\n");
- else
+ if (!version) {
+ if (!beginseen) {
+ fprintf(stderr, "gettable: no BEGIN seen\n");
+ exit(93);
+ }
+ if (!endseen) {
+ fprintf(stderr, "gettable: no END seen\n");
+ exit(94);
+ }
fprintf(stderr, "Host table received.\n");
fprintf(stderr, "Host table received.\n");
+ } else
+ fprintf(stderr, "Version number received.\n");
close(s);
fprintf(stderr, "Connection to %s closed\n", host);
exit(0);
close(s);
fprintf(stderr, "Connection to %s closed\n", host);
exit(0);