InterviewSolution
| 1. |
What This Function Bind() Does? |
|
Answer» Giving a Socket a NAME - bind() #include <ltsys/types.h> Recall that, using socketpair(), sockets could only be shared between parent and child PROCESSES or children of the same parent. With a name attached to the socket, any process on the SYSTEM can describe (and use) it. In a CALL to bind(), s is the file descriptor for the socket, obtained from the call to socket(). name is a pointer to a structure of type sockaddr. If the address family is AF_UNIX (as specified when the socket is created), the structure is defined as follows: struct sockaddr { name.sa_family should be AF_UNIX. name.sa_data should contain up to 14 bytes of a file name which will be ASSIGNED to the socket. namelen gives the actual length of name, that is, the length of the initialized contents of the data structure. A value of 0 is return on success. On failure, -1 is returned with errno describing the error. Example: struct sockaddr name;
Giving a Socket a Name - bind() #include <ltsys/types.h> Recall that, using socketpair(), sockets could only be shared between parent and child processes or children of the same parent. With a name attached to the socket, any process on the system can describe (and use) it. In a call to bind(), s is the file descriptor for the socket, obtained from the call to socket(). name is a pointer to a structure of type sockaddr. If the address family is AF_UNIX (as specified when the socket is created), the structure is defined as follows: struct sockaddr { name.sa_family should be AF_UNIX. name.sa_data should contain up to 14 bytes of a file name which will be assigned to the socket. namelen gives the actual length of name, that is, the length of the initialized contents of the data structure. A value of 0 is return on success. On failure, -1 is returned with errno describing the error. Example: struct sockaddr name;
|
|