Skip to content

Commit

Permalink
[FIX]fix stop_dissect_capture_pkg and handle_packet function, ensure …
Browse files Browse the repository at this point in the history
…that the packet capture is started and stopped correctly
  • Loading branch information
randolphcyg committed Dec 26, 2023
1 parent 2a639c6 commit 51744a2
Show file tree
Hide file tree
Showing 4 changed files with 98 additions and 134 deletions.
7 changes: 7 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,10 @@ module github.com/randolphcyg/gowireshark
go 1.21.5

require github.com/pkg/errors v0.9.1

require (
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/stretchr/testify v1.8.4 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
9 changes: 9 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,2 +1,11 @@
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk=
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
7 changes: 2 additions & 5 deletions online.c
Original file line number Diff line number Diff line change
Expand Up @@ -613,10 +613,6 @@ char *handle_packet(char *device_name, char *bpf_expr, int num, int promisc,
before_callback_init(device);
pcap_loop(device->content.handle, num, process_packet_callback,
(u_char *)device->device_name);
// close libpcap device handler
pcap_close(device->content.handle);
// close cf file for live capture
close_cf_live(device->content.cf_live);

return "";
}
Expand All @@ -633,11 +629,12 @@ char *stop_dissect_capture_pkg(char *device_name) {
return "The device is not in the global map";
}

if (!device->content.handle) {
if (!device || !device->content.handle) {
return "This device has no pcap_handle, no need to close";
}

pcap_breakloop(device->content.handle);
device->content.handle = NULL;

// close cf file for live capture
close_cf_live(device->content.cf_live);
Expand Down
Loading

0 comments on commit 51744a2

Please sign in to comment.