Sockets – Fundamentals of TCP/IP Networks Internets and TCP/IP Introduction

 

Chapter 58: Sockets – Fundamentals of TCP/IP Networks
Part 1 of 3  |  Internets and TCP/IP Introduction
📡 Topic: Internets
🌐 Protocol: TCP/IP
📖 Source: TLPI Ch. 58

Before you can write socket programs that talk over a network, you need to understand what a network actually is and how TCP/IP organizes communication. This part lays that foundation — covering what an internet is, how TCP/IP became the dominant protocol suite, what a router does, and what RFC documents are.

Key Terms
internet (lowercase) Internet (uppercase) subnet / subnetwork router multihomed host TCP/IP ARPANET DARPA RFC protocol suite 4.2BSD

1. What is an Internet?

The word internet (lowercase i) means an internetwork — a system that connects different computer networks together so that every host on every connected network can communicate with every other host.

Think of it like this: your home has a local network (your Wi-Fi). Your office has its own network. An internet is what bridges those separate networks into one big reachable space.

The individual networks inside an internet are called subnetworks or subnets.

What an Internet Looks Like
Network A
Host 1
Host 2
Router
Network B
Host 3
Host 4
Host 1 on Network A can talk to Host 4 on Network B through the Router

The key goal of an internet is to hide the differences between physical networks. Whether Network A uses Ethernet cables and Network B uses fiber optic links, the internet presents a single, unified addressing format to every host. You do not need to know what the lower-level network looks like; you just use an address.

Internet (uppercase I) refers specifically to the global TCP/IP internet — the one connecting billions of devices worldwide.

2. History of TCP/IP

TCP/IP did not appear overnight. It grew out of a US government research project.

TCP/IP History Timeline
1960s
ARPA (US Dept. of Defense agency) sponsors research into a fault-tolerant network — ARPANET
1970s
A new family of protocols is designed for ARPANET — the DARPA Internet Protocol Suite (TCP/IP)
1983
First widespread TCP/IP implementation ships with 4.2BSD (Berkeley Software Distribution Unix)
Later
Linux TCP/IP stack written from scratch, using BSD behavior as reference. Many other stacks derived from BSD code.

ARPA became DARPA (adding “Defense”). The protocol suite is formally called the DARPA Internet Protocol Suite, but everyone calls it TCP/IP — named after its two most important protocols: Transmission Control Protocol (TCP) and Internet Protocol (IP).

TCP/IP won the competition against proprietary networking protocols (like Novell’s IPX and IBM’s SNA) and became the universal standard. Today every networked device speaks TCP/IP.

3. Router and Multihomed Host

A router is a machine whose job is to connect two or more subnets and move packets between them. It must understand the internet-layer protocol (IP) and also understand the data-link-layer protocol of each subnet it connects.

A router has one network interface per subnet it connects. Each interface has a separate address on that subnet.

Router with Two Interfaces
Subnet 1
pukaki
rotoiti
eth0: 10.0.1.1
tekapo
(Router)
eth1: 10.0.2.1
Subnet 2
wakatipu
wanaka
tekapo has one IP address per subnet — it is a multihomed host

The general term multihomed host means any host with more than one network interface — not necessarily a router. A server connected to both an internal LAN and an external network is multihomed. A router is just a multihomed host that also forwards packets from one subnet to another.

Property Multihomed Host Router
Multiple interfaces Yes Yes
Multiple IP addresses Yes Yes
Forwards packets between subnets No (usually) Yes (its purpose)
Example A server with eth0 + eth1 tekapo connecting Subnet 1 and 2

4. What Are RFC Documents?

RFC stands for Request for Comments. Every TCP/IP protocol is formally defined in an RFC document published by the IETF (Internet Engineering Task Force).

Despite the modest name (“request for comments”), RFC documents are the official standards for internet protocols. They describe exactly how TCP, UDP, IP, ICMP, and every other protocol must behave. Implementations that follow the RFC are interoperable with each other.

Why RFCs matter for socket programming:
When you write a socket application on Linux and it communicates correctly with a Windows or BSD server, it works because both sides follow the same RFC — the same agreed-upon rules for how data must be formatted and exchanged.

5. Practical: Check Network Interfaces and Routing

You can explore the internet concepts from this section directly in Linux using standard command-line tools and C code.

List network interfaces and their details:

/* List interfaces using getifaddrs() — POSIX */
#include <stdio.h>
#include <ifaddrs.h>
#include <arpa/inet.h>
#include <netinet/in.h>
#include <string.h>

int main(void)
{
    struct ifaddrs *ifap, *ifa;

    if (getifaddrs(&ifap) == -1) {
        perror("getifaddrs");
        return 1;
    }

    printf("%-15s %-8s %s\n", "Interface", "Family", "Address");
    printf("%-15s %-8s %s\n", "---------", "------", "-------");

    for (ifa = ifap; ifa != NULL; ifa = ifa->ifa_next) {
        if (ifa->ifa_addr == NULL)
            continue;

        int family = ifa->ifa_addr->sa_family;

        if (family == AF_INET) {   /* IPv4 */
            char addr[INET_ADDRSTRLEN];
            struct sockaddr_in *sin = (struct sockaddr_in *)ifa->ifa_addr;
            inet_ntop(AF_INET, &sin->sin_addr, addr, sizeof(addr));
            printf("%-15s %-8s %s\n", ifa->ifa_name, "IPv4", addr);
        }
    }

    freeifaddrs(ifap);
    return 0;
}

Compile and run:

gcc -o list_iface list_iface.c
./list_iface

# Typical output on a Linux machine:
# Interface       Family   Address
# ---------       ------   -------
# lo              IPv4     127.0.0.1
# eth0            IPv4     192.168.1.10
# wlan0           IPv4     192.168.1.25

Shell commands to explore networking concepts:

# Show all interfaces and their IP addresses
ip addr show

# Show the routing table (which router handles which subnet)
ip route show

# Show interfaces with MTU (useful for Data-Link Layer section)
netstat -i

# Trace the path packets take through routers (traceroute = router visibility)
traceroute www.google.com

# Check if a host is reachable (uses ICMP)
ping -c 3 8.8.8.8

# Show ARP table (hardware addresses mapped to IP addresses)
arp -n

Check if your machine is multihomed:

#include <stdio.h>
#include <ifaddrs.h>
#include <netinet/in.h>

int main(void)
{
    struct ifaddrs *ifap, *ifa;
    int count = 0;

    getifaddrs(&ifap);
    for (ifa = ifap; ifa != NULL; ifa = ifa->ifa_next) {
        if (ifa->ifa_addr == NULL) continue;
        if (ifa->ifa_addr->sa_family == AF_INET) {
            /* Skip loopback */
            if (strncmp(ifa->ifa_name, "lo", 2) != 0)
                count++;
        }
    }
    freeifaddrs(ifap);

    if (count > 1)
        printf("This host is MULTIHOMED: %d IPv4 interfaces\n", count);
    else
        printf("Single interface host: %d IPv4 interface\n", count);

    return 0;
}

Interview Questions
Q1. What is the difference between an internet (lowercase) and the Internet (uppercase)?
Answer: An internet (lowercase) is any collection of interconnected networks — it is a generic term. The Internet (uppercase) specifically refers to the global TCP/IP internet that connects billions of devices worldwide.
Q2. What is a subnetwork? How does it relate to an internet?
Answer: A subnetwork (or subnet) is one of the individual networks that compose an internet. An internet connects multiple subnets; a subnet is the building block. For example, your office LAN is one subnet; your cloud VPC is another. An internet is what bridges them.
Q3. What is a multihomed host? Is every router a multihomed host?
Answer: A multihomed host is any host with more than one network interface, giving it an IP address on each connected subnet. Yes, every router is a multihomed host, but not every multihomed host is a router. The distinction is forwarding: a router actively forwards packets between subnets, while a regular multihomed host does not.
Q4. Where did TCP/IP come from? Why is it called TCP/IP and not just IP?
Answer: TCP/IP grew out of the ARPANET project funded by DARPA (US Dept. of Defense) in the 1970s. It is called TCP/IP because TCP (Transmission Control Protocol) is the most widely used transport-layer protocol layered on top of IP (Internet Protocol). The name highlights both the transport and network layers.
Q5. What was 4.2BSD and why is it significant to Linux networking?
Answer: 4.2BSD (1983) was the first widespread Unix distribution to include a complete TCP/IP implementation. Many later TCP/IP stacks (including those in BSD variants) were derived directly from this code. Linux’s TCP/IP stack was written from scratch but uses BSD behavior as its reference standard, ensuring compatibility.
Q6. What is an RFC and why does it matter for socket programming?
Answer: RFC (Request for Comments) documents are the official specifications published by the IETF for internet protocols. Every protocol in the TCP/IP suite is defined in an RFC. They matter for socket programming because any two implementations that correctly follow the same RFC can communicate with each other, regardless of the operating system or hardware.
Q7. How does an internet hide the differences between physical networks?
Answer: An internet uses a uniform addressing scheme (IP addresses) and a common protocol (IP) so that applications do not need to know whether the underlying physical medium is Ethernet, Wi-Fi, fiber, or anything else. The protocol layers abstract the physical differences, presenting a single unified network to all hosts.

Leave a Reply

Your email address will not be published. Required fields are marked *