Ask Your Question
0

how to replace ip in src/dst column with some text

asked 2024-08-22 08:16:55 +0000

BMWE gravatar image

updated 2024-08-22 09:10:18 +0000

Hi,

I'd like to change the ip display of the column to some text with lua.

  1. How can I do it?
  2. The IPs have some common template (like 10.10.XX.1). I'd like that this change would be on this template
edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
0

answered 2024-08-22 14:18:18 +0000

johnthacker gravatar image

Start by looking at the sections on Column and Columns in the WS Lua API reference portion of the Developer's Guide. Those are the functions you should use. There are API calls for converting a field that you already added as a IP address to that form, or you can do it in Lua. Both approaches are shown to get a string in the example here.

edit flag offensive delete link more

Comments

YMMV when trying to set columns from lua - WSDG: 11.5.3. Columns

Some columns cannot be modified, and no error is raised if attempted. The columns that are known to allow modification are "info" and "protocol".

Chuckc gravatar imageChuckc ( 2024-08-22 14:37:17 +0000 )edit

@Chuckc, so I should understand there is no way to change the source and destination IP columns, right?

BMWE gravatar imageBMWE ( 2024-08-22 15:06:11 +0000 )edit

There is a way to do it, but it's somewhat complicated. The details:

The default source and destination columns, which are not just for IP but for the last set address type in the frame - you can have custom columns for ip.src and ip.dst, which would work differently - at the end of packet processing they always replace what is in the column by a string obtained from whatever address is in the frame, unless it is address type NONE in which case nothing happens.

So the correct way to do it is to set pinfo->src and pinfo->dst, which can be done from Lua. If you are using a built in address type like IPv4 that should be straightforward. There are also some built-in generic string and numeric types. For some situations, the right thing would be to register a new address type in the dissector, but I ...(more)

johnthacker gravatar imagejohnthacker ( 2024-08-22 16:20:10 +0000 )edit

I tried it in a sample script and could not update src.
Don't have access to dev system at the moment to see why it get passed over.
Code here (epan/wslua/wslua_column.c):

    ===== Example
    pinfo.cols['info'] = 'foo bar'

    -- syntactic sugar (equivalent to above)
    pinfo.cols.info = 'foo bar'
    */
#define WSLUA_ARG_Columns__newindex_TEXT 3 /* The text for the column. */
    Columns cols = checkColumns(L,1);
    const struct col_names_t* cn;
    const char* colname;
    const char* text;

    if (!cols) return 0;
...
Chuckc gravatar imageChuckc ( 2024-08-22 16:20:38 +0000 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2024-08-22 08:16:55 +0000

Seen: 68 times

Last updated: Aug 22