extract.h revision 26180
16059Samurai/* 26059Samurai * Copyright (c) 1992, 1993, 1994, 1995, 1996 36059Samurai * The Regents of the University of California. All rights reserved. 46059Samurai * 56059Samurai * Redistribution and use in source and binary forms, with or without 66059Samurai * modification, are permitted provided that: (1) source code distributions 76059Samurai * retain the above copyright notice and this paragraph in its entirety, (2) 86059Samurai * distributions including binary code include the above copyright notice and 96059Samurai * this paragraph in its entirety in the documentation or other materials 106059Samurai * provided with the distribution, and (3) all advertising materials mentioning 116059Samurai * features or use of this software display the following acknowledgement: 126059Samurai * ``This product includes software developed by the University of California, 136059Samurai * Lawrence Berkeley Laboratory and its contributors.'' Neither the name of 146059Samurai * the University nor the names of its contributors may be used to endorse 156059Samurai * or promote products derived from this software without specific prior 166059Samurai * written permission. 176059Samurai * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED 186059Samurai * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF 196059Samurai * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 206059Samurai * 216059Samurai * @(#) $Header: extract.h,v 1.15 96/11/26 22:03:22 leres Exp $ (LBL) 226059Samurai */ 236059Samurai 246059Samurai/* Network to host order macros */ 256059Samurai 266059Samurai#ifdef LBL_ALIGN 276059Samurai#define EXTRACT_16BITS(p) \ 286059Samurai ((u_short)*((u_char *)(p) + 0) << 8 | \ 296059Samurai (u_short)*((u_char *)(p) + 1)) 306059Samurai#define EXTRACT_32BITS(p) \ 316059Samurai ((u_int32_t)*((u_char *)(p) + 0) << 24 | \ 326059Samurai (u_int32_t)*((u_char *)(p) + 1) << 16 | \ 336059Samurai (u_int32_t)*((u_char *)(p) + 2) << 8 | \ 346059Samurai (u_int32_t)*((u_char *)(p) + 3)) 356059Samurai#else 366059Samurai#define EXTRACT_16BITS(p) \ 376059Samurai ((u_short)ntohs(*(u_short *)(p))) 386059Samurai#define EXTRACT_32BITS(p) \ 396059Samurai ((u_int32_t)ntohl(*(u_int32_t *)(p))) 406059Samurai#endif 416059Samurai 426059Samurai#define EXTRACT_24BITS(p) \ 436059Samurai ((u_int32_t)*((u_char *)(p) + 0) << 16 | \ 446059Samurai (u_int32_t)*((u_char *)(p) + 1) << 8 | \ 456059Samurai (u_int32_t)*((u_char *)(p) + 2)) 466059Samurai 476059Samurai/* Little endian protocol host order macros */ 486059Samurai 496059Samurai#define EXTRACT_LE_8BITS(p) (*(p)) 506059Samurai#define EXTRACT_LE_16BITS(p) \ 516059Samurai ((u_short)*((u_char *)(p) + 1) << 8 | \ 526059Samurai (u_short)*((u_char *)(p) + 0)) 536059Samurai#define EXTRACT_LE_32BITS(p) \ 546059Samurai ((u_int32_t)*((u_char *)(p) + 3) << 24 | \ 556059Samurai (u_int32_t)*((u_char *)(p) + 2) << 16 | \ 566059Samurai (u_int32_t)*((u_char *)(p) + 1) << 8 | \ 576059Samurai (u_int32_t)*((u_char *)(p) + 0)) 586059Samurai