Explicitly map PACKET_ values to LINUX_SLL_ values, so that even if a
future Linux kernel changes the PACKET_ values out from under us, the values recorded in the packet header in DLT_LINUX_SLL captures does *not* change. Don't map ETH_P_802_2 to the packet length, map it and ETH_P_802_3 to standardized LINUX_SLL_P_ values, so that even if a future Linux kernel changes the ETH_P_ values out from under us, the values recorded in the packet header in DLT_LINUX_SLL captures does *not* change, and so that you don't have to be running on Linux to be able to handle DLT_LINUX_SLL captures.
This commit is contained in:
parent
db46beec77
commit
cf54e028ce
68
pcap-linux.c
68
pcap-linux.c
|
@ -26,7 +26,7 @@
|
|||
*/
|
||||
#ifndef lint
|
||||
static const char rcsid[] =
|
||||
"@(#) $Header: /tcpdump/master/libpcap/pcap-linux.c,v 1.45 2000-12-22 11:53:27 guy Exp $ (LBL)";
|
||||
"@(#) $Header: /tcpdump/master/libpcap/pcap-linux.c,v 1.46 2000-12-22 12:11:36 guy Exp $ (LBL)";
|
||||
#endif
|
||||
|
||||
/*
|
||||
|
@ -374,15 +374,65 @@ pcap_read_packet(pcap_t *handle, pcap_handler callback, u_char *userdata)
|
|||
packet_len += SLL_HDR_LEN;
|
||||
|
||||
hdrp = (struct sll_header *)handle->buffer;
|
||||
hdrp->sll_pkttype = htons(from.sll_pkttype);
|
||||
if (from.sll_protocol == ETH_P_802_2) {
|
||||
/*
|
||||
* This is an 802.3 packet; set the packet type
|
||||
* field to the length, in network byte order.
|
||||
*/
|
||||
hdrp->sll_protocol = htons(packet_len);
|
||||
} else
|
||||
|
||||
/*
|
||||
* Map the PACKET_ value to a LINUX_SLL_ value; we
|
||||
* want the same numerical value to be used in
|
||||
* the link-layer header even if the numerical values
|
||||
* for the PACKET_ #defines change, so that programs
|
||||
* that look at the packet type field will always be
|
||||
* able to handle DLT_LINUX_SLL captures.
|
||||
*/
|
||||
switch (from.sll_pktttype) {
|
||||
|
||||
case PACKET_HOST:
|
||||
hdrp->sll_pkttype = htons(LINUX_SLL_HOST);
|
||||
break;
|
||||
|
||||
case PACKET_BROADCAST:
|
||||
hdrp->sll_pkttype = htons(LINUX_SLL_BROADCAST);
|
||||
break;
|
||||
|
||||
case PACKET_MULTICAST:
|
||||
hdrp->sll_pkttype = htons(LINUX_SLL_MULTICAST);
|
||||
break;
|
||||
|
||||
case PACKET_OTHERHOST:
|
||||
hdrp->sll_pkttype = htons(LINUX_SLL_OTHERHOST);
|
||||
break;
|
||||
|
||||
case PACKET_OUTGOING:
|
||||
hdrp->sll_pkttype = htons(LINUX_SLL_OUTGOING);
|
||||
break;
|
||||
|
||||
default:
|
||||
hdrp->sll_pkttype = -1;
|
||||
break;
|
||||
}
|
||||
|
||||
/*
|
||||
* Map special Linux internal protocol types to
|
||||
* LINUX_SLL_P_ values; we want the same numerical
|
||||
* value to be used in the link-layer header even
|
||||
* if the numerical values for the ETH_P_ #defines
|
||||
* change, so that programs that look at the protocol
|
||||
* field will always be able to handle DLT_LINUX_SLL
|
||||
* captures.
|
||||
*/
|
||||
switch (ntohs(from.sll_protocol)) {
|
||||
|
||||
case ETH_P_802_2:
|
||||
hdrp->sll_protocol = ntohs(LINUX_SLL_P_802_2);
|
||||
break;
|
||||
|
||||
case ETH_P_802_3:
|
||||
hdrp->sll_protocol = ntohs(LINUX_SLL_P_802_3);
|
||||
break;
|
||||
|
||||
default:
|
||||
hdrp->sll_protocol = from.sll_protocol;
|
||||
break;
|
||||
}
|
||||
hdrp->sll_hatype = htons(from.sll_hatype);
|
||||
hdrp->sll_halen = htons(from.sll_halen);
|
||||
memcpy(hdrp->sll_addr, from.sll_addr,
|
||||
|
|
20
sll.h
20
sll.h
|
@ -35,7 +35,7 @@
|
|||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
* @(#) $Header: /tcpdump/master/libpcap/Attic/sll.h,v 1.1 2000-12-21 10:29:24 guy Exp $ (LBL)
|
||||
* @(#) $Header: /tcpdump/master/libpcap/Attic/sll.h,v 1.2 2000-12-22 12:11:36 guy Exp $ (LBL)
|
||||
*/
|
||||
|
||||
/*
|
||||
|
@ -77,13 +77,23 @@ struct sll_header {
|
|||
};
|
||||
|
||||
/*
|
||||
* The LINUX_SLL_ values; they are defined here so that they're available
|
||||
* even on systems other than Linux, but they should be given the same
|
||||
* values as the corresponding PACKET_ values on Linux. (Let's hope
|
||||
* those values never change.)
|
||||
* The LINUX_SLL_ values for "sll_pkttype"; these correspond to the
|
||||
* PACKET_ values on Linux, but are defined here so that they're
|
||||
* available even on systems other than Linux, and so that they
|
||||
* don't change even if the PACKET_ values change.
|
||||
*/
|
||||
#define LINUX_SLL_HOST 0
|
||||
#define LINUX_SLL_BROADCAST 1
|
||||
#define LINUX_SLL_MULTICAST 2
|
||||
#define LINUX_SLL_OTHERHOST 3
|
||||
#define LINUX_SLL_OUTGOING 4
|
||||
|
||||
/*
|
||||
* The LINUX_SLL_ values for "sll_protocol"; these correspond to the
|
||||
* ETH_P_ values on Linux, but are defined here so that they're
|
||||
* available even on systems other than Linux, and so that they
|
||||
* don't change even if the ETH_P_ values change.
|
||||
*/
|
||||
#define LINUX_SLL_P_802_3 0x0001 /* Novell 802.3 frames without 802.2 LLC header */
|
||||
#define LINUX_SLL_P_802_2 0x0004 /* 802.2 frames (not D/I/X Ethernet) */
|
||||
|
||||
|
|
Reference in New Issue