16f9cba8fSJoseph Mingrone /* 26f9cba8fSJoseph Mingrone * Copyright (c) 1993, 1994, 1995, 1996, 1997 36f9cba8fSJoseph Mingrone * The Regents of the University of California. All rights reserved. 46f9cba8fSJoseph Mingrone * 56f9cba8fSJoseph Mingrone * Redistribution and use in source and binary forms, with or without 66f9cba8fSJoseph Mingrone * modification, are permitted provided that: (1) source code distributions 76f9cba8fSJoseph Mingrone * retain the above copyright notice and this paragraph in its entirety, (2) 86f9cba8fSJoseph Mingrone * distributions including binary code include the above copyright notice and 96f9cba8fSJoseph Mingrone * this paragraph in its entirety in the documentation or other materials 106f9cba8fSJoseph Mingrone * provided with the distribution, and (3) all advertising materials mentioning 116f9cba8fSJoseph Mingrone * features or use of this software display the following acknowledgement: 126f9cba8fSJoseph Mingrone * ``This product includes software developed by the University of California, 136f9cba8fSJoseph Mingrone * Lawrence Berkeley Laboratory and its contributors.'' Neither the name of 146f9cba8fSJoseph Mingrone * the University nor the names of its contributors may be used to endorse 156f9cba8fSJoseph Mingrone * or promote products derived from this software without specific prior 166f9cba8fSJoseph Mingrone * written permission. 176f9cba8fSJoseph Mingrone * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED 186f9cba8fSJoseph Mingrone * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF 196f9cba8fSJoseph Mingrone * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 206f9cba8fSJoseph Mingrone * 216f9cba8fSJoseph Mingrone * pcap-util.h - common code for various files 226f9cba8fSJoseph Mingrone */ 236f9cba8fSJoseph Mingrone 246f9cba8fSJoseph Mingrone /* 256f9cba8fSJoseph Mingrone * We use the "receiver-makes-right" approach to byte order; 266f9cba8fSJoseph Mingrone * because time is at a premium when we are writing the file. 276f9cba8fSJoseph Mingrone * In other words, the pcap_file_header and pcap_pkthdr, 286f9cba8fSJoseph Mingrone * records are written in host byte order. 296f9cba8fSJoseph Mingrone * Note that the bytes of packet data are written out in the order in 306f9cba8fSJoseph Mingrone * which they were received, so multi-byte fields in packets are not 316f9cba8fSJoseph Mingrone * written in host byte order, they're written in whatever order the 326f9cba8fSJoseph Mingrone * sending machine put them in. 336f9cba8fSJoseph Mingrone * 346f9cba8fSJoseph Mingrone * We also use this for fixing up packet data headers from a remote 356f9cba8fSJoseph Mingrone * capture, where the server may have a different byte order from the 366f9cba8fSJoseph Mingrone * client. 376f9cba8fSJoseph Mingrone * 386f9cba8fSJoseph Mingrone * ntoh[ls] aren't sufficient because we might need to swap on a big-endian 396f9cba8fSJoseph Mingrone * machine (if the file was written in little-end order). 406f9cba8fSJoseph Mingrone */ 416f9cba8fSJoseph Mingrone #define SWAPLONG(y) \ 426f9cba8fSJoseph Mingrone (((((u_int)(y))&0xff)<<24) | \ 436f9cba8fSJoseph Mingrone ((((u_int)(y))&0xff00)<<8) | \ 446f9cba8fSJoseph Mingrone ((((u_int)(y))&0xff0000)>>8) | \ 456f9cba8fSJoseph Mingrone ((((u_int)(y))>>24)&0xff)) 466f9cba8fSJoseph Mingrone #define SWAPSHORT(y) \ 476f9cba8fSJoseph Mingrone ((u_short)(((((u_int)(y))&0xff)<<8) | \ 486f9cba8fSJoseph Mingrone ((((u_int)(y))&0xff00)>>8))) 496f9cba8fSJoseph Mingrone 50*afdbf109SJoseph Mingrone extern void pcapint_post_process(int linktype, int swapped, 516f9cba8fSJoseph Mingrone struct pcap_pkthdr *hdr, u_char *data); 52