xref: /aosp_15_r20/external/libpcap/pcap-util.h (revision 8b26181f966a6af5cf6981a6f474313de533bb28)
1*8b26181fSAndroid Build Coastguard Worker /*
2*8b26181fSAndroid Build Coastguard Worker  * Copyright (c) 1993, 1994, 1995, 1996, 1997
3*8b26181fSAndroid Build Coastguard Worker  *	The Regents of the University of California.  All rights reserved.
4*8b26181fSAndroid Build Coastguard Worker  *
5*8b26181fSAndroid Build Coastguard Worker  * Redistribution and use in source and binary forms, with or without
6*8b26181fSAndroid Build Coastguard Worker  * modification, are permitted provided that: (1) source code distributions
7*8b26181fSAndroid Build Coastguard Worker  * retain the above copyright notice and this paragraph in its entirety, (2)
8*8b26181fSAndroid Build Coastguard Worker  * distributions including binary code include the above copyright notice and
9*8b26181fSAndroid Build Coastguard Worker  * this paragraph in its entirety in the documentation or other materials
10*8b26181fSAndroid Build Coastguard Worker  * provided with the distribution, and (3) all advertising materials mentioning
11*8b26181fSAndroid Build Coastguard Worker  * features or use of this software display the following acknowledgement:
12*8b26181fSAndroid Build Coastguard Worker  * ``This product includes software developed by the University of California,
13*8b26181fSAndroid Build Coastguard Worker  * Lawrence Berkeley Laboratory and its contributors.'' Neither the name of
14*8b26181fSAndroid Build Coastguard Worker  * the University nor the names of its contributors may be used to endorse
15*8b26181fSAndroid Build Coastguard Worker  * or promote products derived from this software without specific prior
16*8b26181fSAndroid Build Coastguard Worker  * written permission.
17*8b26181fSAndroid Build Coastguard Worker  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
18*8b26181fSAndroid Build Coastguard Worker  * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
19*8b26181fSAndroid Build Coastguard Worker  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
20*8b26181fSAndroid Build Coastguard Worker  *
21*8b26181fSAndroid Build Coastguard Worker  * pcap-util.h - common code for various files
22*8b26181fSAndroid Build Coastguard Worker  */
23*8b26181fSAndroid Build Coastguard Worker 
24*8b26181fSAndroid Build Coastguard Worker /*
25*8b26181fSAndroid Build Coastguard Worker  * We use the "receiver-makes-right" approach to byte order;
26*8b26181fSAndroid Build Coastguard Worker  * because time is at a premium when we are writing the file.
27*8b26181fSAndroid Build Coastguard Worker  * In other words, the pcap_file_header and pcap_pkthdr,
28*8b26181fSAndroid Build Coastguard Worker  * records are written in host byte order.
29*8b26181fSAndroid Build Coastguard Worker  * Note that the bytes of packet data are written out in the order in
30*8b26181fSAndroid Build Coastguard Worker  * which they were received, so multi-byte fields in packets are not
31*8b26181fSAndroid Build Coastguard Worker  * written in host byte order, they're written in whatever order the
32*8b26181fSAndroid Build Coastguard Worker  * sending machine put them in.
33*8b26181fSAndroid Build Coastguard Worker  *
34*8b26181fSAndroid Build Coastguard Worker  * We also use this for fixing up packet data headers from a remote
35*8b26181fSAndroid Build Coastguard Worker  * capture, where the server may have a different byte order from the
36*8b26181fSAndroid Build Coastguard Worker  * client.
37*8b26181fSAndroid Build Coastguard Worker  *
38*8b26181fSAndroid Build Coastguard Worker  * ntoh[ls] aren't sufficient because we might need to swap on a big-endian
39*8b26181fSAndroid Build Coastguard Worker  * machine (if the file was written in little-end order).
40*8b26181fSAndroid Build Coastguard Worker  */
41*8b26181fSAndroid Build Coastguard Worker #define	SWAPLONG(y) \
42*8b26181fSAndroid Build Coastguard Worker     (((((u_int)(y))&0xff)<<24) | \
43*8b26181fSAndroid Build Coastguard Worker      ((((u_int)(y))&0xff00)<<8) | \
44*8b26181fSAndroid Build Coastguard Worker      ((((u_int)(y))&0xff0000)>>8) | \
45*8b26181fSAndroid Build Coastguard Worker      ((((u_int)(y))>>24)&0xff))
46*8b26181fSAndroid Build Coastguard Worker #define	SWAPSHORT(y) \
47*8b26181fSAndroid Build Coastguard Worker      ((u_short)(((((u_int)(y))&0xff)<<8) | \
48*8b26181fSAndroid Build Coastguard Worker                 ((((u_int)(y))&0xff00)>>8)))
49*8b26181fSAndroid Build Coastguard Worker 
50*8b26181fSAndroid Build Coastguard Worker extern void pcap_post_process(int linktype, int swapped,
51*8b26181fSAndroid Build Coastguard Worker     struct pcap_pkthdr *hdr, u_char *data);
52*8b26181fSAndroid Build Coastguard Worker 
53*8b26181fSAndroid Build Coastguard Worker extern void fixup_pcap_pkthdr(int linktype, struct pcap_pkthdr *hdr,
54*8b26181fSAndroid Build Coastguard Worker     const u_char *data);
55*8b26181fSAndroid Build Coastguard Worker 
56