aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGuy Harris <guy@alum.mit.edu>2000-08-10 07:58:44 +0000
committerGuy Harris <guy@alum.mit.edu>2000-08-10 07:58:44 +0000
commiteeb4ab5276a4b947178e9def1206eac5fc683217 (patch)
treedb6c2b4b66f19eda8635bb9aee8276b4719dffe4
parent95c935f21617f3bcacc6495fe3492038e949b488 (diff)
If G_HAVE_GINT64 is defined, so that we can use "gint64" and "guint64"
to refer to 64-bit integral quantities, add "pntohll()" and "phtonll()" macros, and "tvb_get_ntohll()" and "tvb_get_letohll()" routines, for fetching 64-bit integral quantities. (They're still a pain to *print*, as there's no standard "printf" format code for them - some systems use "%ll[dox]", some use "%q[dox]", and I think some use formats different from all of them.) svn path=/trunk/; revision=2243
-rw-r--r--packet.h61
-rw-r--r--tvbuff.c106
-rw-r--r--tvbuff.h12
3 files changed, 130 insertions, 49 deletions
diff --git a/packet.h b/packet.h
index 84f358c9f5..a8e0a51c78 100644
--- a/packet.h
+++ b/packet.h
@@ -1,7 +1,7 @@
/* packet.h
* Definitions for packet disassembly structures and routines
*
- * $Id: packet.h,v 1.191 2000/08/07 03:21:25 guy Exp $
+ * $Id: packet.h,v 1.192 2000/08/10 07:58:43 guy Exp $
*
* Ethereal - Network traffic analyzer
* By Gerald Combs <gerald@zing.org>
@@ -43,26 +43,51 @@
/* Pointer versions of ntohs and ntohl. Given a pointer to a member of a
* byte array, returns the value of the two or four bytes at the pointer.
* The pletoh[sl] versions return the little-endian representation.
+ *
+ * If G_HAVE_GINT64 is defined, so we can use "gint64" and "guint64" to
+ * refer to 64-bit integral quantities, we also provide pntohll and
+ * phtolell, which extract 64-bit integral quantities.
*/
-#define pntohs(p) ((guint16) \
- ((guint16)*((guint8 *)p+0)<<8| \
- (guint16)*((guint8 *)p+1)<<0))
-
-#define pntohl(p) ((guint32)*((guint8 *)p+0)<<24| \
- (guint32)*((guint8 *)p+1)<<16| \
- (guint32)*((guint8 *)p+2)<<8| \
- (guint32)*((guint8 *)p+3)<<0)
-
-#define pletohs(p) ((guint16) \
- ((guint16)*((guint8 *)p+1)<<8| \
- (guint16)*((guint8 *)p+0)<<0))
-
-#define pletohl(p) ((guint32)*((guint8 *)p+3)<<24| \
- (guint32)*((guint8 *)p+2)<<16| \
- (guint32)*((guint8 *)p+1)<<8| \
- (guint32)*((guint8 *)p+0)<<0)
+#define pntohs(p) ((guint16) \
+ ((guint16)*((guint8 *)p+0)<<8| \
+ (guint16)*((guint8 *)p+1)<<0))
+
+#define pntohl(p) ((guint32)*((guint8 *)p+0)<<24| \
+ (guint32)*((guint8 *)p+1)<<16| \
+ (guint32)*((guint8 *)p+2)<<8| \
+ (guint32)*((guint8 *)p+3)<<0)
+
+#ifdef G_HAVE_GINT64
+#define pntohll(p) ((guint64)*((guint8 *)p+0)<<56| \
+ (guint64)*((guint8 *)p+1)<<48| \
+ (guint64)*((guint8 *)p+2)<<40| \
+ (guint64)*((guint8 *)p+3)<<32| \
+ (guint64)*((guint8 *)p+4)<<24| \
+ (guint64)*((guint8 *)p+5)<<16| \
+ (guint64)*((guint8 *)p+6)<<8| \
+ (guint64)*((guint8 *)p+7)<<0)
+#endif
+#define pletohs(p) ((guint16) \
+ ((guint16)*((guint8 *)p+1)<<8| \
+ (guint16)*((guint8 *)p+0)<<0))
+
+#define pletohl(p) ((guint32)*((guint8 *)p+3)<<24| \
+ (guint32)*((guint8 *)p+2)<<16| \
+ (guint32)*((guint8 *)p+1)<<8| \
+ (guint32)*((guint8 *)p+0)<<0)
+
+#ifdef G_HAVE_GINT64
+#define pletohll(p) ((guint64)*((guint8 *)p+7)<<56| \
+ (guint64)*((guint8 *)p+6)<<48| \
+ (guint64)*((guint8 *)p+5)<<40| \
+ (guint64)*((guint8 *)p+4)<<32| \
+ (guint64)*((guint8 *)p+3)<<24| \
+ (guint64)*((guint8 *)p+2)<<16| \
+ (guint64)*((guint8 *)p+1)<<8| \
+ (guint64)*((guint8 *)p+0)<<0)
+#endif
#define hi_nibble(b) ((b & 0xf0) >> 4)
#define lo_nibble(b) (b & 0x0f)
diff --git a/tvbuff.c b/tvbuff.c
index b1329e5828..c12cfe9cb7 100644
--- a/tvbuff.c
+++ b/tvbuff.c
@@ -9,7 +9,7 @@
* the data of a backing tvbuff, or can be a composite of
* other tvbuffs.
*
- * $Id: tvbuff.c,v 1.5 2000/06/09 21:15:46 gram Exp $
+ * $Id: tvbuff.c,v 1.6 2000/08/10 07:58:44 guy Exp $
*
* Copyright (c) 2000 by Gilbert Ramirez <gram@xiexie.org>
*
@@ -42,34 +42,62 @@
/* Pointer versions of ntohs and ntohl. Given a pointer to a member of a
* byte array, returns the value of the two or four bytes at the pointer.
* The pletoh[sl] versions return the little-endian representation.
+ *
+ * We also provide "pntoh24()" and "pletoh24()", to extract 24-bit
+ * quantities.
+ *
+ * If G_HAVE_GINT64 is defined, so we can use "gint64" and "guint64" to
+ * refer to 64-bit integral quantities, we also provide pntohll and
+ * phtolell, which extract 64-bit integral quantities.
*/
-#define pntohs(p) ((guint16) \
- ((guint16)*((guint8 *)p+0)<<8| \
- (guint16)*((guint8 *)p+1)<<0))
-
-#define pntohl(p) ((guint32)*((guint8 *)p+0)<<24| \
- (guint32)*((guint8 *)p+1)<<16| \
- (guint32)*((guint8 *)p+2)<<8| \
- (guint32)*((guint8 *)p+3)<<0)
+#define pntohs(p) ((guint16) \
+ ((guint16)*((guint8 *)p+0)<<8| \
+ (guint16)*((guint8 *)p+1)<<0))
-#define pntoh24(p) ((guint32)*((guint8 *)p+0)<<16| \
- (guint32)*((guint8 *)p+1)<<8| \
- (guint32)*((guint8 *)p+2)<<0)
-
-#define pletohs(p) ((guint16) \
- ((guint16)*((guint8 *)p+1)<<8| \
- (guint16)*((guint8 *)p+0)<<0))
+#define pntoh24(p) ((guint32)*((guint8 *)p+0)<<16| \
+ (guint32)*((guint8 *)p+1)<<8| \
+ (guint32)*((guint8 *)p+2)<<0)
+
+#define pntohl(p) ((guint32)*((guint8 *)p+0)<<24| \
+ (guint32)*((guint8 *)p+1)<<16| \
+ (guint32)*((guint8 *)p+2)<<8| \
+ (guint32)*((guint8 *)p+3)<<0)
+
+#ifdef G_HAVE_GINT64
+#define pntohll(p) ((guint64)*((guint8 *)p+0)<<56| \
+ (guint64)*((guint8 *)p+1)<<48| \
+ (guint64)*((guint8 *)p+2)<<40| \
+ (guint64)*((guint8 *)p+3)<<32| \
+ (guint64)*((guint8 *)p+4)<<24| \
+ (guint64)*((guint8 *)p+5)<<16| \
+ (guint64)*((guint8 *)p+6)<<8| \
+ (guint64)*((guint8 *)p+7)<<0)
+#endif
-#define pletohl(p) ((guint32)*((guint8 *)p+3)<<24| \
- (guint32)*((guint8 *)p+2)<<16| \
- (guint32)*((guint8 *)p+1)<<8| \
- (guint32)*((guint8 *)p+0)<<0)
+#define pletohs(p) ((guint16) \
+ ((guint16)*((guint8 *)p+1)<<8| \
+ (guint16)*((guint8 *)p+0)<<0))
#define pletoh24(p) ((guint32)*((guint8 *)p+2)<<16| \
(guint32)*((guint8 *)p+1)<<8| \
(guint32)*((guint8 *)p+0)<<0)
+#define pletohl(p) ((guint32)*((guint8 *)p+3)<<24| \
+ (guint32)*((guint8 *)p+2)<<16| \
+ (guint32)*((guint8 *)p+1)<<8| \
+ (guint32)*((guint8 *)p+0)<<0)
+
+#ifdef G_HAVE_GINT64
+#define pletohll(p) ((guint64)*((guint8 *)p+7)<<56| \
+ (guint64)*((guint8 *)p+6)<<48| \
+ (guint64)*((guint8 *)p+5)<<40| \
+ (guint64)*((guint8 *)p+4)<<32| \
+ (guint64)*((guint8 *)p+3)<<24| \
+ (guint64)*((guint8 *)p+2)<<16| \
+ (guint64)*((guint8 *)p+1)<<8| \
+ (guint64)*((guint8 *)p+0)<<0)
+#endif
typedef struct {
/* The backing tvbuff_t */
@@ -875,6 +903,15 @@ tvb_get_ntohs(tvbuff_t *tvb, gint offset)
}
guint32
+tvb_get_ntoh24(tvbuff_t *tvb, gint offset)
+{
+ guint8* ptr;
+
+ ptr = ensure_contiguous(tvb, offset, 3);
+ return pntoh24(ptr);
+}
+
+guint32
tvb_get_ntohl(tvbuff_t *tvb, gint offset)
{
guint8* ptr;
@@ -883,14 +920,16 @@ tvb_get_ntohl(tvbuff_t *tvb, gint offset)
return pntohl(ptr);
}
-guint32
-tvb_get_ntoh24(tvbuff_t *tvb, gint offset)
+#ifdef G_HAVE_GINT64
+guint64
+tvb_get_ntohll(tvbuff_t *tvb, gint offset)
{
guint8* ptr;
- ptr = ensure_contiguous(tvb, offset, 3);
- return pntoh24(ptr);
+ ptr = ensure_contiguous(tvb, offset, sizeof(guint64));
+ return pntohll(ptr);
}
+#endif
guint16
tvb_get_letohs(tvbuff_t *tvb, gint offset)
@@ -902,6 +941,15 @@ tvb_get_letohs(tvbuff_t *tvb, gint offset)
}
guint32
+tvb_get_letoh24(tvbuff_t *tvb, gint offset)
+{
+ guint8* ptr;
+
+ ptr = ensure_contiguous(tvb, offset, 3);
+ return pletoh24(ptr);
+}
+
+guint32
tvb_get_letohl(tvbuff_t *tvb, gint offset)
{
guint8* ptr;
@@ -910,11 +958,13 @@ tvb_get_letohl(tvbuff_t *tvb, gint offset)
return pletohl(ptr);
}
-guint32
-tvb_get_letoh24(tvbuff_t *tvb, gint offset)
+#ifdef G_HAVE_GINT64
+guint64
+tvb_get_letohll(tvbuff_t *tvb, gint offset)
{
guint8* ptr;
- ptr = ensure_contiguous(tvb, offset, 3);
- return pletoh24(ptr);
+ ptr = ensure_contiguous(tvb, offset, sizeof(guint64));
+ return pletohll(ptr);
}
+#endif
diff --git a/tvbuff.h b/tvbuff.h
index 8cbf9e6272..f0b94fe46b 100644
--- a/tvbuff.h
+++ b/tvbuff.h
@@ -9,7 +9,7 @@
* the data of a backing tvbuff, or can be a composite of
* other tvbuffs.
*
- * $Id: tvbuff.h,v 1.5 2000/06/15 03:48:45 gram Exp $
+ * $Id: tvbuff.h,v 1.6 2000/08/10 07:58:44 guy Exp $
*
* Copyright (c) 2000 by Gilbert Ramirez <gram@xiexie.org>
*
@@ -192,12 +192,18 @@ gint tvb_raw_offset(tvbuff_t*);
guint8 tvb_get_guint8(tvbuff_t*, gint offset);
guint16 tvb_get_ntohs(tvbuff_t*, gint offset);
-guint32 tvb_get_ntohl(tvbuff_t*, gint offset);
guint32 tvb_get_ntoh24(tvbuff_t*, gint offset);
+guint32 tvb_get_ntohl(tvbuff_t*, gint offset);
+#ifdef G_HAVE_GINT64
+guint64 tvb_get_ntohll(tvbuff_t*, gint offset);
+#endif
guint16 tvb_get_letohs(tvbuff_t*, gint offset);
-guint32 tvb_get_letohl(tvbuff_t*, gint offset);
guint32 tvb_get_letoh24(tvbuff_t*, gint offset);
+guint32 tvb_get_letohl(tvbuff_t*, gint offset);
+#ifdef G_HAVE_GINT64
+guint64 tvb_get_letohll(tvbuff_t*, gint offset);
+#endif
/* Returns target for convenience. Does not suffer from possible
* expense of tvb_get_ptr(), since this routine is smart enough