Skip to content

Commit 06fb12d

Browse files
committed
v0.10.0
-Allow selection of a profile
1 parent 976a2fa commit 06fb12d

File tree

24 files changed

+91
-43
lines changed

24 files changed

+91
-43
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -486,4 +486,5 @@ $RECYCLE.BIN/
486486
[Nn]ative
487487
[Bb]uild
488488
[Ww]ireshark
489-
[Dd]ata
489+
[Dd]ata
490+
*.egg-info

build.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,13 @@
3535
lemonshark_host_binary_base_directory: str = f"""{lemonshark_host_build_directory}/bin"""
3636

3737
lemonshark_major_version: int = 0
38-
lemonshark_minor_version: int = 9
39-
lemonshark_patch_version: int = 1
38+
lemonshark_minor_version: int = 10
39+
lemonshark_patch_version: int = 0
4040

4141
wireshark_git_url: str = "https://gitlab.com/wireshark/wireshark.git"
4242
wireshark_major_version: int = 4
4343
wireshark_minor_version: int = 4
44-
wireshark_patch_version: int = 3
44+
wireshark_patch_version: int = 6
4545
wireshark_suffix_version: str = ""
4646

4747
wireshark_base_directory: str = f"""{os.getcwd()}/wireshark"""

build_python.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@
33
original_current_working_dir: str = os.getcwd()
44

55
os.chdir(f"""./python/lemonshark""")
6-
os.system(f"""python build.py""")
6+
os.system(f"""python build_python.py""")
77

88
os.chdir(original_current_working_dir)

dotnet/Examples/EpanPacket/Program.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
Console.OutputEncoding = System.Text.Encoding.UTF8;
1313

14+
// Set the environment variable LS_EXAMPLE_FILE to the path of a valid trace file before running this example.
1415
string traceFilePath = Environment.GetEnvironmentVariable("LS_EXAMPLE_FILE", EnvironmentVariableTarget.Process);
1516

1617
string assemblyDirectory = Path.GetDirectoryName(Assembly.GetAssembly(typeof(Program)).Location);
@@ -32,7 +33,7 @@
3233

3334
LemonShark.LemonShark.Init([wiresharkDirectory]);
3435

35-
using Session session = Session.CreateFromFile(traceFilePath, "");
36+
using Session session = Session.CreateFromFile(traceFilePath, "", null);
3637

3738
FieldDescription frameLengthFieldDescription = FieldDescription.GetByName("frame.len");
3839
int[] requestedFieldIds = [frameLengthFieldDescription.Id];

dotnet/Examples/FieldDescriptionDemo/Program.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
Console.OutputEncoding = System.Text.Encoding.UTF8;
77

8+
// Set the environment variable LS_EXAMPLE_FILE to the path of a valid trace file before running this example.
89
string traceFilePath = Environment.GetEnvironmentVariable("LS_EXAMPLE_FILE", EnvironmentVariableTarget.Process);
910

1011
string assemblyDirectory = Path.GetDirectoryName(Assembly.GetAssembly(typeof(Program)).Location);
@@ -26,7 +27,7 @@
2627

2728
LemonShark.LemonShark.Init([wiresharkDirectory]);
2829

29-
using Session session = Session.CreateFromFile(traceFilePath, "");
30+
using Session session = Session.CreateFromFile(traceFilePath, "", null);
3031

3132
// Get all field descriptions
3233
FieldDescription[] fieldDescriptions = FieldDescription.GetAll();

dotnet/Examples/FilterDemo/Program.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
Console.OutputEncoding = System.Text.Encoding.UTF8;
66

7+
// Set the environment variable LS_EXAMPLE_FILE to the path of a valid trace file before running this example.
78
string traceFilePath = Environment.GetEnvironmentVariable("LS_EXAMPLE_FILE", EnvironmentVariableTarget.Process);
89

910
string assemblyDirectory = Path.GetDirectoryName(Assembly.GetAssembly(typeof(Program)).Location);
@@ -25,7 +26,7 @@
2526

2627
LemonShark.LemonShark.Init([wiresharkDirectory]);
2728

28-
using Session session = Session.CreateFromFile(traceFilePath, "");
29+
using Session session = Session.CreateFromFile(traceFilePath, "", null);
2930

3031
// Test a valid filter
3132
string filter = "frame.len < 150";

dotnet/Examples/Packet/Program.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ static void Main(string[] args)
1515
{
1616
Console.OutputEncoding = System.Text.Encoding.UTF8;
1717

18+
// Set the environment variable LS_EXAMPLE_FILE to the path of a valid trace file before running this example.
1819
string traceFilePath = Environment.GetEnvironmentVariable("LS_EXAMPLE_FILE", EnvironmentVariableTarget.Process);
1920

2021
string assemblyDirectory = Path.GetDirectoryName(Assembly.GetAssembly(typeof(Program)).Location);
@@ -37,7 +38,7 @@ static void Main(string[] args)
3738
LemonShark.Init([wiresharkDirectory]);
3839

3940
// Read a file with a read filter
40-
using Session session = Session.CreateFromFile(traceFilePath, "frame.len < 150");
41+
using Session session = Session.CreateFromFile(traceFilePath, "frame.len < 150", null);
4142

4243
try
4344
{

dotnet/LemonShark/LemonShark.csproj

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@
1212
<Authors>DevAM</Authors>
1313
<Company>DevAM</Company>
1414
<Product>LemonShark</Product>
15-
<Version>0.9.1</Version>
16-
<AssemblyVersion>0.9.1</AssemblyVersion>
17-
<FileVersion>0.9.1</FileVersion>
15+
<Version>0.10.0</Version>
16+
<AssemblyVersion>0.10.0</AssemblyVersion>
17+
<FileVersion>0.10.0</FileVersion>
1818
<Description>Wireshark bindings for C# and .NET.</Description>
1919
<Copyright>Copyright (c) 2024 DevAM. All Rights Reserved.</Copyright>
2020
<PackageIcon>icon.png</PackageIcon>

dotnet/LemonShark/Session.cs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@ public class Session : IDisposable
1717

1818

1919
[DllImport(LemonShark.LemonSharkLibName, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
20-
private static extern int ls_session_create_from_file(IntPtr filePath, IntPtr readFilter, ref IntPtr errorMessage);
20+
private static extern int ls_session_create_from_file(IntPtr filePath, IntPtr readFilter, IntPtr profile, ref IntPtr errorMessage);
2121

22-
public static Session CreateFromFile(string filePath, string readFilter)
22+
public static Session CreateFromFile(string filePath, string readFilter, string profile)
2323
{
2424
if (_CurrentSession is not null)
2525
{
@@ -32,12 +32,14 @@ public static Session CreateFromFile(string filePath, string readFilter)
3232

3333
IntPtr utf8ReadFilter = Util.StringToNativeUtf8(readFilter);
3434

35+
IntPtr utf8Profile = Util.StringToNativeUtf8(profile);
36+
3537
IntPtr errorMessage = default;
3638
int creationResult = 0;
3739

3840
try
3941
{
40-
creationResult = ls_session_create_from_file(utf8FilePath, utf8ReadFilter, ref errorMessage);
42+
creationResult = ls_session_create_from_file(utf8FilePath, utf8ReadFilter, utf8Profile, ref errorMessage);
4143
}
4244
finally
4345
{

liblemonshark/examples/epan_packet/epan_packet_demo.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,10 +161,11 @@ int main(void)
161161
{
162162
void *error_handler = ls_error_handler_add(handle_error);
163163

164+
// Set the environment variable LS_EXAMPLE_FILE to the path of a valid trace file before running this example.
164165
const char *trace_file_path = g_getenv("LS_EXAMPLE_FILE");
165166

166167
char *error_message = NULL;
167-
gint32 init_result = ls_session_create_from_file(trace_file_path, "", &error_message);
168+
gint32 init_result = ls_session_create_from_file(trace_file_path, "", NULL, &error_message);
168169

169170
if (init_result == LS_ERROR)
170171
{

liblemonshark/examples/field_description/field_description_demo.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,11 @@ int main(void)
3232
{
3333
void *error_handler = ls_error_handler_add(handle_error);
3434

35+
// Set the environment variable LS_EXAMPLE_FILE to the path of a valid trace file before running this example.
3536
const char *trace_file_path = g_getenv("LS_EXAMPLE_FILE");
3637

3738
char *error_message = NULL;
38-
gint32 init_result = ls_session_create_from_file(trace_file_path, "", &error_message);
39+
gint32 init_result = ls_session_create_from_file(trace_file_path, "", NULL, &error_message);
3940

4041
if (init_result == LS_ERROR)
4142
{

liblemonshark/examples/filter/filter_demo.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,11 @@ int main(void)
1515
{
1616
void *error_handler = ls_error_handler_add(handle_error);
1717

18+
// Set the environment variable LS_EXAMPLE_FILE to the path of a valid trace file before running this example.
1819
const char *trace_file_path = g_getenv("LS_EXAMPLE_FILE");
1920

2021
char *error_message = NULL;
21-
gint32 init_result = ls_session_create_from_file(trace_file_path, "", &error_message);
22+
gint32 init_result = ls_session_create_from_file(trace_file_path, "", NULL, &error_message);
2223

2324
if (init_result == LS_ERROR)
2425
{

liblemonshark/examples/packet/packet_demo.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,10 +171,11 @@ int main(void)
171171
{
172172
void *error_handler = ls_error_handler_add(handle_error);
173173

174+
// Set the environment variable LS_EXAMPLE_FILE to the path of a valid trace file before running this example.
174175
const char *trace_file_path = g_getenv("LS_EXAMPLE_FILE");
175176

176177
char *error_message = NULL;
177-
gint32 init_result = ls_session_create_from_file(trace_file_path, "", &error_message);
178+
gint32 init_result = ls_session_create_from_file(trace_file_path, "", NULL, &error_message);
178179

179180
if (init_result == LS_ERROR)
180181
{

liblemonshark/src/include/session.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ extern "C"
2323
#include "packet.h"
2424
#include "epan_packet.h"
2525

26-
WS_DLL_PUBLIC gint32 ls_session_create_from_file(const char *file_path, const char *read_filter, char **error_message);
26+
WS_DLL_PUBLIC gint32 ls_session_create_from_file(const char *file_path, const char *read_filter, const char *profile, char **error_message);
2727

2828
WS_DLL_PUBLIC gint32 ls_session_get_next_packet_id(char **error_message);
2929

liblemonshark/src/session.c

Lines changed: 39 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ static session_t *ls_session_new(void)
7777
return session;
7878
}
7979

80-
static gint32 ls_init_infrastructure(char **error_message)
80+
static gint32 ls_init_infrastructure(const char *profile, char **error_message)
8181
{
8282
#ifdef _WIN32
8383
setlocale(LC_ALL, ".UTF-8");
@@ -90,6 +90,8 @@ static gint32 ls_init_infrastructure(char **error_message)
9090

9191
ws_init_version_info(LS_APP_NAME, epan_gather_compile_info, epan_gather_runtime_info);
9292

93+
configuration_init('\0', "wireshark");
94+
9395
static const struct report_message_routines report_routines = {
9496
failure_message,
9597
failure_message,
@@ -129,6 +131,19 @@ static gint32 ls_init_infrastructure(char **error_message)
129131

130132
codecs_init();
131133

134+
if (profile != NULL && strlen(profile) > 0)
135+
{
136+
if (profile_exists(profile, false))
137+
{
138+
set_profile_name(profile);
139+
}
140+
else
141+
{
142+
*error_message = g_strdup("Unknown profile.");
143+
return LS_ERROR;
144+
}
145+
}
146+
132147
preferences = epan_load_settings();
133148

134149
prefs_apply_all();
@@ -138,11 +153,11 @@ static gint32 ls_init_infrastructure(char **error_message)
138153
return LS_OK;
139154
}
140155

141-
static gint32 ls_session_init(char **error_message)
156+
static gint32 ls_session_init(const char *profile, char **error_message)
142157
{
143158
if (infrastructure_is_initialized == FALSE)
144159
{
145-
gint32 init_infrastructure_result = ls_init_infrastructure(error_message);
160+
gint32 init_infrastructure_result = ls_init_infrastructure(profile, error_message);
146161
if (init_infrastructure_result == LS_ERROR)
147162
{
148163
return LS_ERROR;
@@ -274,9 +289,28 @@ static wtap_block_t ls_get_modified_block(struct packet_provider_data *prov, con
274289
return NULL;
275290
}
276291

277-
gint32 ls_session_create_from_file(const char *file_path, const char *read_filter, char **error_message)
292+
gint32 ls_session_create_from_file(const char *file_path, const char *read_filter, const char *profile, char **error_message)
278293
{
279-
gint32 init_result = ls_session_init(error_message);
294+
if (session != NULL)
295+
{
296+
if (error_message != NULL)
297+
{
298+
*error_message = g_strdup("There can only be one session at a time.");
299+
}
300+
301+
return LS_ERROR;
302+
}
303+
304+
if(file_path == NULL || strlen(file_path) == 0)
305+
{
306+
if (error_message != NULL)
307+
{
308+
*error_message = g_strdup("File path is empty.");
309+
}
310+
return LS_ERROR;
311+
}
312+
313+
gint32 init_result = ls_session_init(profile, error_message);
280314
if (init_result == LS_ERROR)
281315
{
282316
return LS_ERROR;

python/examples/epan_packet/epan_packet.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,9 +130,10 @@ def main():
130130

131131
LemonShark.init([wireshark_directory])
132132

133+
# Set the environment variable LS_EXAMPLE_FILE to the path of a valid trace file before running this example.
133134
trace_file_path: str = os.environ["LS_EXAMPLE_FILE"]
134135

135-
session: Session = Session.create_from_file(trace_file_path, "")
136+
session: Session = Session.create_from_file(trace_file_path, "", None)
136137

137138
frame_length_field_description: FieldDescription = FieldDescription.get_by_name("frame.len")
138139
requested_field_ids: List[int] = [frame_length_field_description.get_id()]

python/examples/field_description/field_description_demo.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,10 @@ def main():
4242

4343
LemonShark.init([wireshark_directory])
4444

45+
# Set the environment variable LS_EXAMPLE_FILE to the path of a valid trace file before running this example.
4546
trace_file_path: str = os.environ["LS_EXAMPLE_FILE"]
4647

47-
session: Session = Session.create_from_file(trace_file_path, "")
48+
session: Session = Session.create_from_file(trace_file_path, "", None)
4849

4950
try:
5051
# Get all field descriptions

python/examples/filter/filter_demo.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,10 @@ def main():
2727

2828
LemonShark.init([wireshark_directory])
2929

30+
# Set the environment variable LS_EXAMPLE_FILE to the path of a valid trace file before running this example.
3031
trace_file_path: str = os.environ["LS_EXAMPLE_FILE"]
3132

32-
session: Session = Session.create_from_file(trace_file_path, "")
33+
session: Session = Session.create_from_file(trace_file_path, "", None)
3334

3435
# Test a valid filter
3536
filter:str = "frame.len < 150"

python/examples/packet/packet.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,9 +131,10 @@ def main():
131131

132132
LemonShark.init([wireshark_directory])
133133

134+
# Set the environment variable LS_EXAMPLE_FILE to the path of a valid trace file before running this example.
134135
trace_file_path: str = os.environ["LS_EXAMPLE_FILE"]
135136

136-
session: Session = Session.create_from_file(trace_file_path, "")
137+
session: Session = Session.create_from_file(trace_file_path, "", None)
137138

138139
try:
139140
packet_id: int = 0
File renamed without changes.

python/lemonshark/build.py

Lines changed: 0 additions & 10 deletions
This file was deleted.

python/lemonshark/build_python.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
"""
2+
Copyright (c) 2024 DevAM. All Rights Reserved.
3+
4+
SPDX-License-Identifier: GPL-2.0-only
5+
"""
6+
import os
7+
os.system(f"""pip install --upgrade setuptools twine wheel packaging build""")
8+
os.system(f"""python -m build --wheel --outdir ../../build/python .""")

python/lemonshark/lemonshark/session.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ def get_liblemonshark() -> CDLL:
2121
liblemonshark: CDLL = LemonShark.get_liblemonshark()
2222

2323
if not Session.__liblemonshark_initialized:
24-
liblemonshark.ls_session_create_from_file.argtypes = [c_char_p, c_char_p, POINTER(c_void_p)]
24+
liblemonshark.ls_session_create_from_file.argtypes = [c_char_p, c_char_p, c_char_p, POINTER(c_void_p)]
2525
liblemonshark.ls_session_create_from_file.restype = c_int32
2626

2727
liblemonshark.ls_session_get_next_packet_id.argtypes = [POINTER(c_void_p)]
@@ -43,7 +43,7 @@ def get_liblemonshark() -> CDLL:
4343
def __init__(self) -> None:
4444
self.closed = False
4545

46-
def create_from_file(file_path: str, read_filter: str) -> "Session":
46+
def create_from_file(file_path: str, read_filter: str, profile: str) -> "Session":
4747
liblemonshark: CDLL = Session.get_liblemonshark()
4848

4949
if Session.__current_session is not None:
@@ -53,8 +53,9 @@ def create_from_file(file_path: str, read_filter: str) -> "Session":
5353

5454
c_file_path: c_char_p = c_char_p(file_path.encode("utf-8"))
5555
c_read_filter: c_char_p = c_char_p(read_filter.encode("utf-8"))
56+
c_profile: c_char_p = c_char_p(profile.encode("utf-8"))
5657
c_error_message = c_void_p()
57-
creation_result: int = liblemonshark.ls_session_create_from_file(c_file_path, c_read_filter, byref(c_error_message))
58+
creation_result: int = liblemonshark.ls_session_create_from_file(c_file_path, c_read_filter, c_profile, byref(c_error_message))
5859

5960
if creation_result == LemonShark.error():
6061
error_message: str = ""

python/lemonshark/setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
setup(
1616
name="lemonshark",
17-
version="0.9.1",
17+
version="0.10.0",
1818
description="lemonshark allows to use Wireshark as a library in an python application",
1919
long_description=long_description,
2020
long_description_content_type="text/markdown",

0 commit comments

Comments
 (0)