things that I marked with (?) indicate statements that I still have doubts about
Big thanks to sir @ammarfaizi2 for any support and help 😁
and other members on GNU/Weeb!
- So far, this program not stable and won't work properly on windows platform, known issue are:
- Well known bug on linux platform:
- [client] need to figure out how to copy buffer from stdin to stdout when '\r' printed
- I/O Multiplexing
- TIL windows cannot connect to 0.0.0.0 while linux can do it, on windows, address 0.0.0.0 only useful for listen on all interface
- good article about make and Makefile script
- use
SERVER_ADDR=0.0.0.0 make
to override default server address, also - sock_stream sock_dgram sock_raw is a part of network socket types
- setiap protokol seperti (IP_ICMP) mempunyai struktur data, fungsionalitas dan usecase masing-masing
- man 2 untuk syscall, man 3 untuk library, lihat lengkapnya pada command
man man
- endian = bytes order, tidak digunakan untuk single byte
- network always use big endian, see network byte ordering rfc 1700, and the note
- raw tcp client: nc program
- strace to debug syscall
- netstat to see network connection statistic, e.g list used port
- manage process in a single terminal session:
- monitoring process
- use command
jobs
to list related information
- use command
- maintain process
- use
command &
= move process to background - use command
fg
= move process to foreground - use command
bg
= move process to background, re-run freezed program
- use
- monitoring process
^C interrupt, this signal can be adjusted according to the way program is programmed
^Z stop / freeze program
^D EOF
see man sigaction
for more info
- handle multiple client
- broadcast from one to other client
- flexible array member or dynamic data on variable need to be stored as pointer and cannot stored in stack therefore use malloc
- selain untuk optimasi, alignment memory needed in order to fit some structure data, and can be used properly
- jika tidak di-align dengan benar dapat menyebabkan buffer overflow
- salah satu cara meng-align nya adalah dengan menggunakan
__attribute__((__packed__))
- buffering itu buat menghemat resource dan system call (?)
auto flush occurs when: new line/lf, get input: fgets
| getchar
| etc...
, and exit
here's some example:
printf("> "); // by default line-buffered, so you need to add \n to automatic trigger flush
fflush(stdout); // or force flush fix the issue if the auto flush not performed
while (1);
file descriptor is unique identifier that hold information related to I/O operation, for example tcp socket and some widely-known standard I/O stream and FD: stdin, stdout, and stderr and the preprocessor symbols or predefined constant in macro: STDIN_FILENO
, STDOUT_FILENO
, STDERR_FILENO
respectively
Diagram that shows variant of I/O device:
image from: What does "address space" means when talking about IO devices?
also see the File descriptor from wikipedia and the Linux_System_Programming-man7 book page 3-4
- buffer: some data that was held somewhere in memory
- I/O stream1: wide-terms used for represents an input source or an output destination (?)
- flush: clear buffer and stream it to the specified FD, e.g
printf
tidak akan ditampilkan jika belum di-flush ke stdout dan masih disimpan dalam bentuk buffer - buffering mode on stream1: there's three types of buffering mode, unbuffered, line-buffered, and fullbuffered, each of mode have predefined constant in macro:
_IONBF
,_IOLBF
, and_IOFBF
respectively, seeman setvbuf
for the details of the behaviour - also
struct FILE *
is refer to stream and doesn't literally refer to the actual file - There's high-level and low-level interface2:
- select (old but implemented on all system)
- poll posix-only (included bsd)
- some event on a file descriptor: documented on
man 2 poll
- some event on a file descriptor: documented on
- epoll linux | queu bsd | iocp windows
- io_uring linux
note: I want someone who reads this to validate and verify my statement, so feel free to open a pull request if you discover any misconcept, misinterpretation, or misleading information
- usually in the network domain, we often use dynamic allocated variable to hold flexible array, cuz it will be very wasteful if the variable are fixed-size since it will force the size to be fixed even if the data is small, and fill the rest with null char as a padding (?)
- on the network, you are passing the actual value or data, not the reference of memory address XD
- why always passing the size as additional information in the member struct? I think it's like a trade-off.
- maybe the analogy is more or less like, Why bother to execute a bunch of instructions instead of passing additional information that is not so large (does this mean for the sake of efficiency?)
- sizeof means the size of a defined data structure on a variable, not the size of the variable's value itself. Why? You might ask, That's how data structure and memory work (?)
- and not to confuse with strlen, which only applied to strings in order to count the amount of char.
- How does the program interpret the network data? especially in terms of memory. I curious how to debug this process with gdb but didn't have any clue to get started :(
- this curiousity comes from the buffer overflow vuln on the server
- I think the highlighted thing in this context would be:
- the way processors read/fetch data, how operator and operand are used at the machine-code (assembly) level
- how could packed and aligned memory affect the program behavior?