






















Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
A part of the cs 241 spring 2007 course notes focusing on tcp programming and tcp/ip protocol issues. It covers socket creation using the socket function, bind function, and connection setup for sock_stream. The document also discusses the listen function, accept function, and connect call for sending and receiving data. Additionally, it touches upon the internet protocol and tcp/ip protocol architecture.
Typology: Study notes
1 / 30
This page cannot be seen from the preview
Don't miss anything!























CS 241 Spring 2007System Programming
We will have LMP3 Quiz We will have guest lecture – speaker from Mathematica talkingabout challenges of Mathematica Development on Different OSPlatforms (UNIX, MAC, Linux, Windows). ^
s: socket descriptor, an integer (like a file-handle) domain: integer, communication domain^ e.g., AF_INET typically used (Internet domain) type: communication type^ SOCK_STREAM: reliable, 2-way, connection-based service^ SOCK_DGRAM: unreliable, connectionless,^ other values: need root permission, rarely used, or obsolete protocol: specifies protocol (see file /etc/protocols for a list ofoptions) - usually set to 0 (IP)
determined by the address family (domain). For AF_INET it is a struct sockaddr_in Socket structure is defined in netinet/in.h Socket structure has at least the followingmembers in network byte order:
sa_family_t sin_family; in_port_t sin_port; /* Host Port Number / struct in_addr sin_addr; / IP Address*/
passive: waits for an active participant to request connection active: initiates connection request to passive side
telephone
-^ The acceptedconnection is on a newsocket•^ The old socketcontinues to listen forother active participants
l-sock a-sock-
a-sock-
Accept Function A^ blocking
call Extracts the first connection on the queue of pending connections creates a new socket with the same socket type protocol and addressfamily as the specified socket allocates a new file descriptor for that socket Returns communication file descriptor if successful or -1 otherwise. Server fills the second parameter with information about the client You fill in the size of the buffer used for the second parameter and on
return the third parameter contains the actual size needed tocontain this information. #include <sys/socket.h> int accept (int socket, struct sockaddr *restrict address,socklen_t *restrict address_len);
connect is
blocking
be closed: status = close(s);
Closing a socket
applications Connection – temporary logical association
between two entities in different systems TCP Header
HeaderLength
Reserved
Flags
Window
Checksum
Urgent Pointer
Options + Padding
32 bit length
Version
IHL
DS
ECN^
Total Length
Identification
Flags^
Fragment Offset
Time to Live
Protocol
Header Checksum
Source AddressDestination AddressOptions + Padding
message to TCP over the port 3 TCP hands the message down to IP with
instructions to send it to host B, port 2 IP hands message the message down to MAC
layer (Network Access Protocol – e.g.,Ethernet) with instructions to send it to router J TCP sends smaller pieces – TCP segments IP sends IP Datagrams
destination address Router directs the IP datagram out across network
2 to B – router augments the datagram with anetwork access header Network access protocol on B removes the NAP
header and passes the message to higher layer(IP) IP removes the IP header and passes the
message to TCP TCP does processing and then removes the TCP
header and passes the message to application.