extract.h revision 17680
117680Spst/*
217680Spst * Copyright (c) 1992, 1993, 1994, 1995, 1996
317680Spst *	The Regents of the University of California.  All rights reserved.
417680Spst *
517680Spst * Redistribution and use in source and binary forms, with or without
617680Spst * modification, are permitted provided that: (1) source code distributions
717680Spst * retain the above copyright notice and this paragraph in its entirety, (2)
817680Spst * distributions including binary code include the above copyright notice and
917680Spst * this paragraph in its entirety in the documentation or other materials
1017680Spst * provided with the distribution, and (3) all advertising materials mentioning
1117680Spst * features or use of this software display the following acknowledgement:
1217680Spst * ``This product includes software developed by the University of California,
1317680Spst * Lawrence Berkeley Laboratory and its contributors.'' Neither the name of
1417680Spst * the University nor the names of its contributors may be used to endorse
1517680Spst * or promote products derived from this software without specific prior
1617680Spst * written permission.
1717680Spst * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
1817680Spst * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
1917680Spst * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
2017680Spst *
2117680Spst * @(#) $Header: extract.h,v 1.14 96/07/15 18:23:12 leres Exp $ (LBL)
2217680Spst */
2317680Spst
2417680Spst/* Network to host order macros */
2517680Spst
2617680Spst#ifdef LBL_ALIGN
2717680Spst#define EXTRACT_16BITS(p) \
2817680Spst	((u_short)*((u_char *)(p) + 0) << 8 | \
2917680Spst	(u_short)*((u_char *)(p) + 1))
3017680Spst#define EXTRACT_32BITS(p) \
3117680Spst	((u_int32_t)*((u_char *)(p) + 0) << 24 | \
3217680Spst	(u_int32_t)*((u_char *)(p) + 1) << 16 | \
3317680Spst	(u_int32_t)*((u_char *)(p) + 2) << 8 | \
3417680Spst	(u_int32_t)*((u_char *)(p) + 3))
3517680Spst#else
3617680Spst#define EXTRACT_16BITS(p) \
3717680Spst	((u_short)ntohs(*(u_short *)(p)))
3817680Spst#define EXTRACT_32BITS(p) \
3917680Spst	ntohl(*(u_int32_t *)(p))
4017680Spst#endif
4117680Spst
4217680Spst#define EXTRACT_24BITS(p) \
4317680Spst	((u_int32_t)*((u_char *)(p) + 0) << 16 | \
4417680Spst	(u_int32_t)*((u_char *)(p) + 1) << 8 | \
4517680Spst	(u_int32_t)*((u_char *)(p) + 2))
4617680Spst
4717680Spst/* Little endian protocol host order macros */
4817680Spst
4917680Spst#define EXTRACT_LE_8BITS(p) (*(p))
5017680Spst#define EXTRACT_LE_16BITS(p) \
5117680Spst	((u_short)*((u_char *)(p) + 1) << 8 | \
5217680Spst	(u_short)*((u_char *)(p) + 0))
5317680Spst#define EXTRACT_LE_32BITS(p) \
5417680Spst	((u_int32_t)*((u_char *)(p) + 3) << 24 | \
5517680Spst	(u_int32_t)*((u_char *)(p) + 2) << 16 | \
5617680Spst	(u_int32_t)*((u_char *)(p) + 1) << 8 | \
5717680Spst	(u_int32_t)*((u_char *)(p) + 0))
58