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