(14.3.1)--11.3TheInterfaceFunctionsofSocke.ppt
《(14.3.1)--11.3TheInterfaceFunctionsofSocke.ppt》由会员分享,可在线阅读,更多相关《(14.3.1)--11.3TheInterfaceFunctionsofSocke.ppt(12页珍藏版)》请在得力文库 - 分享文档赚钱的网站上搜索。
1、The Interface Functions of SocketsThe Interface Functions of SocketsSystem call socket()can create a socket and returns a descriptor that can be used to access this socket.The created socket is one end of a communication link.domain:the specified domain.type:the specified communication type of socke
2、ts.protocol:the specified protocol in use.#include#include int socket(int domain,int type,int protocol);Create a socketEach socket domain has its own address format.AF_UNIX:the address format is described by sockaddr_un.AF_INET:the address format is specified by sockaddr_in.struct sockaddr_un sa_fam
3、ily_t sun_family;/*AF_UNIX*/char sun_path;/*pathname*/struct sockaddr_inshort int sin_family;/*AF_INET*/unsigned short int sin_port;struct in_addr sin_addrstruct in_addr unsigned long int s_addr;/Four-byte IP address.Socket addressTo enable the socket created through the system call socket()to be ca
4、lled by other processes,we need to name the socket,so that it can be found by other processes.The local system socket of Unix connects to the pathname of a file system,while the network socket connects to the port number of an IP address.#include int bind(int socket,const struct sockaddr*address,siz
5、e_t address_len);The system call bind()allocates the address in the parameter address to the unnamed socket associated with the file descriptor socket,and the address length is passed by address_len.Name a socketAbout addressThe address length depends on the address family.The system call bind()conv
6、erts a particular address struct pointer into a pointer that points to a general address typegeneral address type:struct sockaddr*.#include int bind(int socket,const struct sockaddr*address,size_t address_len);The address type of a file system socket:struct sockaddr_unThe address type of a network s
7、ocket:struct sockaddr_inReturn value of bind()If the call bind()succeeds,0 is returned.If the call fails,-1 is returned,and set errno to any of the following values.EBADFThe file descriptor is invalid.ENOTSOCKThe file descriptor does not correspond to a socket.EINVALThe file descriptor correspond to
8、 a named socket.EADDRNOTAVATLThe address is not available.EADDRINUSEThe address is already bound to a socket.EACCESSThe file system path cannot be created due to insufficient permissions.ENOTDIR,ENAMETOOLONGThe selected file name does not meet the requirements.#include int listen(int socket,int back
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 14.3 11.3 TheInterfaceFunctionsofSocke
限制150内