What syscalls does a TCP server need?
The minimal useful TCP server must at least use the commands
tcp_listen_fd = socket(TCP): “OS, please create a TCP socket, and give me a file descriptor referencing it”.
bind(tcp_listen_fd, 9999): “OS, please point TCP port 9999 to the new TCP socket”.
listen(tcp_listen_fd): “OS, please start listening on the TCP port (9999)”.
tcp_conn_fd = accept(tcp_listen_fd): “OS, please put me to sleep until there’s a connection to the TCP port, then give me a file descriptor referencing the new TCP connection”.
bytes = recv(tcp_conn_fd): “OS, please put me to sleep until there are some bytes sent by the other end of the TCP connection, then give me some of those bytes”.
send(tcp_conn_fd, bytes): “OS, please send these bytes to the other end of the TCP connection”.
close(tcp_conn_fd): “OS, I’m done with this TCP connection. Close it and remove this file descriptor”.
close(tcp_listen_fd): “OS, I’m done listening for new TCP connections. Stop listening on the TCP port, and remove this file descriptor”.
More by Jim
- Your syntax highlighter is wrong
- Granddad died today
- The Three Ts of Time, Thought and Typing: measuring cost on the web
- I hate telephones
- The sorry state of OpenSSL usability
- The dots do matter: how to scam a Gmail user
- My parents are Flat-Earthers
- How Hacker News stays interesting
- Project C-43: the lost origins of asymmetric crypto
- The hacker hype cycle
- The inception bar: a new phishing method
- Time is running out to catch COVID-19
- A probabilistic pub quiz for nerds
- Smear phishing: a new Android vulnerability
Tagged . All content copyright James Fisher 2016. This post is not associated with my employer. Found an error? Edit this page.