90 likes | 171 Views
Chapter 5 Socket API. 1980, a group at UC Berkeley create a interface that applications use to communicate. Known as socket API or socket interface System is known as Berkeley UNIX or BSD UNIC. Specifying a protocol interface. Two broad approaches
E N D
Chapter 5 Socket API • 1980, a group at UC Berkeley create a interface that applications use to communicate. • Known as socket API or socket interface • System is known as Berkeley UNIX or BSD UNIC
Specifying a protocol interface • Two broad approaches • Define functions specifically to support TCP/IP communication • Define functions that support network communication in general, and use parameters to make TCP/IP communication a special case. • Because the designer at Berkeley wanted to accommodate multiple sets of communication protocol, they used the second approach.
In fact, they provides for generality far beyond TCP/IP. They allowed for multiple families of protocols, with all TCP/IP protocols represented as single family(family PF_INET) • The socket API provides generalized functions that support network communication using many possible protocols as a single protocol family. The calls allow the programmer to specify the type of service required rather than the name of specific protocol.
Socket abstraction • File descriptors • Open function create a file descriptor • The OS maintains a separate file descriptor as an array of pointers to internal data structure • Application program only need to remember the descriptor and use it
Socket API adds a new abstraction for network communication, the socket. • Each active socket is identified by a small integer called its socket descriptor • OS provides a separate system function, socket, that applications call to create a socket; • Application only use open to crate file descriptor • Once the socket has been created, an application must make additional system calls to specify the details of its exact use.
System data structure for sockets Operating system Descriptor table ( one per process) Family: PF_INET 0: Service:SOCK_STREAM 1: Local IP: 2: Remote IP: 3: Local Port: 4: Remote Port:
Using sockets • A socket used by a server to wait for an incoming connection is called a passive socket • A socket used by a client to initiate a connection is called an active socket. • The sockets are created the same way initially
Endpoint address • When a socket is created, it does not contain detailed information about how it will be used. (port number, IP address) • ICP/IP protocols define a communication endpoint to consist of an IP address and a protocol port number. • It allows each protocol family to specify endpoints however it likes • TCP/IP protocols all use a single address representation, with address family AF_INET
Generic address structure • Struct sockaddr{ • u_char sa_len; // total length • U_short sa_family; // type of address • char sa_data[14]; // value of address • }