Q2. List and describe all elementary socket systems calls and transfer calls. (10 marks)
Answer:
Socket System Call
In the early 1980s, with ARPA project, University of California at Berkeley had the responsibility to transport the TCP/IP protocol suit to Unix operating system. It was decided to use Unix system calls with addition to new system calls, if required, as the result new socket interface developed, which become popular as Berkeley UNX or BSD version 4.1. We are going to discuss BSD Unix system calls with you in this section.
The socket system calls is used by any process to create a socket for doing any network 1/0. The structure of socket, we have already discussed as general but here we will discuss in detail with programming concept. The structure of this is given below.
#include <sys/types.h>
#include <sys/socket.h>
int socket (into family, int type, int protocol );
Condition Returns
Successfully Small integer value called the socket descriptor
Unsuccessful Error (-1)
Socket function creates a socket it sets values for only family, type and protocol of socket structure the other fields are set by other functions or by operating system.
#include<sys/types.h>: This header file contains definitions of a number of data types used in system ca!Is.
#include<sys/soeket.h>: The header file socket.h includes a number of definitions of structures needed for sockets.
Socket Descriptor: As you know, in Unix, if some application needs to perform input/output function, it calls the "open" function to create the file descriptor which has further access to the file. Unix uses descriptor as an index ipto process descriptor table, which follows the pointers to the data structure that holds all details about file.
Socket family: As you know socket family defines the protocol group needed for communication. At the time of programming you should choose one of the given options but because we are concerned about TCP/IP you need to remember AF-INST.
Socket types: The Type parameter in socket system call specifies the semantics of communication. Sockets are typed according to the communication properties visible to a user. Mostly Processes can communicate only between sockets of the similar type. If underlying communication protocols support, communication between different types of sockets can happen.
Protocol: The protocol specifies a particular protocol to be used with the socket. Normally only a single protocol exists to support a particular socket type within a given protocol family. Protocol is dependent on the services we are using in our communication.
Data Transfer Calls
Once a connection is established between sockets, an application program can send and receive data. Sending and receiving data can be done with any one of the several system calls given in this section. The system calls vary according to the amount of data to be transmitted and received and the state of the socket being used to perform the data transfers. The system iyall pairs (read, write), (send, recv), (sendto, recvfrom) can be used to transfer data (or communicate) on sockets. The sendto() subroutine allows the process to specify the destination for a message explicitly.
read() : This is used to receive data from the remote machine, it assumes that there is already an open connection present between two machines and it is possible only in case of TCP (the connection oriented protocol in TCP/IP). Here in the above syntax of read() first sockfd is socket descriptor, buff is a pointer to the buffer where we can store the data and buff len is length of buffer or capacity of buffer.
<<Previous Answer || Index Assignment || Next Answer>>