Add "class" that understands IPv4 addresses and subnet masks.
[metze/wireshark/wip.git] / proto.h
diff --git a/proto.h b/proto.h
index 59bede3fa80bbb762ef5c0d285eb3283d43f8033..1dc7f5c1e3638ed6abc421ef90194e1b5397097f 100644 (file)
--- a/proto.h
+++ b/proto.h
@@ -1,7 +1,7 @@
 /* proto.h
  * Definitions for protocol display
  *
- * $Id: proto.h,v 1.1 1999/07/07 22:51:59 gram Exp $
+ * $Id: proto.h,v 1.19 1999/11/15 06:32:15 gram Exp $
  *
  * Ethereal - Network traffic analyzer
  * By Gerald Combs <gerald@zing.org>
 #define __PROTO_H__
 
 #ifdef HAVE_SYS_TIME_H
- #ifndef _SYS_TIME_H
-  #include <sys/time.h>
- #endif
+# ifndef _SYS_TIME_H
+#  include <sys/time.h>
+# endif
+#endif
+
+#ifdef HAVE_WINSOCK_H
+# include <winsock.h>
+#endif
+
+#ifndef __IPV4_H__
+#include "ipv4.h"
 #endif
 
 /* needs glib.h */
@@ -44,6 +52,8 @@ struct value_string;
  * need this macro */
 #define VALS(x)        (struct value_string*)(x)
 
+/* ... and similarly, */
+#define TFS(x) (struct true_false_string*)(x)
 
 /* field types */
 enum ftenum {
@@ -51,45 +61,53 @@ enum ftenum {
        FT_BOOLEAN,     /* TRUE and FALSE come from <glib.h> */
        FT_UINT8,
        FT_UINT16,
+       FT_UINT24,      /* really a UINT32, but displayed as 3 hex-digits if FD_HEX*/
        FT_UINT32,
+       FT_INT8,
+       FT_INT16,
+       FT_INT24,
+       FT_INT32,
+       FT_DOUBLE,
        FT_ABSOLUTE_TIME,
        FT_RELATIVE_TIME,
        FT_STRING,
        FT_ETHER,
-       FT_ETHER_VENDOR,
        FT_BYTES,
        FT_IPv4,
        FT_IPv6,
-       FT_IPXSERVER,
-       FT_VALS_UINT8,
-       FT_VALS_UINT16,
-       FT_VALS_UINT24,
-       FT_VALS_UINT32,
+       FT_IPXNET,
        FT_TEXT_ONLY,   /* non-filterable, used when converting ethereal
                                from old-style proto_tree to new-style proto_tree */
        NUM_FIELD_TYPES /* last item number plus one */
 };
 
+enum {
+       BASE_NONE,
+       BASE_DEC,
+       BASE_HEX,
+       BASE_OCT,
+       BASE_BIN
+};
 
+/* information describing a header field */
 typedef struct header_field_info {
        char                            *name;
        char                            *abbrev;
        enum ftenum                     type;
-       int                             parent;
-       struct value_string             *vals;
-       int                             id; /* assigned by order of registration */
-/*     int                             color;  for use by GUI code */
+       int                             display;        /* for integers only, so far. Base and Endianness */
+       void                            *strings;       /* val_string or true_false_string */
+       guint32                         bitmask;
+       char                            *blurb;         /* Brief description of field. */
+
+       int                             id;             /* assigned by registration function, not programmer */
+       int                             parent;         /* parent protocol */
+       int                             bitshift;       /* bits to shift */
 } header_field_info;
 
-/*extern struct header_field_info hfinfo[];*/
-
 /* Used when registering many fields at once */
 typedef struct hf_register_info {
-       char                    *name;
-       char                    *abbrev;
        int                     *p_id;  /* pointer to int; written to by register() function */
-       enum ftenum             type;
-       struct value_string     *vals;
+       header_field_info       hfinfo;
 } hf_register_info;
 
 
@@ -102,25 +120,47 @@ typedef struct field_info {
        char                            *representation; /* for GUI tree */
        int                             visible;
        union {
-               gboolean        boolean;
                guint32         numeric;
-               struct timeval  abs_time; /* the whole struct, not a pointer */
+               struct timeval  time; /* the whole struct, not a pointer */
+               gdouble         floating;
                gchar           *string;
+               guint8          *bytes;
                guint8          ether[6];
+               ipv4_addr       ipv4;
+               guint8          ipv6[16];
        }                               value;
 } field_info;
 
 
+/* used when calling proto search functions */
 typedef struct proto_tree_search_info {
-       int     target_field;
-       GArray  *result_array;
-       guint8  *packet_data;
+       int                     target;
+       int                     parent;
+       const guint8            *packet_data;
+       guint                   packet_len;
+       GNodeTraverseFunc       traverse_func;
+       union {
+               GArray                  *array;
+               GNode                   *node;
+       }                       result;
 } proto_tree_search_info;
 
+/* Sets up memory used by proto routines. Called at program startup */
 void proto_init(void);
+
+/* Frees memory used by proto routines. Called at program shutdown */
+void proto_cleanup(void);
+
+/* Set length of proto_item after having already been created. */
 void proto_item_set_len(proto_item *ti, gint length);
+
+/* Creates new proto_tree root */
 proto_tree* proto_tree_create_root(void);
+
+/* Clear memory for entry proto_tree. Clears proto_tree struct also. */
 void proto_tree_free(proto_tree *tree);
+
+/* Create a subtree under an existing item; returns tree pointer */
 proto_tree* proto_item_add_subtree(proto_item *ti, gint idx);
 
 int
@@ -131,7 +171,7 @@ int
 proto_register_protocol(char *name, char *abbrev);
 
 void
-proto_register_field_array(int parent, const hf_register_info *hf, int num_records);
+proto_register_field_array(int parent, hf_register_info *hf, int num_records);
 
 proto_item *
 proto_tree_add_item(proto_tree *tree, int hfindex, gint start,
@@ -151,15 +191,51 @@ proto_tree_add_text(proto_tree *tree, gint start, gint length, ...);
 void
 proto_item_fill_label(field_info *fi, gchar *label_str);
 
-/* useful functions for external routines to get info about registered protos and fields */
+/* Returns number of items (protocols or header fields) registered. */
 int proto_registrar_n(void);
+
+/* Returns char* to name for item # n (0-indexed) */
+char* proto_registrar_get_name(int n);
+
+/* Returns char* to abbrev for item # n (0-indexed) */
 char* proto_registrar_get_abbrev(int n);
+
+/* Returns enum ftenum for item # n */
 int proto_registrar_get_ftype(int n);
+
+/* Returns parent protocol for item # n.
+ * Returns -1 if item _is_ a protocol */
 int proto_registrar_get_parent(int n);
+
+/* Is item #n a protocol? */
 gboolean proto_registrar_is_protocol(int n);
-proto_item* proto_find_field(proto_tree* tree, int id);
-proto_item* proto_find_protocol(proto_tree* tree, int protocol_id);
-void proto_get_field_values(proto_tree* subtree, GNodeTraverseFunc fill_array_func,
-       proto_tree_search_info *sinfo);
+
+/* Get length of registered field according to field type.
+ * 0 means undeterminable at registration time.
+ * -1 means unknown field */
+gint proto_registrar_get_length(int n);
+
+/* Checks for existence any protocol or field within a tree.
+ * TRUE = found, FALSE = not found */
+gboolean proto_check_for_protocol_or_field(proto_tree* tree, int id);
+
+/* Search for a protocol subtree, which can occur more than once, and for each successful
+ * find, call the calback function, passing sinfo as the second argument */
+void proto_find_protocol_multi(proto_tree* tree, int target, GNodeTraverseFunc callback,
+                       proto_tree_search_info *sinfo);
+
+/* Just a wrapper to call sinfo->traverse_func() for all nodes in the subtree, with the GNode
+ * and sinfo as the two arguments to sinfo->traverse_func(). Useful when you have to process
+ * all nodes in a subtree. */
+gboolean proto_get_field_values(proto_tree* subtree, proto_tree_search_info *sinfo);
+
+/* Dumps a glossary of the protocol and field registrations to STDOUT */
+void proto_registrar_dump(void);
+
+/* Is the parsing being done for a visible proto_tree or an invisible one?
+ * By setting this correctly, the proto_tree creation is sped up by not
+ * having to call vsnprintf and copy strings around.
+ */
+extern gboolean proto_tree_is_visible;
 
 #endif /* proto.h */