Sharkd: Return error message on load if err!=0
Fixes a bug when the return value from load_cap_file() is nonzero. No response is currently returned causing the client to hang. A non-zero error code can happen for a variety of reasons, one of which is when the PCAP is truncated. An error message from cfile_read_failure_message() is displayed on the console, but no data was returned to the RPC client. This adds a call to wtap_strerrror() to look up a human consumable error message for the specific error code returned during wtap_read(). Adds new self-test to suite_sharkd.py
This commit is contained in:
parent
1236c07a03
commit
d98f6b16ef
|
@ -1087,7 +1087,17 @@ sharkd_session_process_load(const char *buf, const jsmntok_t *tokens, int count)
|
|||
ENDTRY;
|
||||
|
||||
if (err == 0)
|
||||
{
|
||||
sharkd_json_simple_ok(rpcid);
|
||||
}
|
||||
else
|
||||
{
|
||||
sharkd_json_result_prologue(rpcid);
|
||||
sharkd_json_value_string("status", wtap_strerror(err));
|
||||
sharkd_json_value_anyf("err", "%d", err);
|
||||
sharkd_json_result_epilogue();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Binary file not shown.
|
@ -70,6 +70,15 @@ class case_sharkd(subprocesstest.SubprocessTestCase):
|
|||
{"jsonrpc":"2.0","id":1,"error":{"code":-2001,"message":"Unable to open the file"}},
|
||||
))
|
||||
|
||||
def test_sharkd_req_load_truncated_pcap(self, check_sharkd_session, capture_file):
|
||||
check_sharkd_session((
|
||||
{"jsonrpc":"2.0", "id":1, "method":"load",
|
||||
"params":{"file": capture_file('trunc.pcap')}
|
||||
},
|
||||
), (
|
||||
{"jsonrpc":"2.0","id":1,"result":{"status":"Less data was read than was expected","err":-12}},
|
||||
))
|
||||
|
||||
def test_sharkd_req_status_no_pcap(self, check_sharkd_session):
|
||||
check_sharkd_session((
|
||||
{"jsonrpc":"2.0", "id":1, "method":"status"},
|
||||
|
|
Loading…
Reference in New Issue