2 * Routines for PostgreSQL v3 protocol dissection.
3 * <http://www.postgresql.org/docs/current/static/protocol.html>
4 * Copyright 2004 Abhijit Menon-Sen <ams@oryx.com>
8 * Wireshark - Network traffic analyzer
9 * By Gerald Combs <gerald@wireshark.org>
10 * Copyright 1998 Gerald Combs
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, write to the Free Software
24 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
30 #include <epan/packet.h>
31 #include <epan/conversation.h>
32 #include <epan/prefs.h>
34 #include "packet-tcp.h"
37 static int proto_pgsql
= -1;
38 static int hf_frontend
= -1;
39 static int hf_type
= -1;
40 static int hf_length
= -1;
41 static int hf_parameter_name
= -1;
42 static int hf_parameter_value
= -1;
43 static int hf_query
= -1;
44 static int hf_authtype
= -1;
45 static int hf_passwd
= -1;
46 static int hf_salt
= -1;
47 static int hf_statement
= -1;
48 static int hf_portal
= -1;
49 static int hf_tag
= -1;
50 static int hf_status
= -1;
51 static int hf_copydata
= -1;
52 static int hf_error
= -1;
53 static int hf_pid
= -1;
54 static int hf_key
= -1;
55 static int hf_condition
= -1;
56 static int hf_text
= -1;
57 static int hf_tableoid
= -1;
58 static int hf_typeoid
= -1;
59 static int hf_oid
= -1;
60 static int hf_format
= -1;
61 static int hf_field_count
= -1;
62 static int hf_val_name
= -1;
63 static int hf_val_idx
= -1;
64 static int hf_val_length
= -1;
65 static int hf_val_data
= -1;
66 static int hf_val_mod
= -1;
67 static int hf_severity
= -1;
68 static int hf_code
= -1;
69 static int hf_message
= -1;
70 static int hf_detail
= -1;
71 static int hf_hint
= -1;
72 static int hf_position
= -1;
73 static int hf_where
= -1;
74 static int hf_file
= -1;
75 static int hf_line
= -1;
76 static int hf_routine
= -1;
78 static gint ett_pgsql
= -1;
79 static gint ett_values
= -1;
81 static guint pgsql_port
= 5432;
82 static gboolean pgsql_desegment
= TRUE
;
83 static gboolean first_message
= TRUE
;
85 static const value_string fe_messages
[] = {
86 { 'p', "Password message" },
87 { 'Q', "Simple query" },
95 { 'F', "Function call" },
97 { 'c', "Copy completion" },
98 { 'f', "Copy failure" },
99 { 'X', "Termination" },
103 static const value_string be_messages
[] = {
104 { 'R', "Authentication request" },
105 { 'K', "Backend key data" },
106 { 'S', "Parameter status" },
107 { '1', "Parse completion" },
108 { '2', "Bind completion" },
109 { '3', "Close completion" },
110 { 'C', "Command completion" },
111 { 't', "Parameter description" },
112 { 'T', "Row description" },
114 { 'I', "Empty query" },
118 { 's', "Portal suspended" },
119 { 'Z', "Ready for query" },
120 { 'A', "Notification" },
121 { 'V', "Function call response" },
122 { 'G', "CopyIn response" },
123 { 'H', "CopyOut response" },
124 { 'd', "Copy data" },
125 { 'c', "Copy completion" },
130 static const value_string auth_types
[] = {
132 { 1, "Kerberos V4" },
133 { 2, "Kerberos V5" },
134 { 3, "Plaintext password" },
135 { 4, "crypt()ed password" },
136 { 5, "MD5 password" },
137 { 6, "SCM credentials" },
141 static const value_string status_vals
[] = {
143 { 'T', "In a transaction" },
144 { 'E', "In a failed transaction" },
148 static const value_string format_vals
[] = {
154 static void dissect_pgsql_fe_msg(guchar type
, guint length
, tvbuff_t
*tvb
,
155 gint n
, proto_tree
*tree
)
160 proto_item
*ti
, *hidden_item
;
166 siz
= tvb_strsize(tvb
, n
);
167 proto_tree_add_item(tree
, hf_passwd
, tvb
, n
, siz
, ENC_ASCII
|ENC_NA
);
172 siz
= tvb_strsize(tvb
, n
);
173 proto_tree_add_item(tree
, hf_query
, tvb
, n
, siz
, ENC_ASCII
|ENC_NA
);
178 siz
= tvb_strsize(tvb
, n
);
179 proto_tree_add_item(tree
, hf_statement
, tvb
, n
, siz
, ENC_ASCII
|ENC_NA
);
182 siz
= tvb_strsize(tvb
, n
);
183 proto_tree_add_item(tree
, hf_query
, tvb
, n
, siz
, ENC_ASCII
|ENC_NA
);
186 i
= tvb_get_ntohs(tvb
, n
);
187 ti
= proto_tree_add_text(tree
, tvb
, n
, 2, "Parameters: %d", i
);
188 shrub
= proto_item_add_subtree(ti
, ett_values
);
191 proto_tree_add_item(shrub
, hf_typeoid
, tvb
, n
, 4, ENC_BIG_ENDIAN
);
198 siz
= tvb_strsize(tvb
, n
);
199 proto_tree_add_item(tree
, hf_portal
, tvb
, n
, siz
, ENC_ASCII
|ENC_NA
);
202 siz
= tvb_strsize(tvb
, n
);
203 proto_tree_add_item(tree
, hf_statement
, tvb
, n
, siz
, ENC_ASCII
|ENC_NA
);
206 i
= tvb_get_ntohs(tvb
, n
);
207 ti
= proto_tree_add_text(tree
, tvb
, n
, 2, "Parameter formats: %d", i
);
208 shrub
= proto_item_add_subtree(ti
, ett_values
);
211 proto_tree_add_item(shrub
, hf_format
, tvb
, n
, 2, ENC_BIG_ENDIAN
);
215 i
= tvb_get_ntohs(tvb
, n
);
216 ti
= proto_tree_add_text(tree
, tvb
, n
, 2, "Parameter values: %d", i
);
217 shrub
= proto_item_add_subtree(ti
, ett_values
);
220 siz
= tvb_get_ntohl(tvb
, n
);
221 proto_tree_add_int(shrub
, hf_val_length
, tvb
, n
, 4, siz
);
224 proto_tree_add_item(shrub
, hf_val_data
, tvb
, n
, siz
, ENC_NA
);
229 i
= tvb_get_ntohs(tvb
, n
);
230 ti
= proto_tree_add_text(tree
, tvb
, n
, 2, "Result formats: %d", i
);
231 shrub
= proto_item_add_subtree(ti
, ett_values
);
234 proto_tree_add_item(shrub
, hf_format
, tvb
, n
, 2, ENC_BIG_ENDIAN
);
241 siz
= tvb_strsize(tvb
, n
);
242 proto_tree_add_item(tree
, hf_portal
, tvb
, n
, siz
, ENC_ASCII
|ENC_NA
);
245 ti
= proto_tree_add_text(tree
, tvb
, n
, 4, "Returns: ");
246 i
= tvb_get_ntohl(tvb
, n
);
248 proto_item_append_text(ti
, "all");
250 proto_item_append_text(ti
, "%d", i
);
251 proto_item_append_text(ti
, " rows");
254 /* Describe, Close */
257 c
= tvb_get_guint8(tvb
, n
);
265 s
= tvb_get_stringz(wmem_packet_scope(), tvb
, n
, &siz
);
266 hidden_item
= proto_tree_add_string(tree
, i
, tvb
, n
, siz
, s
);
267 PROTO_ITEM_SET_HIDDEN(hidden_item
);
269 tree
, tvb
, n
-1, siz
, "%s: %s",
270 (c
== 'P' ? "Portal" : "Statement"), s
275 /* Messages without a type identifier */
277 i
= tvb_get_ntohl(tvb
, n
);
281 /* Startup message */
283 while ((signed)length
> 0) {
284 siz
= tvb_strsize(tvb
, n
);
286 if ((signed)length
<= 0) {
289 proto_tree_add_item(tree
, hf_parameter_name
, tvb
, n
, siz
, ENC_ASCII
|ENC_NA
);
290 i
= tvb_strsize(tvb
, n
+siz
);
291 proto_tree_add_item(tree
, hf_parameter_value
, tvb
, n
+ siz
, i
, ENC_ASCII
|ENC_NA
);
295 if (length
== 1 && tvb_get_guint8(tvb
, n
) == 0)
302 /* There's nothing to parse here, but what do we do if the
303 SSL negotiation succeeds? */
306 /* Cancellation request */
308 proto_tree_add_item(tree
, hf_pid
, tvb
, n
, 4, ENC_BIG_ENDIAN
);
309 proto_tree_add_item(tree
, hf_key
, tvb
, n
+4, 4, ENC_BIG_ENDIAN
);
316 proto_tree_add_item(tree
, hf_copydata
, tvb
, n
, length
-n
+1, ENC_NA
);
321 siz
= tvb_strsize(tvb
, n
);
322 proto_tree_add_item(tree
, hf_error
, tvb
, n
, siz
, ENC_ASCII
|ENC_NA
);
327 proto_tree_add_item(tree
, hf_oid
, tvb
, n
, 4, ENC_BIG_ENDIAN
);
330 i
= tvb_get_ntohs(tvb
, n
);
331 ti
= proto_tree_add_text(tree
, tvb
, n
, 2, "Parameter formats: %d", i
);
332 shrub
= proto_item_add_subtree(ti
, ett_values
);
335 proto_tree_add_item(shrub
, hf_format
, tvb
, n
, 2, ENC_BIG_ENDIAN
);
339 i
= tvb_get_ntohs(tvb
, n
);
340 ti
= proto_tree_add_text(tree
, tvb
, n
, 2, "Parameter values: %d", i
);
341 shrub
= proto_item_add_subtree(ti
, ett_values
);
344 siz
= tvb_get_ntohl(tvb
, n
);
345 proto_tree_add_item(shrub
, hf_val_length
, tvb
, n
, 4, ENC_BIG_ENDIAN
);
348 proto_tree_add_item(shrub
, hf_val_data
, tvb
, n
, siz
, ENC_NA
);
353 proto_tree_add_item(tree
, hf_format
, tvb
, n
, 2, ENC_BIG_ENDIAN
);
359 static void dissect_pgsql_be_msg(guchar type
, guint length
, tvbuff_t
*tvb
,
360 gint n
, proto_tree
*tree
)
365 proto_item
*ti
, *hidden_item
;
369 /* Authentication request */
371 proto_tree_add_item(tree
, hf_authtype
, tvb
, n
, 4, ENC_BIG_ENDIAN
);
372 i
= tvb_get_ntohl(tvb
, n
);
373 if (i
== 4 || i
== 5) {
374 /* i -= (6-i); :-) */
376 siz
= (i
== 4 ? 2 : 4);
377 proto_tree_add_item(tree
, hf_salt
, tvb
, n
, siz
, ENC_NA
);
383 proto_tree_add_item(tree
, hf_pid
, tvb
, n
, 4, ENC_BIG_ENDIAN
);
384 proto_tree_add_item(tree
, hf_key
, tvb
, n
+4, 4, ENC_BIG_ENDIAN
);
387 /* Parameter status */
389 s
= tvb_get_stringz(wmem_packet_scope(), tvb
, n
, &siz
);
390 hidden_item
= proto_tree_add_string(tree
, hf_parameter_name
, tvb
, n
, siz
, s
);
391 PROTO_ITEM_SET_HIDDEN(hidden_item
);
393 t
= tvb_get_stringz(wmem_packet_scope(), tvb
, n
, &i
);
394 hidden_item
= proto_tree_add_string(tree
, hf_parameter_value
, tvb
, n
, i
, t
);
395 PROTO_ITEM_SET_HIDDEN(hidden_item
);
396 proto_tree_add_text(tree
, tvb
, n
-siz
, siz
+i
, "%s: %s", s
, t
);
399 /* Parameter description */
401 i
= tvb_get_ntohs(tvb
, n
);
402 proto_tree_add_text(tree
, tvb
, n
, 2, "Parameters: %d", i
);
405 proto_tree_add_item(tree
, hf_typeoid
, tvb
, n
, 4, ENC_BIG_ENDIAN
);
410 /* Row description */
412 i
= tvb_get_ntohs(tvb
, n
);
413 ti
= proto_tree_add_item(tree
, hf_field_count
, tvb
, n
, 2, ENC_BIG_ENDIAN
);
414 shrub
= proto_item_add_subtree(ti
, ett_values
);
418 siz
= tvb_strsize(tvb
, n
);
419 ti
= proto_tree_add_item(shrub
, hf_val_name
, tvb
, n
, siz
, ENC_ASCII
|ENC_NA
);
420 twig
= proto_item_add_subtree(ti
, ett_values
);
422 proto_tree_add_item(twig
, hf_tableoid
, tvb
, n
, 4, ENC_BIG_ENDIAN
);
424 proto_tree_add_item(twig
, hf_val_idx
, tvb
, n
, 2, ENC_BIG_ENDIAN
);
426 proto_tree_add_item(twig
, hf_typeoid
, tvb
, n
, 4, ENC_BIG_ENDIAN
);
428 proto_tree_add_item(twig
, hf_val_length
, tvb
, n
, 2, ENC_BIG_ENDIAN
);
430 proto_tree_add_item(twig
, hf_val_mod
, tvb
, n
, 4, ENC_BIG_ENDIAN
);
432 proto_tree_add_item(twig
, hf_format
, tvb
, n
, 2, ENC_BIG_ENDIAN
);
439 i
= tvb_get_ntohs(tvb
, n
);
440 ti
= proto_tree_add_item(tree
, hf_field_count
, tvb
, n
, 2, ENC_BIG_ENDIAN
);
441 shrub
= proto_item_add_subtree(ti
, ett_values
);
444 siz
= tvb_get_ntohl(tvb
, n
);
445 proto_tree_add_int(shrub
, hf_val_length
, tvb
, n
, 4, siz
);
448 proto_tree_add_item(shrub
, hf_val_data
, tvb
, n
, siz
, ENC_NA
);
454 /* Command completion */
456 siz
= tvb_strsize(tvb
, n
);
457 proto_tree_add_item(tree
, hf_tag
, tvb
, n
, siz
, ENC_ASCII
|ENC_NA
);
462 proto_tree_add_item(tree
, hf_status
, tvb
, n
, 1, ENC_NA
);
469 while ((signed)length
> 0) {
470 c
= tvb_get_guint8(tvb
, n
);
473 s
= tvb_get_stringz(wmem_packet_scope(), tvb
, n
+1, &siz
);
476 case 'S': i
= hf_severity
; break;
477 case 'C': i
= hf_code
; break;
478 case 'M': i
= hf_message
; break;
479 case 'D': i
= hf_detail
; break;
480 case 'H': i
= hf_hint
; break;
481 case 'P': i
= hf_position
; break;
482 case 'W': i
= hf_where
; break;
483 case 'F': i
= hf_file
; break;
484 case 'L': i
= hf_line
; break;
485 case 'R': i
= hf_routine
; break;
487 proto_tree_add_string(tree
, i
, tvb
, n
, siz
+1, s
);
493 /* NOTICE response */
495 proto_tree_add_item(tree
, hf_pid
, tvb
, n
, 4, ENC_BIG_ENDIAN
);
497 siz
= tvb_strsize(tvb
, n
);
498 proto_tree_add_item(tree
, hf_condition
, tvb
, n
, siz
, ENC_ASCII
|ENC_NA
);
500 siz
= tvb_strsize(tvb
, n
);
502 proto_tree_add_item(tree
, hf_text
, tvb
, n
, siz
, ENC_ASCII
|ENC_NA
);
508 proto_tree_add_item(tree
, hf_format
, tvb
, n
, 1, ENC_BIG_ENDIAN
);
510 i
= tvb_get_ntohs(tvb
, n
);
511 ti
= proto_tree_add_text(tree
, tvb
, n
, 2, "Columns: %d", i
);
512 shrub
= proto_item_add_subtree(ti
, ett_values
);
515 proto_tree_add_item(shrub
, hf_format
, tvb
, n
, 2, ENC_BIG_ENDIAN
);
522 proto_tree_add_item(tree
, hf_copydata
, tvb
, n
, length
-n
+1, ENC_NA
);
525 /* Function call response */
527 siz
= tvb_get_ntohl(tvb
, n
);
528 proto_tree_add_int(tree
, hf_val_length
, tvb
, n
, 4, siz
);
530 proto_tree_add_item(tree
, hf_val_data
, tvb
, n
+4, siz
, ENC_NA
);
535 /* This function is called by tcp_dissect_pdus() to find the size of the
536 message starting at tvb[offset]. */
538 pgsql_length(packet_info
*pinfo _U_
, tvbuff_t
*tvb
, int offset
)
544 /* The length is either the four bytes after the type, or, if the
545 type is 0, the first four bytes. */
546 type
= tvb_get_guint8(tvb
, offset
);
549 length
= tvb_get_ntohl(tvb
, offset
+n
);
554 /* This function is responsible for dissecting a single message. */
557 dissect_pgsql_msg(tvbuff_t
*tvb
, packet_info
*pinfo
, proto_tree
*tree
, void* data _U_
)
559 proto_item
*ti
, *hidden_item
;
566 gboolean fe
= (pinfo
->match_uint
== pinfo
->destport
);
569 type
= tvb_get_guint8(tvb
, 0);
572 length
= tvb_get_ntohl(tvb
, n
);
574 /* This is like specifying VALS(messages) for hf_type, which we can't do
575 directly because of messages without type bytes, and because the type
576 interpretation depends on fe. */
578 /* There are a few frontend messages that have no leading type byte.
579 We identify them by the fact that the first byte of their length
580 must be zero, and that the next four bytes are a unique tag. */
582 guint tag
= tvb_get_ntohl(tvb
, 4);
584 if (length
== 16 && tag
== 80877102)
585 typestr
= "Cancel request";
586 else if (length
== 8 && tag
== 80877103)
587 typestr
= "SSL request";
588 else if (tag
== 196608)
589 typestr
= "Startup message";
593 typestr
= val_to_str_const(type
, fe_messages
, "Unknown");
596 typestr
= val_to_str_const(type
, be_messages
, "Unknown");
599 /* This is a terrible hack. It makes the "Info" column reflect
600 the contents of every message in a TCP packet. Could it be
602 col_append_fstr(pinfo
->cinfo
, COL_INFO
, "%s%c",
603 ( first_message
? "" : "/" ), type
);
604 first_message
= FALSE
;
607 ti
= proto_tree_add_item(tree
, proto_pgsql
, tvb
, 0, -1, ENC_NA
);
608 ptree
= proto_item_add_subtree(ti
, ett_pgsql
);
613 proto_tree_add_text(ptree
, tvb
, 0, n
, "Type: %s", typestr
);
614 hidden_item
= proto_tree_add_item(ptree
, hf_type
, tvb
, 0, n
, ENC_ASCII
|ENC_NA
);
615 PROTO_ITEM_SET_HIDDEN(hidden_item
);
616 proto_tree_add_item(ptree
, hf_length
, tvb
, n
, 4, ENC_BIG_ENDIAN
);
617 hidden_item
= proto_tree_add_boolean(ptree
, hf_frontend
, tvb
, 0, 0, fe
);
618 PROTO_ITEM_SET_HIDDEN(hidden_item
);
622 dissect_pgsql_fe_msg(type
, length
, tvb
, n
, ptree
);
624 dissect_pgsql_be_msg(type
, length
, tvb
, n
, ptree
);
627 return tvb_length(tvb
);
630 /* This function is called once per TCP packet. It sets COL_PROTOCOL and
631 * identifies FE/BE messages by adding a ">" or "<" to COL_INFO. Then it
632 * arranges for each message to be dissected individually. */
635 dissect_pgsql(tvbuff_t
*tvb
, packet_info
*pinfo
, proto_tree
*tree
, void* data
)
637 /* conversation_t *cv; */
639 first_message
= TRUE
;
641 /* We don't use conversation data yet, but... */
642 /* cv = find_or_create_conversation(pinfo); */
644 col_set_str(pinfo
->cinfo
, COL_PROTOCOL
, "PGSQL");
645 col_set_str(pinfo
->cinfo
, COL_INFO
,
646 (pinfo
->match_uint
== pinfo
->destport
) ?
649 tcp_dissect_pdus(tvb
, pinfo
, tree
, pgsql_desegment
, 5,
650 pgsql_length
, dissect_pgsql_msg
, data
);
651 return tvb_length(tvb
);
655 proto_reg_handoff_pgsql(void);
658 proto_register_pgsql(void)
660 static hf_register_info hf
[] = {
662 { "Frontend", "pgsql.frontend", FT_BOOLEAN
, BASE_NONE
, NULL
, 0x0,
663 "True for messages from the frontend, false otherwise.",
667 { "Type", "pgsql.type", FT_STRING
, BASE_NONE
, NULL
, 0,
668 "A one-byte message type identifier.", HFILL
}
671 { "Length", "pgsql.length", FT_UINT32
, BASE_DEC
, NULL
, 0,
672 "The length of the message (not including the type).",
675 { &hf_parameter_name
,
676 { "Parameter name", "pgsql.parameter_name", FT_STRINGZ
,
677 BASE_NONE
, NULL
, 0, "The name of a database parameter.",
680 { &hf_parameter_value
,
681 { "Parameter value", "pgsql.parameter_value", FT_STRINGZ
,
682 BASE_NONE
, NULL
, 0, "The value of a database parameter.",
686 { "Query", "pgsql.query", FT_STRINGZ
, BASE_NONE
, NULL
, 0,
687 "A query string.", HFILL
}
690 { "Password", "pgsql.password", FT_STRINGZ
, BASE_NONE
, NULL
, 0,
691 "A password.", HFILL
}
694 { "Authentication type", "pgsql.authtype", FT_INT32
, BASE_DEC
,
696 "The type of authentication requested by the backend.", HFILL
}
699 { "Salt value", "pgsql.salt", FT_BYTES
, BASE_NONE
, NULL
, 0,
700 "The salt to use while encrypting a password.", HFILL
}
703 { "Statement", "pgsql.statement", FT_STRINGZ
, BASE_NONE
, NULL
, 0,
704 "The name of a prepared statement.", HFILL
}
707 { "Portal", "pgsql.portal", FT_STRINGZ
, BASE_NONE
, NULL
, 0,
708 "The name of a portal.", HFILL
}
711 { "Tag", "pgsql.tag", FT_STRINGZ
, BASE_NONE
, NULL
, 0,
712 "A completion tag.", HFILL
}
715 { "Status", "pgsql.status", FT_UINT8
, BASE_DEC
, VALS(status_vals
),
716 0, "The transaction status of the backend.", HFILL
}
719 { "Copy data", "pgsql.copydata", FT_BYTES
, BASE_NONE
, NULL
, 0,
720 "Data sent following a Copy-in or Copy-out response.", HFILL
}
723 { "Error", "pgsql.error", FT_STRINGZ
, BASE_NONE
, NULL
, 0,
724 "An error message.", HFILL
}
727 { "PID", "pgsql.pid", FT_UINT32
, BASE_DEC
, NULL
, 0,
728 "The process ID of a backend.", HFILL
}
731 { "Key", "pgsql.key", FT_UINT32
, BASE_DEC
, NULL
, 0,
732 "The secret key used by a particular backend.", HFILL
}
735 { "Condition", "pgsql.condition", FT_STRINGZ
, BASE_NONE
, NULL
, 0,
736 "The name of a NOTIFY condition.", HFILL
}
739 { "Text", "pgsql.text", FT_STRINGZ
, BASE_NONE
, NULL
, 0,
740 "Text from the backend.", HFILL
}
743 { "Table OID", "pgsql.oid.table", FT_UINT32
, BASE_DEC
, NULL
, 0,
744 "The object identifier of a table.", HFILL
}
747 { "Type OID", "pgsql.oid.type", FT_UINT32
, BASE_DEC
, NULL
, 0,
748 "The object identifier of a type.", HFILL
}
751 { "OID", "pgsql.oid", FT_UINT32
, BASE_DEC
, NULL
, 0,
752 "An object identifier.", HFILL
}
755 { "Format", "pgsql.format", FT_UINT16
, BASE_DEC
, VALS(format_vals
),
756 0, "A format specifier.", HFILL
}
759 { "Field count", "pgsql.field.count", FT_UINT16
, BASE_DEC
, NULL
, 0,
760 "The number of fields within a row.", HFILL
}
763 { "Column name", "pgsql.col.name", FT_STRINGZ
, BASE_NONE
, NULL
, 0,
764 "The name of a column.", HFILL
}
767 { "Column index", "pgsql.col.index", FT_UINT32
, BASE_DEC
, NULL
, 0,
768 "The position of a column within a row.", HFILL
}
771 { "Column length", "pgsql.val.length", FT_INT32
, BASE_DEC
, NULL
, 0,
772 "The length of a parameter value, in bytes. -1 means NULL.",
776 { "Data", "pgsql.val.data", FT_BYTES
, BASE_NONE
, NULL
, 0,
777 "Parameter data.", HFILL
}
780 { "Type modifier", "pgsql.col.typemod", FT_INT32
, BASE_DEC
, NULL
, 0,
781 "The type modifier for a column.", HFILL
}
784 { "Severity", "pgsql.severity", FT_STRINGZ
, BASE_NONE
, NULL
, 0,
785 "Message severity.", HFILL
}
788 { "Code", "pgsql.code", FT_STRINGZ
, BASE_NONE
, NULL
, 0,
789 "SQLState code.", HFILL
}
792 { "Message", "pgsql.message", FT_STRINGZ
, BASE_NONE
, NULL
, 0,
793 "Error message.", HFILL
}
796 { "Detail", "pgsql.detail", FT_STRINGZ
, BASE_NONE
, NULL
, 0,
797 "Detailed error message.", HFILL
}
800 { "Hint", "pgsql.hint", FT_STRINGZ
, BASE_NONE
, NULL
, 0,
801 "A suggestion to resolve an error.", HFILL
}
804 { "Position", "pgsql.position", FT_STRINGZ
, BASE_NONE
, NULL
, 0,
805 "The index of the error within the query string.", HFILL
}
808 { "Context", "pgsql.where", FT_STRINGZ
, BASE_NONE
, NULL
, 0,
809 "The context in which an error occurred.", HFILL
}
812 { "File", "pgsql.file", FT_STRINGZ
, BASE_NONE
, NULL
, 0,
813 "The source-code file where an error was reported.", HFILL
}
816 { "Line", "pgsql.line", FT_STRINGZ
, BASE_NONE
, NULL
, 0,
817 "The line number on which an error was reported.", HFILL
}
820 { "Routine", "pgsql.routine", FT_STRINGZ
, BASE_NONE
, NULL
, 0,
821 "The routine that reported an error.", HFILL
}
825 static gint
*ett
[] = {
832 proto_pgsql
= proto_register_protocol("PostgreSQL", "PGSQL", "pgsql");
833 proto_register_field_array(proto_pgsql
, hf
, array_length(hf
));
834 proto_register_subtree_array(ett
, array_length(ett
));
836 mod_pgsql
= prefs_register_protocol(proto_pgsql
, proto_reg_handoff_pgsql
);
837 prefs_register_uint_preference(
838 mod_pgsql
, "tcp.port", "PGSQL TCP port", "Set the port for PGSQL "
839 "messages (if different from the default of 5432)", 10, &pgsql_port
844 proto_reg_handoff_pgsql(void)
846 static gboolean initialized
= FALSE
;
847 static dissector_handle_t pgsql_handle
;
848 static guint saved_pgsql_port
;
851 pgsql_handle
= new_create_dissector_handle(dissect_pgsql
, proto_pgsql
);
854 dissector_delete_uint("tcp.port", saved_pgsql_port
, pgsql_handle
);
857 dissector_add_uint("tcp.port", pgsql_port
, pgsql_handle
);
858 saved_pgsql_port
= pgsql_port
;