4 * Wireshark's interface to the Lua Programming Language
6 * (c) 2006, Luis E. Garcia Ontanon <luis@ontanon.org>
7 * (c) 2008, Balint Reczey <balint.reczey@ericsson.com>
11 * Wireshark - Network traffic analyzer
12 * By Gerald Combs <gerald@wireshark.org>
13 * Copyright 1998 Gerald Combs
15 * This program is free software; you can redistribute it and/or
16 * modify it under the terms of the GNU General Public License
17 * as published by the Free Software Foundation; either version 2
18 * of the License, or (at your option) any later version.
20 * This program is distributed in the hope that it will be useful,
21 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 * GNU General Public License for more details.
25 * You should have received a copy of the GNU General Public License
26 * along with this program; if not, write to the Free Software
27 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
30 /* WSLUA_MODULE Pinfo Obtaining packet information */
35 #include <epan/addr_resolv.h>
40 * Track pointers to wireshark's structures.
41 * see comment on wslua_tvb.c
44 static GPtrArray* outstanding_Pinfo = NULL;
45 static GPtrArray* outstanding_Column = NULL;
46 static GPtrArray* outstanding_Columns = NULL;
48 CLEAR_OUTSTANDING(Pinfo,expired, TRUE)
49 CLEAR_OUTSTANDING(Column,expired, TRUE)
50 CLEAR_OUTSTANDING(Columns,expired, TRUE)
52 Pinfo* push_Pinfo(lua_State* L, packet_info* ws_pinfo) {
55 pinfo = g_malloc(sizeof(struct _wslua_pinfo));
56 pinfo->ws_pinfo = ws_pinfo;
57 pinfo->expired = FALSE;
58 g_ptr_array_add(outstanding_Pinfo,pinfo);
60 return pushPinfo(L,pinfo);
63 #define PUSH_COLUMN(L,c) {g_ptr_array_add(outstanding_Column,c);pushColumn(L,c);}
64 #define PUSH_COLUMNS(L,c) {g_ptr_array_add(outstanding_Columns,c);pushColumns(L,c);}
66 WSLUA_CLASS_DEFINE(Address,NOP,NOP); /* Represents an address */
68 WSLUA_CONSTRUCTOR Address_ip(lua_State* L) {
69 /* Creates an Address Object representing an IP address. */
71 #define WSLUA_ARG_Address_ip_HOSTNAME 1 /* The address or name of the IP host. */
72 Address addr = g_malloc(sizeof(address));
73 guint32* ip_addr = g_malloc(sizeof(guint32));
74 const gchar* name = luaL_checkstring(L,WSLUA_ARG_Address_ip_HOSTNAME);
76 if (! get_host_ipaddr(name, (guint32*)ip_addr)) {
80 SET_ADDRESS(addr, AT_IPv4, 4, ip_addr);
82 WSLUA_RETURN(1); /* the Address object */
87 static int Address_ipv6(lua_State* L) {
88 Address addr = g_malloc(sizeof(address));
90 SET_ADDRESS(addr, AT_NONE, 4, g_malloc(4));
95 static int Address_ss7(lua_State* L) {
96 Address addr = g_malloc(sizeof(address));
98 SET_ADDRESS(addr, AT_NONE, 4, g_malloc(4));
103 static int Address_eth(lua_State* L) {
104 Address addr = g_malloc(sizeof(address));
106 SET_ADDRESS(addr, AT_NONE, 4, g_malloc(4));
111 static int Address_sna(lua_State* L) {
112 Address addr = g_malloc(sizeof(address));
114 SET_ADDRESS(addr, AT_NONE, 4, g_malloc(4));
119 static int Address_atalk(lua_State* L) {
120 Address addr = g_malloc(sizeof(address));
122 SET_ADDRESS(addr, AT_NONE, 4, g_malloc(4));
127 static int Address_vines(lua_State* L) {
128 Address addr = g_malloc(sizeof(address));
130 SET_ADDRESS(addr, AT_NONE, 4, g_malloc(4));
135 static int Address_osi(lua_State* L) {
136 Address addr = g_malloc(sizeof(address));
138 SET_ADDRESS(addr, AT_NONE, 4, g_malloc(4));
143 static int Address_arcnet(lua_State* L) {
144 Address addr = g_malloc(sizeof(address));
146 SET_ADDRESS(addr, AT_NONE, 4, g_malloc(4));
151 static int Address_fc(lua_State* L) {
152 Address addr = g_malloc(sizeof(address));
154 SET_ADDRESS(addr, AT_NONE, 4, g_malloc(4));
159 static int Address_string(lua_State* L) {
160 Address addr = g_malloc(sizeof(address));
162 SET_ADDRESS(addr, AT_NONE, 4, g_malloc(4));
167 static int Address_eui64(lua_State* L) {
168 Address addr = g_malloc(sizeof(address));
170 SET_ADDRESS(addr, AT_NONE, 4, g_malloc(4));
175 static int Address_uri(lua_State* L) {
176 Address addr = g_malloc(sizeof(address));
178 SET_ADDRESS(addr, AT_NONE, 4, g_malloc(4));
183 static int Address_tipc(lua_State* L) {
184 Address addr = g_malloc(sizeof(address));
186 SET_ADDRESS(addr, AT_NONE, 4, g_malloc(4));
193 WSLUA_METHODS Address_methods[] = {
195 {"ipv4", Address_ip },
197 {"ipv6", Address_ipv6 },
198 {"ss7pc", Address_ss7 },
199 {"eth", Address_eth },
200 {"sna", Address_sna },
201 {"atalk", Address_atalk },
202 {"vines", Address_vines },
203 {"osi", Address_osi },
204 {"arcnet", Address_arcnet },
206 {"string", Address_string },
207 {"eui64", Address_eui64 },
208 {"uri", Address_uri },
209 {"tipc", Address_tipc },
214 WSLUA_METAMETHOD Address__tostring(lua_State* L) {
215 Address addr = checkAddress(L,1);
217 lua_pushstring(L,get_addr_name(addr));
219 WSLUA_RETURN(1); /* The string representing the address. */
222 static int Address__gc(lua_State* L) {
223 Address addr = checkAddress(L,1);
226 if (addr->data) g_free((void*)addr->data);
233 WSLUA_METAMETHOD Address__eq(lua_State* L) { /* compares two Addresses */
234 Address addr1 = checkAddress(L,1);
235 Address addr2 = checkAddress(L,2);
236 gboolean result = FALSE;
238 if (ADDRESSES_EQUAL(addr1, addr2))
241 lua_pushboolean(L,result);
246 WSLUA_METAMETHOD Address__le(lua_State* L) { /* compares two Addresses */
247 Address addr1 = checkAddress(L,1);
248 Address addr2 = checkAddress(L,2);
249 gboolean result = FALSE;
251 if (CMP_ADDRESS(addr1, addr2) <= 0)
254 lua_pushboolean(L,result);
259 WSLUA_METAMETHOD Address__lt(lua_State* L) { /* compares two Addresses */
260 Address addr1 = checkAddress(L,1);
261 Address addr2 = checkAddress(L,2);
262 gboolean result = FALSE;
264 if (CMP_ADDRESS(addr1, addr2) < 0)
267 lua_pushboolean(L,result);
272 WSLUA_META Address_meta[] = {
273 {"__gc", Address__gc },
274 {"__tostring", Address__tostring },
275 {"__eq",Address__eq},
276 {"__le",Address__le},
277 {"__lt",Address__lt},
282 int Address_register(lua_State *L) {
283 WSLUA_REGISTER_CLASS(Address);
288 WSLUA_CLASS_DEFINE(Column,FAIL_ON_NULL("expired column"),NOP); /* A Column in the packet list */
295 static const struct col_names_t colnames[] = {
296 {"number",COL_NUMBER},
297 {"abs_time",COL_ABS_TIME},
298 {"cls_time",COL_CLS_TIME},
299 {"rel_time",COL_REL_TIME},
300 {"date",COL_ABS_DATE_TIME},
301 {"delta_time",COL_DELTA_TIME},
302 {"delta_time_displayed",COL_DELTA_TIME_DIS},
304 {"src_res",COL_RES_SRC},
305 {"src_unres",COL_UNRES_SRC},
306 {"dl_src",COL_DEF_DL_SRC},
307 {"dl_src_res",COL_RES_DL_SRC},
308 {"dl_src_unres",COL_UNRES_DL_SRC},
309 {"net_src",COL_DEF_NET_SRC},
310 {"net_src_res",COL_RES_NET_SRC},
311 {"net_src_unres",COL_UNRES_NET_SRC},
313 {"dst_res",COL_RES_DST},
314 {"dst_unres",COL_UNRES_DST},
315 {"dl_dst",COL_DEF_DL_DST},
316 {"dl_dst_res",COL_RES_DL_DST},
317 {"dl_dst_unres",COL_UNRES_DL_DST},
318 {"net_dst",COL_DEF_NET_DST},
319 {"net_dst_res",COL_RES_NET_DST},
320 {"net_dst_unres",COL_UNRES_NET_DST},
321 {"src_port",COL_DEF_SRC_PORT},
322 {"src_port_res",COL_RES_SRC_PORT},
323 {"src_port_unres",COL_UNRES_SRC_PORT},
324 {"dst_port",COL_DEF_DST_PORT},
325 {"dst_port_res",COL_RES_DST_PORT},
326 {"dst_port_unres",COL_UNRES_DST_PORT},
327 {"protocol",COL_PROTOCOL},
329 {"packet_len",COL_PACKET_LENGTH},
330 {"cumulative_bytes",COL_CUMULATIVE_BYTES},
333 {"direction",COL_IF_DIR},
334 {"circuit_id",COL_CIRCUIT_ID},
335 {"src_idx",COL_SRCIDX},
336 {"dst_idx",COL_DSTIDX},
338 {"tx_rate",COL_TX_RATE},
340 {"hpux_subsys",COL_HPUX_SUBSYS},
341 {"hpux_devid",COL_HPUX_DEVID},
342 {"dce_call",COL_DCE_CALL},
346 static gint col_name_to_id(const gchar* name) {
347 const struct col_names_t* cn;
348 for(cn = colnames; cn->name; cn++) {
349 if (g_str_equal(cn->name,name)) {
357 static const gchar* col_id_to_name(gint id) {
358 const struct col_names_t* cn;
359 for(cn = colnames; cn->name; cn++) {
360 if ( cn->id == id ) {
368 WSLUA_METAMETHOD Column__tostring(lua_State *L) {
369 Column c = checkColumn(L,1);
376 /* XXX: should return the column's text ! */
377 name = col_id_to_name(c->col);
378 lua_pushstring(L,name ? name : "Unknown Column");
380 WSLUA_RETURN(1); /* A string representing the column */
383 static int Column__gc(lua_State* L) {
384 Column col = checkColumn(L,1);
397 WSLUA_METHOD Column_clear(lua_State *L) {
398 /* Clears a Column */
399 Column c = checkColumn(L,1);
401 if (!(c && c->cinfo)) return 0;
403 if (check_col(c->cinfo, c->col))
404 col_clear(c->cinfo, c->col);
409 WSLUA_METHOD Column_set(lua_State *L) {
410 /* Sets the text of a Column */
411 #define WSLUA_ARG_Column_set_TEXT 2 /* The text to which to set the Column */
412 Column c = checkColumn(L,1);
413 const gchar* s = luaL_checkstring(L,WSLUA_ARG_Column_set_TEXT);
415 if (!(c && c->cinfo))
418 if (!s) WSLUA_ARG_ERROR(Column_set,TEXT,"must be a string");
420 if (check_col(c->cinfo, c->col))
421 col_set_str(c->cinfo, c->col, s);
426 WSLUA_METHOD Column_append(lua_State *L) {
427 /* Appends text to a Column */
428 #define WSLUA_ARG_Column_append_TEXT 2 /* The text to append to the Column */
429 Column c = checkColumn(L,1);
430 const gchar* s = luaL_checkstring(L,WSLUA_ARG_Column_append_TEXT);
432 if (!(c && c->cinfo))
435 if (!s) WSLUA_ARG_ERROR(Column_append,TEXT,"must be a string");
438 if (check_col(c->cinfo, c->col))
439 col_append_str(c->cinfo, c->col, s);
444 WSLUA_METHOD Column_preppend(lua_State *L) {
445 /* Prepends text to a Column */
446 #define WSLUA_ARG_Column_prepend_TEXT 2 /* The text to prepend to the Column */
447 Column c = checkColumn(L,1);
448 const gchar* s = luaL_checkstring(L,WSLUA_ARG_Column_prepend_TEXT);
450 if (!(c && c->cinfo))
453 if (!s) WSLUA_ARG_ERROR(Column_prepend,TEXT,"must be a string");
455 if (check_col(c->cinfo, c->col))
456 col_prepend_fstr(c->cinfo, c->col, "%s",s);
461 WSLUA_METHODS Column_methods[] = {
462 {"clear", Column_clear },
463 {"set", Column_set },
464 {"append", Column_append },
465 {"preppend", Column_preppend },
470 WSLUA_META Column_meta[] = {
471 {"__tostring", Column__tostring },
472 {"__gc", Column__gc },
477 int Column_register(lua_State *L) {
478 WSLUA_REGISTER_CLASS(Column);
487 WSLUA_CLASS_DEFINE(Columns,NOP,NOP);
488 /* The Columns of the packet list. */
490 WSLUA_METAMETHOD Columns__tostring(lua_State *L) {
491 lua_pushstring(L,"Columns");
493 /* The string "Columns", no real use, just for debugging purposes. */
496 WSLUA_METAMETHOD Columns__newindex(lua_State *L) {
497 /* Sets the text of a specific column */
498 #define WSLUA_ARG_Columns__newindex_COLUMN 2 /* the name of the column to set */
499 #define WSLUA_ARG_Columns__newindex_TEXT 3 /* the text for the column */
500 Columns cols = checkColumns(L,1);
501 const struct col_names_t* cn;
507 luaL_error(L,"expired column");
511 colname = luaL_checkstring(L,WSLUA_ARG_Columns__newindex_COLUMN);
512 text = luaL_checkstring(L,WSLUA_ARG_Columns__newindex_TEXT);
514 for(cn = colnames; cn->name; cn++) {
515 if( g_str_equal(cn->name,colname) ) {
516 if (check_col(cols->cinfo, cn->id))
517 col_set_str(cols->cinfo, cn->id, text);
522 WSLUA_ARG_ERROR(Columns__newindex,COLUMN,"the column name must be a valid column");
527 WSLUA_METAMETHOD Columns_index(lua_State *L) {
528 Columns cols = checkColumns(L,1);
529 const struct col_names_t* cn;
530 const char* colname = luaL_checkstring(L,2);
533 Column c = g_malloc(sizeof(struct _wslua_col_info));
535 c->col = col_name_to_id(colname);
544 luaL_error(L,"expired column");
548 if (!colname) return 0;
550 for(cn = colnames; cn->name; cn++) {
551 if( g_str_equal(cn->name,colname) ) {
552 Column c = g_malloc(sizeof(struct _wslua_col_info));
553 c->cinfo = cols->cinfo;
554 c->col = col_name_to_id(colname);
565 static int Columns_gc(lua_State* L) {
566 Columns cols = checkColumns(L,1);
571 cols->expired = TRUE;
580 static const luaL_reg Columns_meta[] = {
581 {"__tostring", Columns__tostring },
582 {"__newindex", Columns__newindex },
583 {"__index", Columns_index},
584 {"__gc", Columns_gc},
589 int Columns_register(lua_State *L) {
590 WSLUA_REGISTER_META(Columns);
595 WSLUA_CLASS_DEFINE(Pinfo,FAIL_ON_NULL("expired pinfo"),NOP);
596 /* Packet information */
598 static int Pinfo_tostring(lua_State *L) { lua_pushstring(L,"a Pinfo"); return 1; }
600 #define PINFO_GET_NUMBER(name,val) static int name(lua_State *L) { \
601 Pinfo pinfo = checkPinfo(L,1); \
602 if (!pinfo) return 0;\
603 if (pinfo->expired) { \
604 luaL_error(L,"expired_pinfo"); \
607 lua_pushnumber(L,(lua_Number)(val));\
611 #define PINFO_GET_STRING(name,val) static int name(lua_State *L) { \
612 Pinfo pinfo = checkPinfo(L,1); \
613 const gchar* value; \
614 if (!pinfo) return 0; \
615 if (pinfo->expired) { \
616 luaL_error(L,"expired_pinfo"); \
620 if (value) lua_pushstring(L,(const char*)(value)); else lua_pushnil(L); \
624 #define PINFO_GET_ADDRESS(name,role) static int name(lua_State *L) { \
625 Pinfo pinfo = checkPinfo(L,1); \
626 Address addr = g_malloc(sizeof(address)); \
627 if (!pinfo) return 0; \
628 if (pinfo->expired) { \
629 luaL_error(L,"expired_pinfo"); \
632 COPY_ADDRESS(addr, &(pinfo->ws_pinfo->role)); \
633 pushAddress(L,addr); \
637 PINFO_GET_NUMBER(Pinfo_number,pinfo->ws_pinfo->fd->num)
638 PINFO_GET_NUMBER(Pinfo_len,pinfo->ws_pinfo->fd->pkt_len)
639 PINFO_GET_NUMBER(Pinfo_caplen,pinfo->ws_pinfo->fd->cap_len)
640 PINFO_GET_NUMBER(Pinfo_abs_ts,(((double)pinfo->ws_pinfo->fd->abs_ts.secs) + (((double)pinfo->ws_pinfo->fd->abs_ts.nsecs) / 1000000000.0) ))
641 PINFO_GET_NUMBER(Pinfo_rel_ts,(((double)pinfo->ws_pinfo->fd->rel_ts.secs) + (((double)pinfo->ws_pinfo->fd->rel_ts.nsecs) / 1000000000.0) ))
642 PINFO_GET_NUMBER(Pinfo_delta_ts,(((double)pinfo->ws_pinfo->fd->del_cap_ts.secs) + (((double)pinfo->ws_pinfo->fd->del_cap_ts.nsecs) / 1000000000.0) ))
643 PINFO_GET_NUMBER(Pinfo_delta_dis_ts,(((double)pinfo->ws_pinfo->fd->del_dis_ts.secs) + (((double)pinfo->ws_pinfo->fd->del_dis_ts.nsecs) / 1000000000.0) ))
644 PINFO_GET_NUMBER(Pinfo_ipproto,pinfo->ws_pinfo->ipproto)
645 PINFO_GET_NUMBER(Pinfo_circuit_id,pinfo->ws_pinfo->circuit_id)
646 PINFO_GET_NUMBER(Pinfo_desegment_len,pinfo->ws_pinfo->desegment_len)
647 PINFO_GET_NUMBER(Pinfo_desegment_offset,pinfo->ws_pinfo->desegment_offset)
648 PINFO_GET_NUMBER(Pinfo_ptype,pinfo->ws_pinfo->ptype)
649 PINFO_GET_NUMBER(Pinfo_src_port,pinfo->ws_pinfo->srcport)
650 PINFO_GET_NUMBER(Pinfo_dst_port,pinfo->ws_pinfo->destport)
652 PINFO_GET_STRING(Pinfo_curr_proto,pinfo->ws_pinfo->current_proto)
654 PINFO_GET_ADDRESS(Pinfo_net_src,net_src)
655 PINFO_GET_ADDRESS(Pinfo_net_dst,net_dst)
656 PINFO_GET_ADDRESS(Pinfo_dl_src,dl_src)
657 PINFO_GET_ADDRESS(Pinfo_dl_dst,dl_dst)
658 PINFO_GET_ADDRESS(Pinfo_src,src)
659 PINFO_GET_ADDRESS(Pinfo_dst,dst)
661 static int Pinfo_visited(lua_State *L) {
662 Pinfo pinfo = checkPinfo(L,1);
663 if (!pinfo) return 0;
664 if (pinfo->expired) {
665 luaL_error(L,"expired_pinfo");
668 lua_pushboolean(L,pinfo->ws_pinfo->fd->flags.visited);
673 static int Pinfo_match(lua_State *L) {
674 Pinfo pinfo = checkPinfo(L,1);
676 if (!pinfo) return 0;
677 if (pinfo->expired) {
678 luaL_error(L,"expired_pinfo");
682 if (pinfo->ws_pinfo->match_string) {
683 lua_pushstring(L,pinfo->ws_pinfo->match_string);
685 lua_pushnumber(L,(lua_Number)(pinfo->ws_pinfo->match_port));
691 static int Pinfo_columns(lua_State *L) {
693 Pinfo pinfo = checkPinfo(L,1);
694 const gchar* colname = luaL_optstring(L,2,NULL);
696 if (pinfo->expired) {
697 luaL_error(L,"expired_pinfo");
701 cols = g_malloc(sizeof(struct _wslua_cols));
702 cols->cinfo = pinfo->ws_pinfo->cinfo;
703 cols->expired = FALSE;
706 PUSH_COLUMNS(L,cols);
709 PUSH_COLUMNS(L,cols);
710 lua_pushstring(L,colname);
711 return Columns_index(L);
729 PARAM_DESEGMENT_OFFSET,
731 } pinfo_param_type_t;
733 static int pushnil_param(lua_State* L, packet_info* pinfo _U_, pinfo_param_type_t pt _U_ ) {
738 int Pinfo_set_addr(lua_State* L, packet_info* pinfo, pinfo_param_type_t pt) {
739 const address* from = checkAddress(L,1);
743 luaL_error(L,"Not an OK address");
748 luaL_error(L,"expired_pinfo");
759 case PARAM_ADDR_DL_SRC:
760 to = &(pinfo->dl_src);
762 case PARAM_ADDR_DL_DST:
763 to = &(pinfo->dl_dst);
765 case PARAM_ADDR_NET_SRC:
766 to = &(pinfo->net_src);
768 case PARAM_ADDR_NET_DST:
769 to = &(pinfo->net_dst);
772 g_assert(!"BUG: A bad parameter");
776 COPY_ADDRESS(to,from);
780 int Pinfo_set_int(lua_State* L, packet_info* pinfo, pinfo_param_type_t pt) {
781 gint64 v = luaL_checkint(L,1);
784 luaL_error(L,"expired_pinfo");
790 pinfo->srcport = (guint32)v;
793 pinfo->destport = (guint32)v;
795 case PARAM_CIRCUIT_ID:
796 pinfo->circuit_id = (guint32)v;
798 case PARAM_DESEGMENT_LEN:
799 pinfo->desegment_len = (guint32)v;
801 case PARAM_DESEGMENT_OFFSET:
802 pinfo->desegment_offset = (int)v;
805 g_assert(!"BUG: A bad parameter");
811 typedef struct _pinfo_method_t {
814 int (*set)(lua_State*, packet_info*, pinfo_param_type_t);
815 pinfo_param_type_t param;
818 static int Pinfo_hi(lua_State *L) {
819 Pinfo pinfo = checkPinfo(L,1);
820 Address addr = g_malloc(sizeof(address));
822 if (!pinfo) return 0;
823 if (pinfo->expired) {
824 luaL_error(L,"expired_pinfo");
828 if (CMP_ADDRESS(&(pinfo->ws_pinfo->src), &(pinfo->ws_pinfo->dst) ) >= 0) {
829 COPY_ADDRESS(addr, &(pinfo->ws_pinfo->src));
831 COPY_ADDRESS(addr, &(pinfo->ws_pinfo->dst));
838 static int Pinfo_lo(lua_State *L) {
839 Pinfo pinfo = checkPinfo(L,1);
840 Address addr = g_malloc(sizeof(address));
842 if (!pinfo) return 0;
843 if (pinfo->expired) {
844 luaL_error(L,"expired_pinfo");
848 if (CMP_ADDRESS(&(pinfo->ws_pinfo->src), &(pinfo->ws_pinfo->dst) ) < 0) {
849 COPY_ADDRESS(addr, &(pinfo->ws_pinfo->src));
851 COPY_ADDRESS(addr, &(pinfo->ws_pinfo->dst));
859 static const pinfo_method_t Pinfo_methods[] = {
861 /* WSLUA_ATTRIBUTE Pinfo_number RO The number of this packet in the current file */
862 {"number", Pinfo_number, pushnil_param, PARAM_NONE},
864 /* WSLUA_ATTRIBUTE Pinfo_len RO The length of the frame */
865 {"len", Pinfo_len, pushnil_param, PARAM_NONE },
867 /* WSLUA_ATTRIBUTE Pinfo_caplen RO The captured length of the frame */
868 {"caplen", Pinfo_caplen, pushnil_param, PARAM_NONE },
870 /* WSLUA_ATTRIBUTE Pinfo_abs_ts RO When the packet was captured */
871 {"abs_ts",Pinfo_abs_ts, pushnil_param, PARAM_NONE },
873 /* WSLUA_ATTRIBUTE Pinfo_rel_ts RO Number of seconds passed since beginning of capture */
874 {"rel_ts",Pinfo_rel_ts, pushnil_param, PARAM_NONE },
876 /* WSLUA_ATTRIBUTE Pinfo_delta_ts RO Number of seconds passed since the last captured packet */
877 {"delta_ts",Pinfo_delta_ts, pushnil_param, PARAM_NONE },
879 /* WSLUA_ATTRIBUTE Pinfo_delta_dis_ts RO Number of seconds passed since the last displayed packet */
880 {"delta_dis_ts",Pinfo_delta_dis_ts, pushnil_param, PARAM_NONE },
882 /* WSLUA_ATTRIBUTE Pinfo_visited RO Whether this packet hass been already visited */
883 {"visited",Pinfo_visited, pushnil_param, PARAM_NONE },
885 /* WSLUA_ATTRIBUTE Pinfo_src RW Source Address of this Packet */
886 {"src", Pinfo_src, Pinfo_set_addr, PARAM_ADDR_SRC },
888 /* WSLUA_ATTRIBUTE Pinfo_dst RW Destination Address of this Packet */
889 {"dst", Pinfo_dst, Pinfo_set_addr, PARAM_ADDR_DST },
891 /* WSLUA_ATTRIBUTE Pinfo_lo RO lower Address of this Packet */
892 {"lo", Pinfo_lo, pushnil_param, PARAM_NONE },
894 /* WSLUA_ATTRIBUTE Pinfo_hi RW higher Address of this Packet */
895 {"hi", Pinfo_hi, pushnil_param, PARAM_NONE },
897 /* WSLUA_ATTRIBUTE Pinfo_dl_src RW Data Link Source Address of this Packet */
898 {"dl_src", Pinfo_dl_src, Pinfo_set_addr, PARAM_ADDR_DL_SRC },
900 /* WSLUA_ATTRIBUTE Pinfo_dl_dst RW Data Link Destination Address of this Packet */
901 {"dl_dst", Pinfo_dl_dst, Pinfo_set_addr, PARAM_ADDR_DL_DST },
903 /* WSLUA_ATTRIBUTE Pinfo_net_src RW Network Layer Source Address of this Packet */
904 {"net_src", Pinfo_net_src, Pinfo_set_addr, PARAM_ADDR_NET_SRC },
906 /* WSLUA_ATTRIBUTE Pinfo_net_dst RW Network Layer Destination Address of this Packet */
907 {"net_dst", Pinfo_net_dst, Pinfo_set_addr, PARAM_ADDR_NET_DST },
909 /* WSLUA_ATTRIBUTE Pinfo_ptype RW Type of Port of .src_port and .dst_port */
910 {"port_type", Pinfo_ptype, pushnil_param, PARAM_NONE },
912 /* WSLUA_ATTRIBUTE Pinfo_src_port RW Source Port of this Packet */
913 {"src_port", Pinfo_src_port, Pinfo_set_int, PARAM_PORT_SRC },
915 /* WSLUA_ATTRIBUTE Pinfo_dst_port RW Source Address of this Packet */
916 {"dst_port", Pinfo_dst_port, Pinfo_set_int, PARAM_PORT_SRC },
918 /* WSLUA_ATTRIBUTE Pinfo_ipproto RO IP Protocol id */
919 {"ipproto", Pinfo_ipproto, pushnil_param, PARAM_NONE },
921 /* WSLUA_ATTRIBUTE Pinfo_circuit_id RO For circuit based protocols */
922 {"circuit_id", Pinfo_circuit_id, Pinfo_set_int, PARAM_CIRCUIT_ID },
924 /* WSLUA_ATTRIBUTE Pinfo_match RO Port/Data we are matching */
925 {"match", Pinfo_match, pushnil_param, PARAM_NONE },
927 /* WSLUA_ATTRIBUTE Pinfo_curr_proto RO Which Protocol are we dissecting */
928 {"curr_proto", Pinfo_curr_proto, pushnil_param, PARAM_NONE },
930 /* WSLUA_ATTRIBUTE Pinfo_columns RO Accesss to the packet list columns */
931 {"columns", Pinfo_columns, pushnil_param, PARAM_NONE },
933 /* WSLUA_ATTRIBUTE Pinfo_cols RO Accesss to the packet list columns (equivalent to pinfo.cols) */
934 {"cols", Pinfo_columns, pushnil_param, PARAM_NONE },
936 /* WSLUA_ATTRIBUTE Pinfo_desegment_len RW Estimated number of additional bytes required for completing the PDU */
937 {"desegment_len", Pinfo_desegment_len, Pinfo_set_int, PARAM_DESEGMENT_LEN },
939 /* WSLUA_ATTRIBUTE Pinfo_desegment_len RW Offset in the tvbuff at which the dissector will continue processing when next called*/
940 {"desegment_offset", Pinfo_desegment_offset, Pinfo_set_int, PARAM_DESEGMENT_OFFSET },
942 {NULL,NULL,NULL,PARAM_NONE}
946 static int pushnil(lua_State* L) {
951 static int Pinfo_index(lua_State* L) {
952 Pinfo pinfo = checkPinfo(L,1);
953 const gchar* name = luaL_checkstring(L,2);
954 lua_CFunction method = pushnil;
955 const pinfo_method_t* curr;
957 if (! (pinfo && name) ) {
961 if (pinfo->expired) {
962 luaL_error(L,"expired_pinfo");
966 for (curr = Pinfo_methods ; curr->name ; curr++) {
967 if (g_str_equal(curr->name,name)) {
977 static int Pinfo_setindex(lua_State* L) {
978 Pinfo pinfo = checkPinfo(L,1);
979 const gchar* name = luaL_checkstring(L,2);
980 int (*method)(lua_State*, packet_info* pinfo, pinfo_param_type_t) = pushnil_param;
981 const pinfo_method_t* curr;
982 pinfo_param_type_t param_type = PARAM_NONE;
984 if (! (pinfo && name) ) {
987 if (pinfo->expired) {
988 luaL_error(L,"expired_pinfo");
992 for (curr = Pinfo_methods ; curr->name ; curr++) {
993 if (g_str_equal(curr->name,name)) {
995 param_type = curr->param;
1002 return method(L,pinfo->ws_pinfo,param_type);
1005 static int Pinfo_gc(lua_State* L) {
1006 Pinfo pinfo = checkPinfo(L,1);
1008 if (!pinfo) return 0;
1010 if (!pinfo->expired)
1011 pinfo->expired = TRUE;
1019 static const luaL_reg Pinfo_meta[] = {
1020 {"__index", Pinfo_index},
1021 {"__newindex",Pinfo_setindex},
1022 {"__tostring", Pinfo_tostring},
1027 int Pinfo_register(lua_State* L) {
1028 WSLUA_REGISTER_META(Pinfo);
1029 outstanding_Pinfo = g_ptr_array_new();
1030 outstanding_Column = g_ptr_array_new();
1031 outstanding_Columns = g_ptr_array_new();