2 * Copyright (C) 1993-2001 by Darren Reed.
4 * See the IPFILTER.LICENCE file for details on licencing.
6 * $Id: ipft_sn.c,v 1.7 2003/02/16 02:32:36 darrenr Exp $
10 * Written to comply with the recent RFC 1761 from Sun.
16 static const char rcsid
[] = "@(#)$Id: ipft_sn.c,v 1.7 2003/02/16 02:32:36 darrenr Exp $";
19 int lc_sz
; /* LLC header length */
20 int lc_to
; /* LLC Type offset */
21 int lc_tl
; /* LLC Type length */
25 * While many of these maybe the same, some do have different header formats
26 * which make this useful.
28 static struct llc llcs
[SDL_MAX
+1] = {
29 { 0, 0, 0 }, /* SDL_8023 */
30 { 0, 0, 0 }, /* SDL_8024 */
31 { 0, 0, 0 }, /* SDL_8025 */
32 { 0, 0, 0 }, /* SDL_8026 */
33 { 14, 12, 2 }, /* SDL_ETHER */
34 { 0, 0, 0 }, /* SDL_HDLC */
35 { 0, 0, 0 }, /* SDL_CHSYNC */
36 { 0, 0, 0 }, /* SDL_IBMCC */
37 { 0, 0, 0 }, /* SDL_FDDI */
38 { 0, 0, 0 }, /* SDL_OTHER */
41 static int snoop_open
__P((char *));
42 static int snoop_close
__P((void));
43 static int snoop_readip
__P((char *, int, char **, int *));
45 static int sfd
= -1, s_type
= -1;
46 static int snoop_read_rec
__P((struct snooppkt
*));
48 struct ipread snoop
= { snoop_open
, snoop_close
, snoop_readip
, 0 };
51 static int snoop_open(fname
)
61 if (!strcmp(fname
, "-"))
63 else if ((fd
= open(fname
, O_RDONLY
)) == -1)
66 if (read(fd
, (char *)&sh
, sizeof(sh
)) != sizeof(sh
))
69 s_v
= (int)ntohl(sh
.s_v
);
70 s_type
= (int)ntohl(sh
.s_type
);
72 if (s_v
!= SNOOP_VERSION
||
73 s_type
< 0 || s_type
> SDL_MAX
) {
79 printf("opened snoop file %s:\n", fname
);
80 printf("\tid: %8.8s version: %d type: %d\n", sh
.s_id
, s_v
, s_type
);
86 static int snoop_close()
93 * read in the header (and validate) which should be the first record
96 static int snoop_read_rec(rec
)
101 if (read(sfd
, (char *)rec
, sizeof(*rec
)) != sizeof(*rec
))
104 ilen
= (int)ntohl(rec
->sp_ilen
);
105 plen
= (int)ntohl(rec
->sp_plen
);
106 if (ilen
> plen
|| plen
< sizeof(*rec
))
109 plen
-= sizeof(*rec
);
120 * read an entire snoop packet record. only the data part is copied into
121 * the available buffer, with the number of bytes copied returned.
123 static int snoop_read(buf
, cnt
)
128 static char *bufp
= NULL
;
131 if ((i
= snoop_read_rec(&rec
)) <= 0)
137 bufp
= realloc(bufp
, i
);
139 if (read(sfd
, bufp
, i
) != i
)
150 * return only an IP packet read into buf
152 static int snoop_readip(buf
, cnt
, ifn
, dir
)
156 static char *bufp
= NULL
;
163 if ((i
= snoop_read_rec(&rec
)) <= 0)
169 bufp
= realloc(bufp
, i
);
172 if (read(sfd
, s
, i
) != i
)
179 * XXX - bogus assumption here on the part of the time field
180 * that it won't be greater than 4 bytes and the 1st two will
181 * have the values 8 and 0 for IP. Should be a table of
182 * these too somewhere. Really only works for SDL_ETHER.
184 bcopy(s
, ty
, l
->lc_tl
);
185 } while (ty
[0] != 0x8 && ty
[1] != 0);