1*e4c9ae7dSotto /* $OpenBSD: extract.h,v 1.8 2004/02/02 09:43:27 otto Exp $ */ 2cf4e9b47Sho 3df930be7Sderaadt /* 4c15d59edSmickey * Copyright (c) 1992, 1993, 1994, 1995, 1996 5df930be7Sderaadt * The Regents of the University of California. All rights reserved. 6df930be7Sderaadt * 7df930be7Sderaadt * Redistribution and use in source and binary forms, with or without 8df930be7Sderaadt * modification, are permitted provided that: (1) source code distributions 9df930be7Sderaadt * retain the above copyright notice and this paragraph in its entirety, (2) 10df930be7Sderaadt * distributions including binary code include the above copyright notice and 11df930be7Sderaadt * this paragraph in its entirety in the documentation or other materials 12df930be7Sderaadt * provided with the distribution, and (3) all advertising materials mentioning 13df930be7Sderaadt * features or use of this software display the following acknowledgement: 14df930be7Sderaadt * ``This product includes software developed by the University of California, 15df930be7Sderaadt * Lawrence Berkeley Laboratory and its contributors.'' Neither the name of 16df930be7Sderaadt * the University nor the names of its contributors may be used to endorse 17df930be7Sderaadt * or promote products derived from this software without specific prior 18df930be7Sderaadt * written permission. 19df930be7Sderaadt * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED 20df930be7Sderaadt * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF 21df930be7Sderaadt * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 22df930be7Sderaadt * 238b959691Sho * @(#) $TCPDUMP: /tcpdump/master/tcpdump/extract.h,v 1.17 2001/09/17 21:57:52 fenner Exp $ (LBL) 24df930be7Sderaadt */ 25df930be7Sderaadt 26dc709136Sbitblt /* Network to host order macros */ 27dc709136Sbitblt 28dc709136Sbitblt #define EXTRACT_16BITS(p) \ 298b959691Sho ((u_int16_t)*((const u_int8_t *)(p) + 0) << 8 | \ 308b959691Sho (u_int16_t)*((const u_int8_t *)(p) + 1)) 31*e4c9ae7dSotto 32dc709136Sbitblt #define EXTRACT_32BITS(p) \ 338b959691Sho ((u_int32_t)*((const u_int8_t *)(p) + 0) << 24 | \ 348b959691Sho (u_int32_t)*((const u_int8_t *)(p) + 1) << 16 | \ 358b959691Sho (u_int32_t)*((const u_int8_t *)(p) + 2) << 8 | \ 368b959691Sho (u_int32_t)*((const u_int8_t *)(p) + 3)) 37dc709136Sbitblt 38dc709136Sbitblt #define EXTRACT_24BITS(p) \ 398b959691Sho ((u_int32_t)*((const u_int8_t *)(p) + 0) << 16 | \ 408b959691Sho (u_int32_t)*((const u_int8_t *)(p) + 1) << 8 | \ 418b959691Sho (u_int32_t)*((const u_int8_t *)(p) + 2)) 42dc709136Sbitblt 43dc709136Sbitblt /* Little endian protocol host order macros */ 44dc709136Sbitblt 45dc709136Sbitblt #define EXTRACT_LE_8BITS(p) (*(p)) 46dc709136Sbitblt #define EXTRACT_LE_16BITS(p) \ 478b959691Sho ((u_int16_t)*((const u_int8_t *)(p) + 1) << 8 | \ 488b959691Sho (u_int16_t)*((const u_int8_t *)(p) + 0)) 49dc709136Sbitblt #define EXTRACT_LE_32BITS(p) \ 508b959691Sho ((u_int32_t)*((const u_int8_t *)(p) + 3) << 24 | \ 518b959691Sho (u_int32_t)*((const u_int8_t *)(p) + 2) << 16 | \ 528b959691Sho (u_int32_t)*((const u_int8_t *)(p) + 1) << 8 | \ 538b959691Sho (u_int32_t)*((const u_int8_t *)(p) + 0)) 54