An implementations in rust of the different code samples in Beej's Guide to Network Programming
Warning
The first few exercises were implemented using libc which has a lot of unsafe code. The latter exercises were impemented using nix which is a safer alternative.
> cargo run -- --help
Usage: beej-rs <COMMAND>
Commands:
show-ip Section 5.1 "getaddrinfo() -- Prepare to Launch": Show IP addresses
stream-server Section 6.1 "A Simple Stream Server": TCP server
stream-client Section 6.2 "A Simple Stream Client": TCP client
socket-listener Section 6.3 "Datagram Sockets": UDP server. From now on, we use `nix` for c bindings, which is a little bit safer than `libc`
socket-talker Section 6.3 "Datagram Sockets": UDP client
poll-std-in Section 7.2 "poll() - Synchonous I/O Multiplexing": Poll stdin for input
poll-server Section 7.2 "poll() - Synchonous I/O Multiplexing": Poll server for input
select Section 7.3 "select()—Synchronous I/O Multiplexing, Old School": Wait for something to appear on standard input
select-server Section 7.3 "select()—Synchronous I/O Multiplexing, Old School": Simple multi-user chat server
broadcaster Section 7.7 "Broadcast Packets—Hello, World!": A UDP Client that broadcasts
help Print this message or the help of the given subcommand(s)
Options:
-h, --help Print help
-V, --version Print version
- Section 5.1 "getaddrinfo() -- Prepare to Launch"
- Section 6.1 "A Simple Stream Server"
- Section 6.2 "A Simple Stream Client"
- Section 6.3 "Datagram Sockets" UDP Server
- Bindings:
nix
- Protocol:
UDP
- listener.c -> listener.rs
- Bindings:
- Section 6.3 "Datagram Sockets" UDP Client
- Section 7.2 "poll() - Synchonous I/O Multiplexing"
- Section 7.2 "poll() - Synchonous I/O Multiplexing"
- Poll server for input
- Bindings:
nix
- Protocol:
TCP
- pollserver.c -> pollserver.rs
- Section 7.3 "select()—Synchronous I/O Multiplexing, Old School"
- Bindings:
nix
- select from stdin
- select.c -> select.rs
- Bindings:
- Section 7.3 "select()—Synchronous I/O Multiplexing, Old School"
- select server
- Bindings:
nix
- Protocol:
TCP
- selectserver.c -> selectserver.rs
- Section 7.7 "Broadcast Packets—Hello, World!"
- Bindings:
nix
- Protocol:
UDP
- broadcast client
- broadcaster.c -> broadcaster.rs
- Bindings:
Note: the design of the cli grew organically as I was reading the book, so it's quite incoherent