13  i_net: Networking Abstraction

The i_net module handles DOOM’s networking: sockets, packet I/O, and command dispatch.


13.1 πŸ“„ File: i_net.h (lines 33–39)

Two networking functions: - I_InitNetwork: Initializes networking at startup
- I_NetCmd: Handles packet send/receive each frame


13.2 πŸ”§ Socket Setup and Packet Transmission

13.2.1 πŸ“„ File: i_net.c (lines 90–100)

Creates a UDP socket for player-to-player communication.


13.2.2 πŸ“„ File: i_net.c (lines 113–119)

Binds the socket to all network interfaces (INADDR_ANY) at a specified port.


13.2.3 πŸ“„ File: i_net.c (lines 132–139)

Converts values to network byte order before transmission (htonl, etc.).


13.2.4 πŸ“„ File: i_net.c (lines 149–152)

Uses sendto() to transmit packets to other DOOM nodes.


13.2.5 πŸ“„ File: i_net.c (lines 169–176)

Attempts to receive network packets using recvfrom().


13.2.6 πŸ“„ File: i_net.c (lines 188–194)

Checks sender IP against known addresses; if none match, drops the packet.


13.2.7 πŸ“„ File: i_net.c (lines 204–208)

Parses game state from received packets.


13.3 🌐 Local Host Address Detection

13.3.1 πŸ“„ File: i_net.c (lines 229–231)

Uses gethostname() to get local machine’s name.


13.3.2 πŸ“„ File: i_net.c (lines 233–237)

Resolves the hostname to an IP address with gethostbyname().


13.4 πŸ”„ I_InitNetwork and I_NetCmd

13.4.1 πŸ“„ File: i_net.c (lines 250–253)

Allocates doomcom to store shared network state.


13.4.2 πŸ“„ File: i_net.c (lines 255–259)

-dup command-line argument sets ticdup for packet duplication.


13.4.3 πŸ“„ File: i_net.c (lines 267–270)

-extratic enables backup tics in network packets.


13.4.4 πŸ“„ File: i_net.c (lines 272–276)

Allows overriding the default network port.


13.4.5 πŸ“„ File: i_net.c (lines 282–287)

If no multiplayer mode requested, configure single-player.


13.4.6 πŸ“„ File: i_net.c (lines 293–296)

Enables networking by setting netgame = true and assigning packet handlers.


13.4.7 πŸ“„ File: i_net.c (lines 298–300)

Initializes player number and number of nodes.


13.4.8 πŸ“„ File: i_net.c (lines 302–304)

Parses command-line arguments for host addresses.


13.4.9 πŸ“„ File: i_net.c (lines 305–309)

Parses IP address for target node.


13.4.10 πŸ“„ File: i_net.c (lines 312–316)

Resolves each hostname to an IP address.


13.4.11 πŸ“„ File: i_net.c (lines 327–331)

Creates separate sockets for sending and receiving.


13.5 πŸ“‘ I_NetCmd

13.5.1 πŸ“„ File: i_net.c (lines 345–347)

Unrecognized command triggers an error.


And that’s DOOM’s networking layer β€” abstracting UDP communication to enable smooth multiplayer gameplay.