Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions marine/exceptions.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
class BadBPFException(Exception):
pass


class BadDisplayFilterException(Exception):
pass


class InvalidFieldException(Exception):
pass


class UnknownInternalException(Exception):
pass
22 changes: 19 additions & 3 deletions marine/marine.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@
from io import StringIO
from typing import Optional, List, Dict

from .exceptions import (
BadBPFException,
BadDisplayFilterException,
InvalidFieldException,
UnknownInternalException,
)
from . import encap_consts


Expand Down Expand Up @@ -81,9 +87,19 @@ def filter_and_parse(
bpf, display_filter, encoded_fields, encapsulation_type
)
if filter_id < 0:
raise ValueError(
err
) # TODO: create custom exception for every error type
if filter_id == c_int.in_dll(self._marine, "BAD_BPF_ERROR_CODE").value:
raise BadBPFException(err)
elif (
filter_id
== c_int.in_dll(self._marine, "BAD_DISPLAY_FILTER_ERROR_CODE").value
):
raise BadDisplayFilterException(err)
elif (
filter_id
== c_int.in_dll(self._marine, "INVALID_FIELD_ERROR_CODE").value
):
raise InvalidFieldException(err)
raise UnknownInternalException(err)
self._filters_cache[filter_key] = filter_id

packet_data = self._prepare_packet_data(packet)
Expand Down