The Big Picture: Layers from Top to Bottom
Windows does not handle networking in one lump. It uses layers, like floors of a building. Each layer does one job and only talks to the floor directly above and below. A stack is simply this pile of layers.
The previous chapter showed the idea of layers (application, transport, internet, link). This section shows the real Windows files that fill those layers.
2.1 Layered Architecture (Application → Winsock → AFD → TCP/IP → NDIS → Miniport → NIC)
USER MODE (normal programs, limited power)
┌─────────────────────────────────────────────┐
│ Application (browser, game, Outlook ...) │
├─────────────────────────────────────────────┤
│ Winsock API (ws2_32.dll) │
└─────────────────────┬───────────────────────┘
══════════════════════╪═══ system call: user mode -> kernel mode
KERNEL MODE (the OS core, full power)
┌─────────────────────┴───────────────────────┐
│ Winsock kernel driver (afd.sys) │
├─────────────────────────────────────────────┤
│ TCP/IP protocol driver (tcpip.sys) │
├─────────────────────────────────────────────┤
│ NDIS (ndis.sys) │
├─────────────────────────────────────────────┤
│ Miniport driver (Intel, Realtek, Wi-Fi ...) │
└─────────────────────┬───────────────────────┘
│
┌─────┴─────┐
│ NIC (hw) │
└───────────┘
What each layer does:
| Layer | File | Job in plain words |
|---|---|---|
| Application | chrome.exe, etc. | The program that wants to use the network |
| Winsock API | ws2_32.dll | The "menu" of network calls an app can use: connect, send, receive |
| AFD | afd.sys | Ancillary Function Driver for Winsock. The kernel side of Winsock. Keeps each socket's buffers and state and passes work to the protocol driver |
| TCP/IP driver | tcpip.sys | Builds and reads TCP, UDP, IP, ICMP and neighbor (ARP) messages. The real "brain" of networking |
| NDIS | ndis.sys | Standard layer between the protocols and the hardware drivers (Section 1) |
| Miniport | vendor .sys file | Talks to the exact NIC |
| NIC | hardware | Sends and receives the bits |
User mode and kernel mode. Windows has two "worlds". In user mode, normal programs run with limited power, so a crash cannot take down the whole PC. In kernel mode, the operating system core and drivers run with full power over the hardware. A program crosses the line with a system call (a controlled request to the kernel). In the diagram, the double line is that border. Everything from AFD downward is kernel code. (See Chapter 12 for more on these two worlds.)
Notice: A packet never goes "straight from the app to the wire". It passes through several layers one after another, and the same layers work in reverse for incoming data.
2.2 How Data Moves Down and Up
Suppose a program sends a short message to a server. This is the simplified trip:
- The app calls
send()in Winsock (ws2_32.dll). - Winsock passes the request to AFD in the kernel.
- AFD hands the data to tcpip.sys. TCP cuts it into segments and adds a TCP header (port numbers, sequence numbers). Then IP adds its header (source and destination IP address). This is the encapsulation from the previous chapter.
- tcpip.sys finds the next hop (Section 9: the routing table) and its MAC address (Section 4: the neighbor cache).
- The finished packet goes to NDIS, which gives it to the miniport driver.
- The miniport places the frame (the packet plus an Ethernet or Wi-Fi header) in a buffer and tells the NIC to send it by DMA.
Receiving is the same trip upward: NIC, interrupt, miniport, NDIS, tcpip.sys (checks headers, rebuilds the data stream), AFD, Winsock, and finally the application.
2.3 Where the Firewall Hooks In: WFP
What it is: The Windows Filtering Platform (WFP) is a set of hooks (called layers) built into the networking stack. At each hook, a filter can look at a packet or a connection and decide: allow, block, or hand it to another component.
Think of WFP as security checkpoints at several doors inside the building, not one guard at the front gate.
Application
│
┌────────┴────────┐
│ Winsock / AFD │ ◄── WFP hooks: "may this program connect or listen?"
├─────────────────┤
│ tcpip.sys │ ◄── WFP hooks: transport and network layers
├─────────────────┤ (inspect and filter packets)
│ NDIS │
├─────────────────┤
│ Miniport │
└─────────────────┘
The Windows Firewall (Section 7) is built on WFP. Other security products and VPN software can add their own WFP filters too. The exact layers and their names are a deep topic. For this course, remember the idea: filtering happens inside the kernel, in the path of every packet.
2.4 Seeing the Stack in Action
| Tool | What it shows |
|---|---|
netstat -ano | Every connection and listening port with its PID (process ID) |
| Resource Monitor → Network tab | Which program talks to which address, with live speeds |
| Task Manager → Performance → Ethernet / Wi-Fi | Live adapter graph and link speed |
| Device Manager → View → Show hidden devices | Hidden driver entries, some networking related |
Windows tip: In Task Manager → Details, right-click the column header, choose Select columns and add PID. Then match a PID from
netstat -anoto see which program owns a connection.
Hedge: Newer Windows versions rearrange some internal details, and some protocols (for example QUIC, which browsers run over UDP) are partly handled by other components. The big picture above stays the same.
Summary
| Term | Plain meaning |
|---|---|
| Stack | A pile of software layers, each doing one job |
ws2_32.dll | The Winsock library an app calls (user mode) |
afd.sys | Kernel side of Winsock; owns each socket's state |
tcpip.sys | The kernel TCP/IP protocol driver |
ndis.sys | The standard layer between protocols and miniports |
| User mode / kernel mode | Limited-power world for apps / full-power world for the OS |
| WFP | Filtering hooks inside the stack; the firewall uses them |
| PID | The number that identifies a running process |