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.