Move the routine to get a list of the network interfaces on the system
[obnox/wireshark/wip.git] / packet-http.c
index b904329978f12db5776833ce82d0b9c21f6ea58a..df23cd9b6d31e3fe59099f4120ad0fef712b7d2a 100644 (file)
@@ -3,7 +3,7 @@
  *
  * Guy Harris <guy@netapp.com>
  *
- * $Id: packet-http.c,v 1.5 1999/07/13 02:52:51 gram Exp $
+ * $Id: packet-http.c,v 1.12 1999/12/06 20:27:19 guy Exp $
  *
  * Ethereal - Network traffic analyzer
  * By Gerald Combs <gerald@zing.org>
 #include <glib.h>
 #include "packet.h"
 
+static int proto_http = -1;
+static int hf_http_response = -1;
+static int hf_http_request = -1;
+
+static gint ett_http = -1;
+
+static proto_tree *http_tree;
+
 static int is_http_request_or_reply(const u_char *data, int linelen);
 
 void dissect_http(const u_char *pd, int offset, frame_data *fd, proto_tree *tree)
 {
-       proto_tree      *http_tree;
+       gboolean        is_ipp = (pi.srcport == 631 || pi.destport == 631);
        proto_item      *ti;
        const u_char    *data, *dataend;
        const u_char    *linep, *lineend, *eol;
@@ -56,7 +64,7 @@ void dissect_http(const u_char *pd, int offset, frame_data *fd, proto_tree *tree
        dataend = data + END_OF_FRAME;
 
        if (check_col(fd, COL_PROTOCOL))
-               col_add_str(fd, COL_PROTOCOL, "HTTP");
+               col_add_str(fd, COL_PROTOCOL, is_ipp ? "IPP" : "HTTP");
        if (check_col(fd, COL_INFO)) {
                /*
                 * Put the first line from the buffer into the summary,
@@ -72,9 +80,8 @@ void dissect_http(const u_char *pd, int offset, frame_data *fd, proto_tree *tree
        }
 
        if (tree) {
-               ti = proto_tree_add_text(tree, offset, END_OF_FRAME,
-                 "Hypertext Transfer Protocol");
-               http_tree = proto_item_add_subtree(ti, ETT_HTTP);
+               ti = proto_tree_add_item(tree, proto_http, offset, END_OF_FRAME, NULL);
+               http_tree = proto_item_add_subtree(ti, ett_http);
 
                while (data < dataend) {
                        /*
@@ -168,8 +175,10 @@ void dissect_http(const u_char *pd, int offset, frame_data *fd, proto_tree *tree
                }
 
                if (data < dataend) {
-                       proto_tree_add_text(http_tree, offset, END_OF_FRAME,
-                           "Data (%d bytes)", END_OF_FRAME);
+                       if (is_ipp)
+                               dissect_ipp(pd, offset, fd, tree);
+                       else
+                               dissect_data(&pd[offset], offset, fd, http_tree);
                }
        }
 }
@@ -183,27 +192,72 @@ is_http_request_or_reply(const u_char *data, int linelen)
 {
        if (linelen >= 3) {
                if (strncasecmp(data, "GET", 3) == 0 ||
-                   strncasecmp(data, "PUT", 3) == 0)
+                   strncasecmp(data, "PUT", 3) == 0) {
+                       proto_tree_add_item_hidden(http_tree, 
+                                                  hf_http_request, 0, 0, 1);
                        return TRUE;
+               }
        }
        if (linelen >= 4) {
                if (strncasecmp(data, "HEAD", 4) == 0 ||
-                   strncasecmp(data, "POST", 4) == 0)
+                   strncasecmp(data, "POST", 4) == 0) {
+                       proto_tree_add_item_hidden(http_tree, 
+                                                  hf_http_request, 0, 0, 1);
                        return TRUE;
+               }
        }
        if (linelen >= 5) {
                if (strncasecmp(data, "TRACE", 5) == 0)
                        return TRUE;
-               if (strncasecmp(data, "HTTP/", 5) == 0)
+               if (strncasecmp(data, "HTTP/", 5) == 0) {
+                       proto_tree_add_item_hidden(http_tree, 
+                                                  hf_http_response, 0, 0, 1);
                        return TRUE;    /* response */
+               }
        }
        if (linelen >= 6) {
-               if (strncasecmp(data, "DELETE", 6) == 0)
+               if (strncasecmp(data, "DELETE", 6) == 0) {
+                       proto_tree_add_item_hidden(http_tree, 
+                                                  hf_http_request, 0, 0, 1);
                        return TRUE;
+               }
        }
        if (linelen >= 7) {
-               if (strncasecmp(data, "OPTIONS", 7) == 0)
+               if (strncasecmp(data, "OPTIONS", 7) == 0) {
+                       proto_tree_add_item_hidden(http_tree, 
+                                                  hf_http_request, 0, 0, 1);
                        return TRUE;
+               }
+       }
+       if (linelen >= 7) {
+               if (strncasecmp(data, "CONNECT", 7) == 0) {
+                       proto_tree_add_item_hidden(http_tree, 
+                                                  hf_http_request, 0, 0, 1);
+                       return TRUE;
+               }
        }
        return FALSE;
 }
+
+void
+proto_register_http(void)
+{
+
+  static hf_register_info hf[] = {
+    { &hf_http_response,
+      { "Response",            "http.response",  
+       FT_BOOLEAN, BASE_NONE, NULL, 0x0,
+       "TRUE if HTTP response" }},
+    { &hf_http_request,
+      { "Request",             "http.request",
+       FT_BOOLEAN, BASE_NONE, NULL, 0x0,
+       "TRUE if HTTP request (GET, PUT, HEAD, POST)" }},
+  };
+  static gint *ett[] = {
+    &ett_http,
+  };
+
+  proto_http = proto_register_protocol("Hypertext Transfer Protocol", "http");
+  proto_register_field_array(proto_http, hf, array_length(hf));
+  proto_register_subtree_array(ett, array_length(ett));
+}