Master Networking Fundamentals: IP, TCP/UDP, Sockets, Compilation, and Shared Libraries
This comprehensive guide covers network layer protocols like IP and its address classes, transport layer details of TCP and UDP, socket programming basics, the full compilation and linking process, and the creation and usage of shared libraries and DLLs across Linux and Windows.
Network Layer
IP (Internet Protocol) provides addressing and routing for inter‑network communication, complemented by ARP, ICMP, and IGMP. IP addresses are divided into classes A, B, C, D, and E, each with specific network‑ID bits and address ranges.
Transport Layer
TCP
TCP is a connection‑oriented, reliable, byte‑stream protocol. It uses flags such as SYN, ACK, FIN, RST, URG, PSH to manage connections, ensure ordered delivery, and perform flow and congestion control. The three‑way handshake establishes a connection, while the four‑way termination gracefully closes it. TCP can suffer from sticky‑packet (粘包) issues, which are mitigated by fixed‑length messages, length‑prefixed headers, delimiters (e.g., \r\n), or higher‑level protocols.
UDP
UDP is a connectionless, best‑effort protocol that delivers datagrams without guarantees of order or reliability. It is suitable for real‑time applications such as VoIP and video conferencing.
Application Layer
Key application‑layer protocols include DNS (domain name resolution), FTP/TFTP (file transfer), TELNET (remote login), HTTP/HTTPS (web traffic), and SMTP (email). URLs follow the syntax scheme://host[:port]/path?query#fragment.
Socket Programming
The read(fd, buf, count) function reads data from a file descriptor, returning the number of bytes read or an error code. The write(fd, buf, count) function writes data, returning the number of bytes written or an error. In TCP socket communication, a client’s connect triggers the SYN, the server’s accept sends SYN‑ACK, and the client’s connect returns after sending ACK, completing the three‑way handshake. Closing a socket follows the four‑step FIN/ACK exchange.
Compilation and Linking
Source code undergoes preprocessing (handling #include, #define), compilation (lexical, syntax, semantic analysis, optimization, generating .s), assembly ( .o), and linking (address allocation, symbol resolution, relocation) to produce an executable or library. Target formats include PE/COFF on Windows, ELF on Linux/Unix, and Mach‑O on macOS. Symbol tables map names like main to addresses, and sections such as .text, .data, .bss, .rodata organize code and data.
Shared Libraries and DLLs
Linux shared objects ( libname.so.x.y.z) use version numbers to maintain ABI compatibility and are searched in /lib, /usr/lib, and directories listed in /etc/ld.so.conf. Environment variables like LD_LIBRARY_PATH and LD_PRELOAD influence loading. Windows DLLs export symbols via __declspec(dllexport) and are loaded with LoadLibrary, queried with GetProcAddress, and unloaded with FreeLibrary. The DllMain entry point handles process and thread attach/detach events.
Runtime Libraries
On Linux, program start proceeds from _start to __libc_start_main, which calls main and then exits via exit /_ exit. On Windows, mainCRTStartup initializes the CRT, processes command‑line arguments, calls main, and performs cleanup before returning to the OS.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
Liangxu Linux
Liangxu, a self‑taught IT professional now working as a Linux development engineer at a Fortune 500 multinational, shares extensive Linux knowledge—fundamentals, applications, tools, plus Git, databases, Raspberry Pi, etc. (Reply “Linux” to receive essential resources.)
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
