diff options
Diffstat (limited to 'usr.sbin/tcpdump/extract.h')
-rw-r--r-- | usr.sbin/tcpdump/extract.h | 46 |
1 files changed, 32 insertions, 14 deletions
diff --git a/usr.sbin/tcpdump/extract.h b/usr.sbin/tcpdump/extract.h index 9561f022669..18a3a49e3cc 100644 --- a/usr.sbin/tcpdump/extract.h +++ b/usr.sbin/tcpdump/extract.h @@ -1,5 +1,3 @@ -/* $OpenBSD: extract.h,v 1.4 1996/07/13 11:01:09 mickey Exp $ */ - /* * Copyright (c) 1992, 1993, 1994, 1995, 1996 * The Regents of the University of California. All rights reserved. @@ -20,20 +18,40 @@ * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. * - * @(#) Header: extract.h,v 1.12 96/06/20 18:48:42 leres Exp (LBL) + * @(#) $Header: /cvs/OpenBSD/src/usr.sbin/tcpdump/extract.h,v 1.5 1996/12/12 16:22:55 bitblt Exp $ (LBL) */ +/* Network to host order macros */ + #ifdef LBL_ALIGN -#define EXTRACT_SHORT(p)\ - ((u_short)\ - ((u_short)*((u_char *)(p)+0)<<8|\ - (u_short)*((u_char *)(p)+1)<<0)) -#define EXTRACT_LONG(p)\ - ((u_int32_t)*((u_char *)(p)+0)<<24|\ - (u_int32_t)*((u_char *)(p)+1)<<16|\ - (u_int32_t)*((u_char *)(p)+2)<<8|\ - (u_int32_t)*((u_char *)(p)+3)<<0) +#define EXTRACT_16BITS(p) \ + ((u_short)*((u_char *)(p) + 0) << 8 | \ + (u_short)*((u_char *)(p) + 1)) +#define EXTRACT_32BITS(p) \ + ((u_int32_t)*((u_char *)(p) + 0) << 24 | \ + (u_int32_t)*((u_char *)(p) + 1) << 16 | \ + (u_int32_t)*((u_char *)(p) + 2) << 8 | \ + (u_int32_t)*((u_char *)(p) + 3)) #else -#define EXTRACT_SHORT(p) ((u_short)ntohs(*(u_short *)(p))) -#define EXTRACT_LONG(p) (ntohl(*(u_int32_t *)(p))) +#define EXTRACT_16BITS(p) \ + ((u_short)ntohs(*(u_short *)(p))) +#define EXTRACT_32BITS(p) \ + ((u_int32_t)ntohl(*(u_int32_t *)(p))) #endif + +#define EXTRACT_24BITS(p) \ + ((u_int32_t)*((u_char *)(p) + 0) << 16 | \ + (u_int32_t)*((u_char *)(p) + 1) << 8 | \ + (u_int32_t)*((u_char *)(p) + 2)) + +/* Little endian protocol host order macros */ + +#define EXTRACT_LE_8BITS(p) (*(p)) +#define EXTRACT_LE_16BITS(p) \ + ((u_short)*((u_char *)(p) + 1) << 8 | \ + (u_short)*((u_char *)(p) + 0)) +#define EXTRACT_LE_32BITS(p) \ + ((u_int32_t)*((u_char *)(p) + 3) << 24 | \ + (u_int32_t)*((u_char *)(p) + 2) << 16 | \ + (u_int32_t)*((u_char *)(p) + 1) << 8 | \ + (u_int32_t)*((u_char *)(p) + 0)) |