aboutsummaryrefslogtreecommitdiff
path: root/examples/std/README.md
diff options
context:
space:
mode:
Diffstat (limited to 'examples/std/README.md')
-rw-r--r--examples/std/README.md115
1 files changed, 111 insertions, 4 deletions
diff --git a/examples/std/README.md b/examples/std/README.md
index dcc152fc2..5d7c384ae 100644
--- a/examples/std/README.md
+++ b/examples/std/README.md
@@ -1,19 +1,126 @@
1 1
2## Running the `embassy-net` examples 2## Running the `embassy-net` examples
3 3
4First, create the tap99 interface. (The number was chosen to 4To run `net`, `tcp_accept`, `net_udp` examples you will need a tap interface. Before running any example, create the tap99 interface. (The number was chosen to
5hopefully not collide with anything.) You only need to do 5hopefully not collide with anything.) You only need to do
6this once. 6this once every time you reboot your computer.
7 7
8```sh 8```sh
9sudo sh tap.sh 9sudo sh tap.sh
10``` 10```
11 11
12Second, have something listening there. For example `nc -lp 8000` 12### `net` example
13
14For this example, you need to have something listening in the correct port. For example `nc -lp 8000`.
13 15
14Then run the example located in the `examples` folder: 16Then run the example located in the `examples` folder:
15 17
16```sh 18```sh
17cd $EMBASSY_ROOT/examples/std/ 19cd $EMBASSY_ROOT/examples/std/
18sudo cargo run --bin net -- --tap tap99 --static-ip 20cargo run --bin net -- --tap tap99 --static-ip
21```
22### `tcp_accept` example
23
24This example listen for a tcp connection.
25
26First run the example located in the `examples` folder:
27
28```sh
29cd $EMBASSY_ROOT/examples/std/
30cargo run --bin tcp_accept -- --tap tap99 --static-ip
31```
32
33Then open a connection to the port. For example `nc 192.168.69.2 9999`.
34
35### `net_udp` example
36
37This example listen for a udp connection.
38
39First run the example located in the `examples` folder:
40
41```sh
42cd $EMBASSY_ROOT/examples/std/
43cargo run --bin net_udp -- --tap tap99 --static-ip
44```
45
46Then open a connection to the port. For example `nc -u 192.168.69.2 9400`.
47
48### `net_dns` example
49
50This example queries a `DNS` for the IP address of `www.example.com`.
51
52In order to achieve this, the `tap99` interface requires configuring tap99 as a gateway device temporarily.
53
54For example, in Ubuntu you can do this by:
55
561. Identifying your default route device. In the next example `eth0`
57
58```sh
59ip r | grep "default"
60default via 192.168.2.1 dev eth0 proto kernel metric 35
61```
62
632. Enabling temporarily IP Forwarding:
64
65```sh
66sudo sysctl -w net.ipv4.ip_forward=1
67```
68
693. Configuring NAT to mascarade traffic from `tap99` to `eth0`
70
71```sh
72sudo iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE
73sudo iptables -A FORWARD -i tap99 -j ACCEPT
74sudo iptables -A FORWARD -m conntrack --ctstate RELATED,ESTABLISHED -j ACCEPT
75```
76
774. Then you can run the example located in the `examples` folder:
78
79```sh
80cd $EMBASSY_ROOT/examples/std/
81cargo run --bin net_dns -- --tap tap99 --static-ip
82```
83
84### `net_ppp` example
85
86This example establish a Point-to-Point Protocol (PPP) connection that can be used, for example, for connecting to internet through a 4G modem via a serial channel.
87
88The example creates a PPP bridge over a virtual serial channel between `pty1` and `pty2` for the example code and a PPP server running on the same computer.
89
90To run this example you will need:
91- ppp (pppd server)
92- socat (socket CAT)
93
94To run the examples you may follow the next steps:
95
961. Save the PPP server configuration:
97```sh
98sudo sh -c 'echo "myuser $(hostname) mypass 192.168.7.10" >> /etc/ppp/pap-secrets'
99```
100
1012. Create a files `pty1` and `pty2` and link them
102```sh
103cd $EMBASSY_ROOT/examples/std/
104socat -v -x PTY,link=pty1,rawer PTY,link=pty2,rawer
105```
106
1073. open a second terminal and start the PPP server:
108```sh
109cd $EMBASSY_ROOT/examples/std/
110sudo pppd $PWD/pty1 115200 192.168.7.1: ms-dns 8.8.4.4 ms-dns 8.8.8.8 nodetach debug local persist silent
111```
112
1134. Open a third terminal and run the example
114```sh
115cd $EMBASSY_ROOT/examples/std/
116RUST_LOG=trace cargo run --bin net_ppp -- --device pty2
117```
1185. Observe the output in the second and third terminal
1196. Open one last terminal to interact with `net_ppp` example through the PPP connection
120```sh
121# ping the net_ppp client
122ping 192.168.7.10
123# open an tcp connection
124nc 192.168.7.10 1234
125# Type anything and observe the output in the different terminals
19``` 126```