 Hello and welcome to the session on socket interface part 2. At the end of this session students will be able to introduce socket interfaces and list some common functions in this interface. The interaction between a process and the operating system is done through a list of predefined functions. Here in this session we are going to discuss some functions which are going to be combined to create a processes. The first function is socket function. The operating system does not create a socket until instructed by the process. The process needs to use a socket function call to create a socket. The prototype is shown here. A call to this function creates a socket but only three fields in the socket structure family, type and protocol. If the call is successful the function returns a unique socket descriptor SOCFD which is a non-negative integer that can be used to refer to the socket in other calls. If the call is not successful the operating system returns minus 1, the bind function. The socket function fills the fields in the socket partially. To bind the socket to the local computer and local port the bind function needs to be called. The bind function fills the value of the local socket address and if it returns minus 1 if binding fails. The prototype is shown here. In this prototype the SOCFD is the value of the socket descriptor returned from the socket function call. Socket address is a pointer to a socket address that needs to help and the address length is the length of the socket address. The connect function. The connect function is used to add a remote socket address to the socket structure. If it returns minus 1 if the connection fails. The prototype is shown here. The argument is same except that the second and third argument defines the remote address instead of local one. The listen function. The listen function. The listen function is called only by the TCP server. After TCP has created and binding it must inform the operating system that a socket is ready for receiving client requests. The accept function. The accept function is used by a server to inform TCP that it is ready to receive connections from clients. And this function returns minus 1 if it fails. The prototype is shown here. The last two arguments are pointers to address and to length. The accept function is a blocking function that when called blocks itself until the connection is made by a client. The accept function then gets the client socket address and the address length and passes it to the server process to be used to access the fork function. The fork function is used by a process to duplicate a process. The process that calls the fork function is referred to as a parent process and a process which is going to be created. The duplicate is called the child process. And here it is interesting that the fork process is called once but it returns twice. In the parent process the return value is a positive integer. In the child process the return value is 0 if there is an error. The fork function returns minus 1 if it fails. After the fork two processes are running concurrently and the CPU gives running time to each process alternatively. Send and receive function. The send function is used by a process to send data to another process running on a remote machine. The receive function is used by a process to receive data from another process running on a remote machine. The functions assume that there is already an open connection between two machines and it can only be used by TCP or may other protocol like HTTP. These functions returns the number of bytes sent or received. Here the FD is a socket descriptor. Send buffer is a pointer to the buffer where data to be sent have been stored. Receive buffer is a pointer to the buffer where the data is issued to be stored. Send bytes is the size of the data to be sent or received. This function returns the number of actual bytes sent or received if successful otherwise minus 1 if there is an error. Send to and receive from functions. The send to function is used by a process to send data to a remote process using services of UDP. The receive from function is used by a process to receive data from a remote process using a services of UDP. UDP is a connectionless protocol. One of the argument defines the remote socket address. Here the socket FD is the socket descriptor, buffer is a pointer to the buffer where the data to be sent or the data to be received is stored and the buffer length is the length of the buffer. The value of the flag can be non-zero but here we are going to set it as 0 for our simple programs. These functions return the number of bytes sent or received if successful and minus 1 if there is an error. The close function is used by a process to close a socket. The socket FD is not valid after calling this function. The socket returns an integer 0 for success and minus 1 for an error by ordering function. The information in computer is stored host byte order which can be a little indian in which the little end byte is stored in the starting address and big indian which is a big end byte stored in a starting address. Network programming needs data and other piece of information to be in network byte order in which the big indian two functions are designed for this particular purpose. The h turns host to network short which changes a short 16 bit value to a network byte order and h to nl host to network long which does the same for a long 32 bit value. There are also two functions that do exactly n to hs and n to hl. The prototype is shown here. The memory management function at the end we need some functions to manage values stored in the memory and there are three common memory functions. The first function memset that is memory set is used to set a specified number of bytes in the memory defined by the destination pointer. The second function memory copy is used to copy a specified number of bytes from a part of a memory to another part of memory that is from source to destination. The third function memory compare which is used to compare two sets of bytes starting from pointer 1 and pointer 2 and the result is 0 if two sets are equal. It is less than 0 if the first set is smaller than the second and it is greater than 0 if the first set is larger than the second address conversion functions. So generally what happens we normally work with 32 bit IP address which is in a dotted decimal format. Then we want to store the address in socket. We need to change it to the number and there are two functions which are used to convert an address from a presentation to a number and vice versa. I need ptern presentation to number and I need n to p number to presentation. Header files to use just describe the functions we need a set of header files and we define these header files in a separate file okay in header files dot h. We include the files in our programs to avoid including long list of the header files. The header files which are going to be used in the programs are shown here pause the video think and answer the answer is C here is the reference thank you.