Unit4 Elementary Socket Calls
Unit4 Elementary Socket Calls
• The socket functions are then defined as taking a pointer to the generic socket
address structure
– int bind(int, struct sockaddr *, socklen_t);
Value-Result Arguments
• When a socket address structure is passed to any
socket function, it is always passed by reference (a
pointer to the structure is passed). The length of the
structure is also passed as an argument.
• The way in which the length is passed depends on
which direction the structure is being passed:
– From the process to the kernel
– From the kernel to the process
From process to kernel
• bind, connect, and sendto functions pass a socket address structure from
the process to the kernel.
• Arguments to these functions:
– The pointer to the socket address structure
– The integer size of the structure
Arguments:
•family: is either AF_INET or AF_INET6. If family is not supported, both functions return an error with errno set
to EAFNOSUPPORT.
Functions:
•inet_pton: converts the string pointed to by strptr, storing the binary result through the pointer addrptr. If successful, the
return value is 1. If the input string is not a valid presentation format for the specified family, 0 is returned.
•inet_ntop does the reverse conversion, from numeric (addrptr) to presentation (strptr).
• The following figure summarizes the five functions on address conversion
functions: