2 * Copyright (C) 1993-1998 by Darren Reed.
4 * Redistribution and use in source and binary forms are permitted
5 * provided that this notice is preserved and due credit is given
6 * to the original author and the contributors.
10 * Written to comply with the recent RFC 1761 from Sun.
14 #if !defined(__SVR4) && !defined(__GNUC__)
17 #include <sys/types.h>
21 #include <sys/socket.h>
22 #include <sys/ioctl.h>
23 #include <sys/param.h>
25 #include <netinet/in.h>
26 #include <netinet/in_systm.h>
28 #include <netinet/ip_var.h>
30 #include <netinet/ip.h>
31 #include <netinet/tcp.h>
33 #include "ip_compat.h"
34 #include <netinet/tcpip.h>
40 static const char rcsid[] = "@(#)$Id: ipft_sn.c,v 2.1 1999/08/04 17:30:04 darrenr Exp $";
44 int lc_sz; /* LLC header length */
45 int lc_to; /* LLC Type offset */
46 int lc_tl; /* LLC Type length */
50 * While many of these maybe the same, some do have different header formats
51 * which make this useful.
53 static struct llc llcs[SDL_MAX+1] = {
54 { 0, 0, 0 }, /* SDL_8023 */
55 { 0, 0, 0 }, /* SDL_8024 */
56 { 0, 0, 0 }, /* SDL_8025 */
57 { 0, 0, 0 }, /* SDL_8026 */
58 { 14, 12, 2 }, /* SDL_ETHER */
59 { 0, 0, 0 }, /* SDL_HDLC */
60 { 0, 0, 0 }, /* SDL_CHSYNC */
61 { 0, 0, 0 }, /* SDL_IBMCC */
62 { 0, 0, 0 }, /* SDL_FDDI */
63 { 0, 0, 0 }, /* SDL_OTHER */
66 static int snoop_open __P((char *));
67 static int snoop_close __P((void));
68 static int snoop_readip __P((char *, int, char **, int *));
70 static int sfd = -1, s_type = -1;
71 static int snoop_read_rec __P((struct snooppkt *));
73 struct ipread snoop = { snoop_open, snoop_close, snoop_readip };
76 static int snoop_open(fname)
85 if (!strcmp(fname, "-"))
87 else if ((fd = open(fname, O_RDONLY)) == -1)
90 if (read(fd, (char *)&sh, sizeof(sh)) != sizeof(sh))
93 if (sh.s_v != SNOOP_VERSION ||
94 sh.s_type < 0 || sh.s_type > SDL_MAX) {
101 printf("opened snoop file %s:\n", fname);
102 printf("\tid: %8.8s version: %d type: %d\n", sh.s_id, sh.s_v, s_type);
108 static int snoop_close()
115 * read in the header (and validate) which should be the first record
118 static int snoop_read_rec(rec)
119 struct snooppkt *rec;
123 if (read(sfd, (char *)rec, sizeof(*rec)) != sizeof(*rec))
126 if (rec->sp_ilen > rec->sp_plen || rec->sp_plen < sizeof(*rec))
129 p = rec->sp_plen - sizeof(*rec);
130 n = MIN(p, rec->sp_ilen);
140 * read an entire snoop packet record. only the data part is copied into
141 * the available buffer, with the number of bytes copied returned.
143 static int snoop_read(buf, cnt)
148 static char *bufp = NULL;
151 if ((i = snoop_read_rec(&rec)) <= 0)
157 bufp = realloc(bufp, i);
159 if (read(sfd, bufp, i) != i)
170 * return only an IP packet read into buf
172 static int snoop_readip(buf, cnt, ifn, dir)
176 static char *bufp = NULL;
183 if ((i = snoop_read_rec(&rec)) <= 0)
189 bufp = realloc(bufp, i);
192 if (read(sfd, s, i) != i)
199 * XXX - bogus assumption here on the part of the time field
200 * that it won't be greater than 4 bytes and the 1st two will
201 * have the values 8 and 0 for IP. Should be a table of
202 * these too somewhere. Really only works for SDL_ETHER.
204 bcopy(s, ty, l->lc_tl);
205 } while (ty[0] != 0x8 && ty[1] != 0);