pete > courses > CS 315 Fall 26 > lecture 16: networking concepts


Lecture 16: networking concepts

Goals


we’ve already discussed signals, which are one way to perform interprocess communication (IPC)

but it’s a really constrained communication channel: one process can send to another process one of 32 different values and that’s it

that doesn’t allow for very eloquent or verbose conversations

(not least because the recipient of the signal doesn’t even know who it came from!)

and so we get to the final major topic of this course: TCP/IP networking, which is another form of interprocess communication

one that allows for much more interesting conversations


we’re going to stay relatively high level and concentrate on how applications use the networking-related system calls to make communication happen

in CSCI 0431 (Spring 2025!), we’ll actually understand how the system calls make it all work (in fact, you’ll write those system calls yourselves)

so a lot of questions that arise today may be met with "that’s beyond the scope of this course"

the goal for today is to see the abstractions and patterns; next time we’ll look at the code (system calls) that makes it happen


for our purposes, network communication will happen in the context of a connection

a connection is a conduit for communication between two processes

the two processes may be on the same computer

or they may be on different computers

or they may even be the same process

either process may send data to the process on the other end "along" or "over" the connection—that is, the connection is bidirectional

in any event, the "connection" abstraction is the central idea


another central idea is the socket, which is the name given to each end of a connection

(when we get to the nuts and bolts, we will actually use the socket(2) system call to ask the kernel to create a socket for us)

in fact, the set of system calls that "do" networking are collectively referred to as the "sockets interface" or the "BSD sockets interface"

"BSD" stands for Berkeley Software Distribution, which is the descendant of the original UNIX that was developed a UC Berkeley, in which the sockets interface was standardized


a potentially useful analogy is that of a phone call

once a call has been made and the recipient has picked up, the two people have made (the equivalent of) a connection

either person can talk and the other will hear

the two people represent the pair of sockets, one on each end of the connection


the phone-call analogy remains relevant when we discuss how a connection is created

one popular method to describe communication between two parties is the ladder diagram, in which parallel vertical lines are used to represent each party, the vertical axis represents time (earliest at the top) and arrows between the lines indicate communication between parties

therefore, connection-creation could be described like so:

Process X                                           Process Y

ask kernel for socket   |                       |
set socket to listen    |                       |
                        |                       |   ask kernel for socket
                        |                       |   tell socket to connect
                        |   connection request  |     to process X
                        | <-------------------- |   
receive request         |                       |
create connection       |                       |
send acknowledgement    |   acknowledgement     |
                        | --------------------> |   receive acknowledgement
                        |                       |   create connection

(both sides go through the "create connection" step because both kernels need to have a data structure that reflects its parameters)

after the connection has been created using those steps, Process X can send data to Process Y and vice versa


some terminology before we get to some technicalities

a process awaiting incoming connections, in this case Process X, is called a server

a process initiating a connection, in this case Process Y, is called a client

once the connection is established, however, the distinction evaporates, at least from the perspective of transmitting raw data

that is, the endpoints have equal power and responsibility over the connection: both can send data, both can receive data, both can terminate the connection

as we will see, the respective processes may use the connection to ask for things (like a client) or deliver things (like a server) but that’s above the level we’re discussing right now


this probably raises more questions than it answers, but for the time being, let’s focus on one in particular: how does Process Y identify Process X when it tells the socket to connect?

the way this stuff all works together means this is actually two questions:


on the Internet, a computer is identified by an Internet Protocol address (or "IP address")

you may have seen these "dotted quads"

for example, weathertop’s IP address is 144.233.20.202

it’s a dotted quad because it’s four number separated by dots

each of the four numbers can range from 0-255

so each is 8 bits, therefore an IP address is just a fancy way of describing a 32-bit value


that’s how we identify the computer, now we need a way to specify a particular process on that computer

we do this using a port number, which is just a 16-bit unsigned integer

with this in mind, we can refine the ladder diagram above

after Process X creates the socket and before it starts listening for incoming connections, it must ask to listen on a particular port

likewise, when Process Y initiates the connection, it must specify both the IP address of the computer on which Process X is running as well as the port number on which the latter is listening


the question is now: how does Process Y know the port number upon which Process X is listening for incoming connections?

half of the answer is that certain ports are set aside for certain purposes

the default port for requesting (unencrypted) web pages is 80

for encrypted web pages, we use port 443

the default port for ssh is 22

so the program that requests web pages (eg, firefox, chrome) or that makes ssh connections (eg, ssh, scp) has knowledge of this port number built in

the other half of the answer is that many network applications are written as client/server pairs

think of things like online computer games, where the same company is writing both the client and the server: they can hardcode the port numbers within both, and the only important thing is that both ends agree


let’s get back to IP addresses

the IP stands for Internet Protocol and are the rules that dictate what data gets sent back and forth between computers that results in communication happening

data is communicated in the form of packets: that is, small (historically and still quite often <1500) sequences of bytes that are delivered as a unit

so communication consists of series of packets flying back and forth between computers

you can think of them like messages written on little pieces of paper

they are delivered as a unit and don’t (usually) get split up


an interesting aspect of IP is the set of things it doesn’t do

in light of these, you might ask yourself why on Earth anybody would use IP


the fact of the matter is that very few applications use IP directly

they use other protocols that are built on top of IP, like TCP and UDP

this means that these other protocols send data from computer to computer using the rules of IP

but they add other information of their own that make up for its shortcomings


a couple very brief comments about UDP and TCP

both are built "on top of" IP

meaning they use IP to (unreliably) send packets from point A to point B

beyond this, UDP only adds the notion of ports, as discussed above

by contrast, TCP adds the notion of ports, too, but it also adds realiable, in-order delivery of data

most data on the Internet is probably sent using TCP (though there is quite a lot of use for UDP, which we’ll talk about in Networks)


but back to IP

for our purposes, every packet that flies over the Internet contains within it four pieces of data:

plus the content of the communication being sent, often called the payload

(and a bunch of other metadata, too, but that’s not important for this course)

those four pieces of information define a unique connection


except that my guess is you (and other normal users) very rarely—if ever—see and use IP addresses

you usually identify a website by name

for instance, in the URL bar of your browser, you would identify the webpage you want to view by entering something like this:

http://www.cs.middlebury.edu/~pjohnson/courses/f17-0315/

the "www.cs.middlebury.edu" part is what specifies which machine to connect to

except it isn’t an IP address!

and, honestly, it’s unreasonable to expect us pathetic humans to remember IP addresses for every site we might want to visit, so there exists a system that allows us to look them up by name

this is the domain name system (DNS)

when one wishes to translate a name like "www.cs.middlebury.edu" to an IP address, one sends a DNS request to a DNS server and receives back a DNS response that contains the corresponding IP address

(this leaves a chicken-and-egg problem: how do we know the IP address of the DNS server? answer to come in a moment)


with knowledge of the purpose of DNS, we can now better understand what the browser does when you type a URL into the address bar

consider the same URL as above

here is what the browser will do, reading left to right:


at this point, the client (your browser process) and the server (a process running on www.cs.middlebury.edu) can exchange data

but what data will result in you seeing the web page?

notably, TCP does not make any restrictions, requirements, or impose meaning on any of the data sent by or delivered to a process

it is entirely up to the sending and receiving processes to send the "right" data to achieve the application’s goals

fortunately, there is a protocol (a set of communication rules) for requesting and receiving web pages

this protocol is called HTTP, the Hypertext Transfer Protocol

so once the connection is established as described above, the client will send a request for the file ~pjohnson/courses/f17-0315/ using the rules of HTTP

and the server will respond with the corresponding data

(you can see this corresponding data if you use the "View Page Source" option in your browser: it’s written in a language called HTML: Hypertext Markup Language, which describes things like text and links and images and placement and all that fun stuff)


back to the question I deferred earlier: namely, how does a computer know which DNS server to use?

there’s a related question we haven’t touched on, which is how does a computer know what its IP address should be?

recall that IP addresses are geographic-ish (eg, all Middlebury computers have IP addresses that begin with 140.233)

so your computer’s IP address at Middlebury will start with 140.233, but it’s going to have a completely different IP address when you go home

what causes it to change?


the answer is that whenever a computer connects to a network, it sends out a request asking for its network configuration parameters

among these parameters is the IP address the computer should use and the IP address of the DNS server it should use

(DNS servers are almost always provided by the Internet server provider)

this request and response is performed according to the rules of DHCP, the dynamic host configuration protocol

when a computer connects to a network, it sends out a DHCP request

another machine on the network sends back a DHCP response, which contains information like the IP address the newly-attached computer should use, the DNS servers it should use, and a bunch of other information we’ll talk about in Networks


next time we’ll look at code

and, frankly, it won’t be terribly earth-shattering: we’ll see individual system calls to perform each step discussed today

and then we’ll be able to write to and read from connections

I say "read" and "write" intentionally, because the connections will, in fact, be identified by file descriptors!

this highlights the idea that files are the central UNIX abstraction

meaning that the original architects of UNIX decided that a lot of system activities could be viewed as operations on files; eg,

the fact that UNIX is still going strong (understatement) is a testament to the foresight and accuity of their choice of abstraction


flashback to architecture: what is endianness ?

eg, big-endian and little-endian

they describe how multi-byte integers are stored in memory

for example, if I want to store the value 1 as a 32-bit integer, it’s going to consume 4 consecutive memory addresses

one of those memory addresses will hold the byte 0x00, another will hold 0x00, a third will hold 0x00, and the last will hold 0x01

the question is: which address will hold which byte?

on a little-endian system, the least-significant byte will be at the lowest-numbered address

on a big-endian system, the least-significant byte will be at the highest-numbered address


why does this matter?

because the IP addresses and port numbers we discussed today are integers

and if a big-endian system sends the integer 0x00000001 to a little-endian system, the latter will interpret it as 0x01000000

thus, we need to standardize

and the decision was that all integers transmitted during network communications will be done so in big-endian format

if the sender or receiver is little-endian, it will need to translate on the fly

Last modified: