Skip to content

Commit

Permalink
Added ether_type argument to RAW protocol support code
Browse files Browse the repository at this point in the history
  • Loading branch information
ccie18643 committed Sep 17, 2024
1 parent 9224970 commit aa28335
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 3 deletions.
2 changes: 1 addition & 1 deletion pytcp/protocols/enums.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ def from_proto(proto: Proto) -> EtherType:
return EtherType.ARP

if isinstance(proto, Raw):
return EtherType.RAW
return proto.ether_type

assert False, f"Unknown protocol: {type(proto)}"

Expand Down
4 changes: 3 additions & 1 deletion pytcp/protocols/raw/raw__assembler.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@

from pytcp.lib.proto_assembler import ProtoAssembler
from pytcp.lib.tracker import Tracker
from pytcp.protocols.enums import IpProto
from pytcp.protocols.enums import EtherType, IpProto
from pytcp.protocols.raw.raw__base import Raw


Expand All @@ -52,6 +52,7 @@ def __init__(
self,
*,
raw__payload: bytes = bytes(),
ether_type: EtherType = EtherType.RAW,
ip_proto: IpProto = IpProto.RAW,
echo_tracker: Tracker | None = None,
) -> None:
Expand All @@ -62,4 +63,5 @@ def __init__(
self._tracker: Tracker = Tracker(prefix="TX", echo_tracker=echo_tracker)

self._payload: bytes = raw__payload
self._ether_type: EtherType = ether_type
self._ip_proto: IpProto = ip_proto
11 changes: 10 additions & 1 deletion pytcp/protocols/raw/raw__base.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
from typing import override

from pytcp.lib.proto import Proto
from pytcp.protocols.enums import IpProto
from pytcp.protocols.enums import EtherType, IpProto


class Raw(Proto):
Expand All @@ -47,6 +47,7 @@ class Raw(Proto):
"""

_payload: bytes
_ether_type: EtherType
_ip_proto: IpProto

@override
Expand Down Expand Up @@ -89,6 +90,14 @@ def payload(self) -> bytes:

return self._payload

@property
def ether_type(self) -> EtherType:
"""
Get the Ethernet protocol number.
"""

return self._ether_type

@property
def ip_proto(self) -> IpProto:
"""
Expand Down

0 comments on commit aa28335

Please sign in to comment.