gencode.c (26178) | gencode.c (39294) |
---|---|
1/* | 1/* |
2 * Copyright (c) 1990, 1991, 1992, 1993, 1994, 1995, 1996 | 2 * Copyright (c) 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998 |
3 * The Regents of the University of California. All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that: (1) source code distributions 7 * retain the above copyright notice and this paragraph in its entirety, (2) 8 * distributions including binary code include the above copyright notice and 9 * this paragraph in its entirety in the documentation or other materials 10 * provided with the distribution, and (3) all advertising materials mentioning --- 4 unchanged lines hidden (view full) --- 15 * or promote products derived from this software without specific prior 16 * written permission. 17 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED 18 * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF 19 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 20 */ 21#ifndef lint 22static const char rcsid[] = | 3 * The Regents of the University of California. All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that: (1) source code distributions 7 * retain the above copyright notice and this paragraph in its entirety, (2) 8 * distributions including binary code include the above copyright notice and 9 * this paragraph in its entirety in the documentation or other materials 10 * provided with the distribution, and (3) all advertising materials mentioning --- 4 unchanged lines hidden (view full) --- 15 * or promote products derived from this software without specific prior 16 * written permission. 17 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED 18 * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF 19 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 20 */ 21#ifndef lint 22static const char rcsid[] = |
23 "@(#) $Header: gencode.c,v 1.91 96/12/11 19:10:23 leres Exp $ (LBL)"; | 23 "@(#) $Header: gencode.c,v 1.94 98/07/12 13:06:49 leres Exp $ (LBL)"; |
24#endif 25 26#include <sys/types.h> 27#include <sys/socket.h> 28#include <sys/time.h> 29 30#if __STDC__ 31struct mbuf; --- 15 unchanged lines hidden (view full) --- 47#include <varargs.h> 48#endif 49 50#include "pcap-int.h" 51 52#include "ethertype.h" 53#include "nlpid.h" 54#include "gencode.h" | 24#endif 25 26#include <sys/types.h> 27#include <sys/socket.h> 28#include <sys/time.h> 29 30#if __STDC__ 31struct mbuf; --- 15 unchanged lines hidden (view full) --- 47#include <varargs.h> 48#endif 49 50#include "pcap-int.h" 51 52#include "ethertype.h" 53#include "nlpid.h" 54#include "gencode.h" |
55#include "ppp.h" |
|
55#include <pcap-namedb.h> 56 57#include "gnuc.h" 58#ifdef HAVE_OS_PROTO_H 59#include "os-proto.h" 60#endif 61 62#define JMP(c) ((c)|BPF_JMP|BPF_K) --- 407 unchanged lines hidden (view full) --- 470 /* 471 * SLIP doesn't have a link level type. The 16 byte 472 * header is hacked into our SLIP driver. 473 */ 474 off_linktype = -1; 475 off_nl = 16; 476 return; 477 | 56#include <pcap-namedb.h> 57 58#include "gnuc.h" 59#ifdef HAVE_OS_PROTO_H 60#include "os-proto.h" 61#endif 62 63#define JMP(c) ((c)|BPF_JMP|BPF_K) --- 407 unchanged lines hidden (view full) --- 471 /* 472 * SLIP doesn't have a link level type. The 16 byte 473 * header is hacked into our SLIP driver. 474 */ 475 off_linktype = -1; 476 off_nl = 16; 477 return; 478 |
479 case DLT_SLIP_BSDOS: 480 /* XXX this may be the same as the DLT_PPP_BSDOS case */ 481 off_linktype = -1; 482 /* XXX end */ 483 off_nl = 24; 484 return; 485 |
|
478 case DLT_NULL: 479 off_linktype = 0; 480 off_nl = 4; 481 return; 482 483 case DLT_PPP: 484 off_linktype = 2; 485 off_nl = 4; 486 return; 487 | 486 case DLT_NULL: 487 off_linktype = 0; 488 off_nl = 4; 489 return; 490 491 case DLT_PPP: 492 off_linktype = 2; 493 off_nl = 4; 494 return; 495 |
496 case DLT_PPP_BSDOS: 497 off_linktype = 5; 498 off_nl = 24; 499 return; 500 |
|
488 case DLT_FDDI: 489 /* 490 * FDDI doesn't really have a link-level type field. 491 * We assume that SSAP = SNAP is being used and pick 492 * out the encapsulated Ethernet type. 493 */ 494 off_linktype = 19; 495#ifdef PCAP_FDDIPAD --- 52 unchanged lines hidden (view full) --- 548static inline struct block * 549gen_false() 550{ 551 return gen_uncond(0); 552} 553 554static struct block * 555gen_linktype(proto) | 501 case DLT_FDDI: 502 /* 503 * FDDI doesn't really have a link-level type field. 504 * We assume that SSAP = SNAP is being used and pick 505 * out the encapsulated Ethernet type. 506 */ 507 off_linktype = 19; 508#ifdef PCAP_FDDIPAD --- 52 unchanged lines hidden (view full) --- 561static inline struct block * 562gen_false() 563{ 564 return gen_uncond(0); 565} 566 567static struct block * 568gen_linktype(proto) |
556 int proto; | 569 register int proto; |
557{ | 570{ |
571 struct block *b0, *b1; 572 |
|
558 /* If we're not using encapsulation and checking for IP, we're done */ 559 if (off_linktype == -1 && proto == ETHERTYPE_IP) 560 return gen_true(); 561 562 switch (linktype) { 563 564 case DLT_SLIP: 565 return gen_false(); 566 567 case DLT_PPP: 568 if (proto == ETHERTYPE_IP) | 573 /* If we're not using encapsulation and checking for IP, we're done */ 574 if (off_linktype == -1 && proto == ETHERTYPE_IP) 575 return gen_true(); 576 577 switch (linktype) { 578 579 case DLT_SLIP: 580 return gen_false(); 581 582 case DLT_PPP: 583 if (proto == ETHERTYPE_IP) |
569 proto = 0x0021; /* XXX - need ppp.h defs */ | 584 proto = PPP_IP; /* XXX was 0x21 */ |
570 break; 571 | 585 break; 586 |
587 case DLT_PPP_BSDOS: 588 switch (proto) { 589 590 case ETHERTYPE_IP: 591 b0 = gen_cmp(off_linktype, BPF_H, PPP_IP); 592 b1 = gen_cmp(off_linktype, BPF_H, PPP_VJC); 593 gen_or(b0, b1); 594 b0 = gen_cmp(off_linktype, BPF_H, PPP_VJNC); 595 gen_or(b1, b0); 596 return b0; 597 598 case ETHERTYPE_DN: 599 proto = PPP_DECNET; 600 break; 601 602 case ETHERTYPE_ATALK: 603 proto = PPP_APPLE; 604 break; 605 606 case ETHERTYPE_NS: 607 proto = PPP_NS; 608 break; 609 } 610 break; 611 |
|
572 case DLT_NULL: 573 /* XXX */ 574 if (proto == ETHERTYPE_IP) 575 return (gen_cmp(0, BPF_W, (bpf_int32)htonl(AF_INET))); 576 else 577 return gen_false(); 578 case DLT_EN10MB: 579 /* --- 789 unchanged lines hidden (view full) --- 1369 nlen = __pcap_atoin(s1, &n); 1370 /* Promote short ipaddr */ 1371 n <<= 32 - nlen; 1372 1373 if (s2 != NULL) { 1374 mlen = __pcap_atoin(s2, &m); 1375 /* Promote short ipaddr */ 1376 m <<= 32 - mlen; | 612 case DLT_NULL: 613 /* XXX */ 614 if (proto == ETHERTYPE_IP) 615 return (gen_cmp(0, BPF_W, (bpf_int32)htonl(AF_INET))); 616 else 617 return gen_false(); 618 case DLT_EN10MB: 619 /* --- 789 unchanged lines hidden (view full) --- 1409 nlen = __pcap_atoin(s1, &n); 1410 /* Promote short ipaddr */ 1411 n <<= 32 - nlen; 1412 1413 if (s2 != NULL) { 1414 mlen = __pcap_atoin(s2, &m); 1415 /* Promote short ipaddr */ 1416 m <<= 32 - mlen; |
1417 if ((n & ~m) != 0) 1418 bpf_error("non-network bits set in \"%s mask %s\"", 1419 s1, s2); |
|
1377 } else { 1378 /* Convert mask len to mask */ 1379 if (masklen > 32) 1380 bpf_error("mask length must be <= 32"); 1381 m = 0xffffffff << (32 - masklen); | 1420 } else { 1421 /* Convert mask len to mask */ 1422 if (masklen > 32) 1423 bpf_error("mask length must be <= 32"); 1424 m = 0xffffffff << (32 - masklen); |
1425 if ((n & ~m) != 0) 1426 bpf_error("non-network bits set in \"%s/%d\"", 1427 s1, masklen); |
|
1382 } 1383 1384 switch (q.addr) { 1385 1386 case Q_NET: 1387 return gen_host(n, m, q.proto, q.dir); 1388 1389 default: --- 554 unchanged lines hidden --- | 1428 } 1429 1430 switch (q.addr) { 1431 1432 case Q_NET: 1433 return gen_host(n, m, q.proto, q.dir); 1434 1435 default: --- 554 unchanged lines hidden --- |