diff --git a/examples/tcp_daytime_service.py b/examples/tcp_daytime_service.py index 982b195a..f32895e6 100755 --- a/examples/tcp_daytime_service.py +++ b/examples/tcp_daytime_service.py @@ -56,8 +56,8 @@ class TcpDaytimeService(TcpService): def __init__( self, *, - local_ip_address: str = "0.0.0.0", - local_port: int = 13, + local_ip_address: str, + local_port: int, message_count: int = -1, message_delay: int = 1, ): @@ -113,14 +113,24 @@ def service(self, *, connected_socket: Socket) -> None: @click.command() @click.option("--interface", default="tap7") -def cli(*, interface: str) -> None: +@click.option("--local-ip-address", default="0.0.0.0") +@click.option("--local-port", default=13, type=int) +def cli( + *, + interface: str, + local_ip_address: str, + local_port: int, +) -> None: """ Start PyTCP stack and stop it when user presses Ctrl-C. Run the TCP Daytime service. """ stack = TcpIpStack(fd=initialize_tap(tap_name=interface)) - service = TcpDaytimeService() + service = TcpDaytimeService( + local_ip_address=local_ip_address, + local_port=local_port, + ) try: stack.start() diff --git a/examples/tcp_discard_service.py b/examples/tcp_discard_service.py index 959b2ee8..64a2849f 100755 --- a/examples/tcp_discard_service.py +++ b/examples/tcp_discard_service.py @@ -53,7 +53,10 @@ class TcpDiscardService(TcpService): """ def __init__( - self, *, local_ip_address: str = "0.0.0.0", local_port: int = 9 + self, + *, + local_ip_address: str, + local_port: int, ): """ Class constructor. @@ -120,14 +123,24 @@ def service(self, *, connected_socket: Socket) -> None: @click.command() @click.option("--interface", default="tap7") -def cli(*, interface: str) -> None: +@click.option("--local-ip-address", default="0.0.0.0") +@click.option("--local-port", default=9, type=int) +def cli( + *, + interface: str, + local_ip_address: str, + local_port: int, +) -> None: """ Start PyTCP stack and stop it when user presses Ctrl-C. Run the TCP Discard service. """ stack = TcpIpStack(fd=initialize_tap(tap_name=interface)) - service = TcpDiscardService() + service = TcpDiscardService( + local_ip_address=local_ip_address, + local_port=local_port, + ) try: stack.start() diff --git a/examples/tcp_echo_service.py b/examples/tcp_echo_service.py index d1f6f479..ee7dbc80 100755 --- a/examples/tcp_echo_service.py +++ b/examples/tcp_echo_service.py @@ -54,7 +54,10 @@ class TcpEchoService(TcpService): """ def __init__( - self, *, local_ip_address: str = "0.0.0.0", local_port: int = 7 + self, + *, + local_ip_address: str, + local_port: int, ): """ Class constructor. @@ -131,14 +134,24 @@ def service(self, *, connected_socket: Socket) -> None: @click.command() @click.option("--interface", default="tap7") -def cli(*, interface: str) -> None: +@click.option("--local-ip-address", default="0.0.0.0") +@click.option("--local-port", default=7, type=int) +def cli( + *, + interface: str, + local_ip_address: str, + local_port: int, +) -> None: """ Start PyTCP stack and stop it when user presses Ctrl-C. Run the TCP Echo service. """ stack = TcpIpStack(fd=initialize_tap(tap_name=interface)) - service = TcpEchoService() + service = TcpEchoService( + local_ip_address=local_ip_address, + local_port=local_port, + ) try: stack.start() diff --git a/examples/udp_daytime_service.py b/examples/udp_daytime_service.py index 35ef4a17..905835d8 100755 --- a/examples/udp_daytime_service.py +++ b/examples/udp_daytime_service.py @@ -54,7 +54,10 @@ class UdpDaytimeService(UdpService): """ def __init__( - self, *, local_ip_address: str = "0.0.0.0", local_port: int = 13 + self, + *, + local_ip_address: str, + local_port: int, ): """ Class constructor. @@ -83,14 +86,24 @@ def service(self, *, listening_socket: Socket) -> None: @click.command() @click.option("--interface", default="tap7") -def cli(*, interface: str) -> None: +@click.option("--local-ip-address", default="0.0.0.0") +@click.option("--local-port", default=13, type=int) +def cli( + *, + interface: str, + local_ip_address: str, + local_port: int, +) -> None: """ Start PyTCP stack and stop it when user presses Ctrl-C. Run the UDP Daytime service. """ stack = TcpIpStack(fd=initialize_tap(tap_name=interface)) - service = UdpDaytimeService() + service = UdpDaytimeService( + local_ip_address=local_ip_address, + local_port=local_port, + ) try: stack.start() diff --git a/examples/udp_discard_service.py b/examples/udp_discard_service.py index ccf098cd..c0591d95 100755 --- a/examples/udp_discard_service.py +++ b/examples/udp_discard_service.py @@ -53,7 +53,10 @@ class UdpDiscardService(UdpService): """ def __init__( - self, *, local_ip_address: str = "0.0.0.0", local_port: int = 9 + self, + *, + local_ip_address: str, + local_port: int, ): """ Class constructor. @@ -80,14 +83,24 @@ def service(self, *, listening_socket: Socket) -> None: @click.command() @click.option("--interface", default="tap7") -def cli(*, interface: str) -> None: +@click.option("--local-ip-address", default="0.0.0.0") +@click.option("--local-port", default=9, type=int) +def cli( + *, + interface: str, + local_ip_address: str, + local_port: int, +) -> None: """ Start PyTCP stack and stop it when user presses Ctrl-C. Run the UDP Discard service. """ stack = TcpIpStack(fd=initialize_tap(tap_name=interface)) - service = UdpDiscardService() + service = UdpDiscardService( + local_ip_address=local_ip_address, + local_port=local_port, + ) try: stack.start() diff --git a/examples/udp_echo_service.py b/examples/udp_echo_service.py index 02a2aa13..8565a539 100755 --- a/examples/udp_echo_service.py +++ b/examples/udp_echo_service.py @@ -53,9 +53,7 @@ class UdpEchoService(UdpService): UDP Echo service support class. """ - def __init__( - self, *, local_ip_address: str = "0.0.0.0", local_port: int = 7 - ): + def __init__(self, *, local_ip_address: str = "::", local_port: int = 7): """ Class constructor. """ @@ -96,14 +94,19 @@ def service(self, *, listening_socket: Socket) -> None: @click.command() @click.option("--interface", default="tap7") -def cli(*, interface: str) -> None: +@click.option("--local-ip-address", default="0.0.0.0") +@click.option("--local-port", default=7, type=int) +def cli(*, interface: str, local_ip_address: str, local_port: int) -> None: """ Start PyTCP stack and stop it when user presses Ctrl-C. Run the UDP Echo service. """ stack = TcpIpStack(fd=initialize_tap(tap_name=interface)) - service = UdpEchoService() + service = UdpEchoService( + local_ip_address=local_ip_address, + local_port=local_port, + ) try: stack.start() diff --git a/pytcp/protocols/udp/fpa.py b/pytcp/protocols/udp/fpa.py index 3be17278..328efbf3 100755 --- a/pytcp/protocols/udp/fpa.py +++ b/pytcp/protocols/udp/fpa.py @@ -76,6 +76,7 @@ def __init__( self._plen = UDP_HEADER_LEN + len(self._data) self._hlen = UDP_HEADER_LEN self._dlen = len(self._data) + self._cksum = 0 def __len__(self) -> int: """