Skip to content

Commit f4e588a

Browse files
committed
Cleaned up examples code
1 parent c0caed3 commit f4e588a

9 files changed

+27
-54
lines changed

examples/icmp_echo_client.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@
5757
IpAddress,
5858
MacAddress,
5959
)
60-
from pytcp import TcpIpStack, initialize_interface, stack
60+
from pytcp import stack
6161
from pytcp.protocols.icmp4.message.icmp4_message__echo_request import (
6262
Icmp4EchoRequestMessage,
6363
)
@@ -225,17 +225,14 @@ def cli(
225225
Start Icmp Echo client.
226226
"""
227227

228-
fd, mtu = initialize_interface(interface)
229-
230228
if ip6_host:
231229
ip6_host.gateway = ip6_gateway
232230

233231
if ip4_host:
234232
ip4_host.gateway = ip4_gateway
235233

236-
stack = TcpIpStack(
237-
fd=fd,
238-
mtu=mtu,
234+
stack.init(
235+
*stack.initialize_interface(interface),
239236
mac_address=mac_address,
240237
ip6_host=ip6_host,
241238
ip4_host=ip4_host,

examples/tcp_daytime_service.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@
5555
IpAddress,
5656
MacAddress,
5757
)
58-
from pytcp import TcpIpStack, initialize_interface
58+
from pytcp import stack
5959

6060
if TYPE_CHECKING:
6161
from pytcp.socket.socket import Socket
@@ -184,17 +184,14 @@ def cli(
184184
Start TCP Daytime service.
185185
"""
186186

187-
fd, mtu = initialize_interface(interface)
188-
189187
if ip6_host:
190188
ip6_host.gateway = ip6_gateway
191189

192190
if ip4_host:
193191
ip4_host.gateway = ip4_gateway
194192

195-
stack = TcpIpStack(
196-
fd=fd,
197-
mtu=mtu,
193+
stack.init(
194+
*stack.initialize_interface(interface),
198195
mac_address=mac_address,
199196
ip6_host=ip6_host,
200197
ip4_host=ip4_host,

examples/tcp_discard_service.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@
5454
IpAddress,
5555
MacAddress,
5656
)
57-
from pytcp import TcpIpStack, initialize_interface
57+
from pytcp import stack
5858

5959
if TYPE_CHECKING:
6060
from pytcp.socket.socket import Socket
@@ -190,17 +190,14 @@ def cli(
190190
Start TCP Daytime service.
191191
"""
192192

193-
fd, mtu = initialize_interface(interface)
194-
195193
if ip6_host:
196194
ip6_host.gateway = ip6_gateway
197195

198196
if ip4_host:
199197
ip4_host.gateway = ip4_gateway
200198

201-
stack = TcpIpStack(
202-
fd=fd,
203-
mtu=mtu,
199+
stack.init(
200+
*stack.initialize_interface(interface),
204201
mac_address=mac_address,
205202
ip6_host=ip6_host,
206203
ip4_host=ip4_host,

examples/tcp_echo_client.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@
5656
IpAddress,
5757
MacAddress,
5858
)
59-
from pytcp import TcpIpStack, initialize_interface
59+
from pytcp import stack
6060

6161

6262
class TcpEchoClient(Client):
@@ -202,17 +202,14 @@ def cli(
202202
Start TCP Echo client.
203203
"""
204204

205-
fd, mtu = initialize_interface(interface)
206-
207205
if ip6_host:
208206
ip6_host.gateway = ip6_gateway
209207

210208
if ip4_host:
211209
ip4_host.gateway = ip4_gateway
212210

213-
stack = TcpIpStack(
214-
fd=fd,
215-
mtu=mtu,
211+
stack.init(
212+
*stack.initialize_interface(interface),
216213
mac_address=mac_address,
217214
ip6_host=ip6_host,
218215
ip4_host=ip4_host,

examples/tcp_echo_service.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@
5555
IpAddress,
5656
MacAddress,
5757
)
58-
from pytcp import TcpIpStack, initialize_interface
58+
from pytcp import stack
5959

6060
if TYPE_CHECKING:
6161
from pytcp.socket.socket import Socket
@@ -200,17 +200,14 @@ def cli(
200200
Start TCP Echo service.
201201
"""
202202

203-
fd, mtu = initialize_interface(interface)
204-
205203
if ip6_host:
206204
ip6_host.gateway = ip6_gateway
207205

208206
if ip4_host:
209207
ip4_host.gateway = ip4_gateway
210208

211-
stack = TcpIpStack(
212-
fd=fd,
213-
mtu=mtu,
209+
stack.init(
210+
*stack.initialize_interface(interface),
214211
mac_address=mac_address,
215212
ip6_host=ip6_host,
216213
ip4_host=ip4_host,

examples/udp_daytime_service.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@
5555
IpAddress,
5656
MacAddress,
5757
)
58-
from pytcp import TcpIpStack, initialize_interface
58+
from pytcp import stack
5959

6060
if TYPE_CHECKING:
6161
from pytcp.socket.socket import Socket
@@ -150,17 +150,14 @@ def cli(
150150
Start UDP Daytime service.
151151
"""
152152

153-
fd, mtu = initialize_interface(interface)
154-
155153
if ip6_host:
156154
ip6_host.gateway = ip6_gateway
157155

158156
if ip4_host:
159157
ip4_host.gateway = ip4_gateway
160158

161-
stack = TcpIpStack(
162-
fd=fd,
163-
mtu=mtu,
159+
stack.init(
160+
*stack.initialize_interface(interface),
164161
mac_address=mac_address,
165162
ip6_host=ip6_host,
166163
ip4_host=ip4_host,

examples/udp_discard_service.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@
5454
IpAddress,
5555
MacAddress,
5656
)
57-
from pytcp import TcpIpStack, initialize_interface
57+
from pytcp import stack
5858

5959
if TYPE_CHECKING:
6060
from pytcp.socket.socket import Socket
@@ -147,17 +147,14 @@ def cli(
147147
Start UDP Discard service.
148148
"""
149149

150-
fd, mtu = initialize_interface(interface)
151-
152150
if ip6_host:
153151
ip6_host.gateway = ip6_gateway
154152

155153
if ip4_host:
156154
ip4_host.gateway = ip4_gateway
157155

158-
stack = TcpIpStack(
159-
fd=fd,
160-
mtu=mtu,
156+
stack.init(
157+
*stack.initialize_interface(interface),
161158
mac_address=mac_address,
162159
ip6_host=ip6_host,
163160
ip4_host=ip4_host,

examples/udp_echo_client.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@
5555
IpAddress,
5656
MacAddress,
5757
)
58-
from pytcp import TcpIpStack, initialize_interface
58+
from pytcp import stack
5959

6060

6161
class UdpEchoClient(Client):
@@ -183,17 +183,14 @@ def cli(
183183
Start UDP Echo client.
184184
"""
185185

186-
fd, mtu = initialize_interface(interface)
187-
188186
if ip6_host:
189187
ip6_host.gateway = ip6_gateway
190188

191189
if ip4_host:
192190
ip4_host.gateway = ip4_gateway
193191

194-
stack = TcpIpStack(
195-
fd=fd,
196-
mtu=mtu,
192+
stack.init(
193+
*stack.initialize_interface(interface),
197194
mac_address=mac_address,
198195
ip6_host=ip6_host,
199196
ip4_host=ip4_host,

examples/udp_echo_service.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@
5555
IpAddress,
5656
MacAddress,
5757
)
58-
from pytcp import TcpIpStack, initialize_interface
58+
from pytcp import stack
5959

6060
if TYPE_CHECKING:
6161
from pytcp.socket.socket import Socket
@@ -163,17 +163,14 @@ def cli(
163163
Start TCP Echo service.
164164
"""
165165

166-
fd, mtu = initialize_interface(interface)
167-
168166
if ip6_host:
169167
ip6_host.gateway = ip6_gateway
170168

171169
if ip4_host:
172170
ip4_host.gateway = ip4_gateway
173171

174-
stack = TcpIpStack(
175-
fd=fd,
176-
mtu=mtu,
172+
stack.init(
173+
*stack.initialize_interface(interface),
177174
mac_address=mac_address,
178175
ip6_host=ip6_host,
179176
ip4_host=ip4_host,

0 commit comments

Comments
 (0)