- 1、本文档共28页,可阅读全部内容。
- 2、有哪些信誉好的足球投注网站(book118)网站文档一经付费(服务费),不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。
- 3、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。如您付费,意味着您自己接受本站规则且自行承担风险,本站不退款、不进行额外附加服务;查看《如何避免下载的几个坑》。如果您已付费下载过本站文档,您可以点击 这里二次下载。
- 4、如文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“版权申诉”(推荐),也可以打举报电话:400-050-0827(电话支持时间:9:00-18:30)。
查看更多
Socketaddressstructureinamp;lt;syssocket.hamp;gt;structsockaddr{u_sh.ppt
Socket Programming Socket address structure in sys/socket.h: struct sockaddr{ u_short sa_family; /* address family: AF_xxx value */ char sa_data[14]; /* up to 14 bytes of protocol- */ /* specific address */ } Socket Programming Socket address structure in netinet/in.h: (Internet family) struct in_addr{ u_long s_addr; /* 32-bit netid/hostid */ /* network byte ordered */ } Socket Programming struct sockaddr_in{ short sin_family; /* AF_INET */ u_short sin_port; /* 16-bit port number */ /* network byte ordered */ struct in_addr sin_addr; /* 32-bit netid/hostid */ /* network byte ordered */ char sin_zero[8]; /* unused */ } Socket Programming socket : specify the type of communication protocol desired (TCP, UDP etc.) #include sys/types.h #include sys/socket.h int socket(int family, int type, int protocol); family: AF_UNIX (UNIX internal protocol) AF_INET (Internet protocols) AF_NS (Xerox NS protocols) AF_IMPLINK (IMP link layer) (AF: address family) Socket Programming type: SOCK_STREAM (stream socket, TCP) SOCK_DGRAM (datagram socket, UDP) SOCK_RAW (raw socket) SOCK_SEQPACKET (sequenced packet socket) SOCK_RDM (reliably delivered message socket) (not implemented yet) protocol: typically set to 0 for most user applications The output of the system call is the socket descriptor. Socket Programming bind: assign a name to an unnamed socket #include sys/types.h #include sys/socket.h int bind(int sockfd, struct sockaddr *myaddr, int addrlen); sockfd: socket descriptor (return by*myaddr: a pointer to a protocol-specific address addrlen: the size of this address structure The output 0 if success; otherwise, it fails. Socket Programming connect: establish a connection with a server #include sys/types.h #include sys/socket.h int connect (int sockfd, struct sockaddr *servaddr, int addrlen); same as the system call bind. The output 0 if success; otherwise, it fails. Socket
您可能关注的文档
- Music psychology, musicology, musical practice.ppt
- My GK-12 Adventure at Delcastle.ppt
- Network Address Translation in MAC Layer.ppt
- Network Address Translation.ppt
- Neurology.ppt
- New Horizontal College English Book One.ppt
- October 12, 2000.ppt
- Offcie 2000技巧篇之word的技巧介绍.ppt
- Oracle Assets Release 12 Enhancements.ppt
- outline概要-hku libraries-Topic 2 Planning for Research Librari.ppt
文档评论(0)