summaryrefslogtreecommitdiff
path: root/lib/libpcap/etherent.c
diff options
context:
space:
mode:
authorMichael Shalayeff <mickey@cvs.openbsd.org>1996-07-12 13:19:14 +0000
committerMichael Shalayeff <mickey@cvs.openbsd.org>1996-07-12 13:19:14 +0000
commit315030ef409756aa4e3157c7812a81792c64aed3 (patch)
tree3653ad97954580a6d932f9a7c2da2b25da87dbae /lib/libpcap/etherent.c
parentc7a13b78b636f513ae61e3cb593d0e5a543a3977 (diff)
bring it to the latest 0.2 LBL release.
Diffstat (limited to 'lib/libpcap/etherent.c')
-rw-r--r--lib/libpcap/etherent.c124
1 files changed, 66 insertions, 58 deletions
diff --git a/lib/libpcap/etherent.c b/lib/libpcap/etherent.c
index 53f9a07ef46..29af870e021 100644
--- a/lib/libpcap/etherent.c
+++ b/lib/libpcap/etherent.c
@@ -1,8 +1,7 @@
-/* $OpenBSD */
-/* $NetBSD: etherent.c,v 1.2 1995/03/06 11:38:14 mycroft Exp $ */
+/* $OpenBSD: etherent.c,v 1.4 1996/07/12 13:19:07 mickey Exp $ */
/*
- * Copyright (c) 1990, 1993, 1994
+ * Copyright (c) 1990, 1993, 1994, 1995
* The Regents of the University of California. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -23,20 +22,24 @@
*/
#ifndef lint
static char rcsid[] =
- "@(#) Header: etherent.c,v 1.8 94/06/20 19:07:50 leres Exp (LBL)";
+ "@(#) Header: etherent.c,v 1.18 95/10/07 03:08:12 leres Exp (LBL)";
#endif
#include <sys/types.h>
#include <ctype.h>
+#include <memory.h>
#include <pcap.h>
#include <pcap-namedb.h>
#include <stdio.h>
+#include <string.h>
-#ifndef __GNUC__
-#define inline
+#ifdef HAVE_OS_PROTO_H
+#include "os-proto.h"
#endif
+#include "pcap-int.h"
+
static inline int xdtoi(int);
static inline int skip_space(FILE *);
static inline int skip_line(FILE *);
@@ -86,66 +89,71 @@ pcap_next_etherent(FILE *fp)
register int c, d, i;
char *bp;
static struct pcap_etherent e;
- static int nline = 1;
- top:
- while (nline) {
+
+ memset((char *)&e, 0, sizeof(e));
+ do {
/* Find addr */
c = skip_space(fp);
if (c == '\n')
continue;
+
/* If this is a comment, or first thing on line
- cannot be ethernet address, skip the line. */
- else if (!isxdigit(c))
+ cannot be etehrnet address, skip the line. */
+ if (!isxdigit(c)) {
c = skip_line(fp);
- else {
- /* must be the start of an address */
- for (i = 0; i < 6; i += 1) {
- d = xdtoi(c);
- c = getc(fp);
- if (c != ':') {
- d <<= 4;
- d |= xdtoi(c);
- c = getc(fp);
- }
- e.addr[i] = d;
- if (c != ':')
- break;
+ continue;
+ }
+
+ /* must be the start of an address */
+ for (i = 0; i < 6; i += 1) {
+ d = xdtoi(c);
+ c = getc(fp);
+ if (isxdigit(c)) {
+ d <<= 4;
+ d |= xdtoi(c);
c = getc(fp);
}
- nline = 0;
+ e.addr[i] = d;
+ if (c != ':')
+ break;
+ c = getc(fp);
}
if (c == EOF)
- return 0;
- }
-
- /* If we started a new line, 'c' holds the char past the ether addr,
- which we assume is white space. If we are continuing a line,
- 'c' is garbage. In either case, we can throw it away. */
-
- c = skip_space(fp);
- if (c == '\n') {
- nline = 1;
- goto top;
- }
- else if (c == '#') {
- (void)skip_line(fp);
- nline = 1;
- goto top;
- }
- else if (c == EOF)
- return 0;
-
- /* Must be a name. */
- bp = e.name;
- /* Use 'd' to prevent buffer overflow. */
- d = sizeof(e.name) - 1;
- do {
- *bp++ = c;
- c = getc(fp);
- } while (!isspace(c) && c != EOF && --d > 0);
- *bp = '\0';
- if (c == '\n')
- nline = 1;
-
- return &e;
+ break;
+
+ /* Must be whitespace */
+ if (!isspace(c)) {
+ c = skip_line(fp);
+ continue;
+ }
+ c = skip_space(fp);
+
+ /* hit end of line... */
+ if (c == '\n')
+ continue;
+
+ if (c == '#') {
+ c = skip_line(fp);
+ continue;
+ }
+
+ /* pick up name */
+ bp = e.name;
+ /* Use 'd' to prevent buffer overflow. */
+ d = sizeof(e.name) - 1;
+ do {
+ *bp++ = c;
+ c = getc(fp);
+ } while (!isspace(c) && c != EOF && --d > 0);
+ *bp = '\0';
+
+ /* Eat trailing junk */
+ if (c != '\n')
+ (void)skip_line(fp);
+
+ return &e;
+
+ } while (c != EOF);
+
+ return (NULL);
}