|
h>MyPLinuxÁªÃË
|
¶¨Ò庯Êý | void endprotoent(void);MyPLinuxÁªÃË
|
º¯Êý˵Ã÷ | endprotoent()ÓÃÀ´¹Ø±ÕÓÉgetprotoent()´ò¿ªµÄÎļþ¡£MyPLinuxÁªÃË
|
·µ»ØÖµ | MyPLinuxÁªÃË
|
·¶Àý | ²Î¿¼getprotoent()MyPLinuxÁªÃË
|
| ¡¡ |
MyPLinuxÁªÃË
| MyPLinuxÁªÃË endservent£¨½áÊøÍøÂç·þÎñÊý¾ÝµÄ¶ÁÈ¡£© |
Ïà¹Øº¯Êý | getservent£¬getservbyname£¬getservbyport£¬setserventMyPLinuxÁªÃË
|
±íÍ·Îļþ | #include<netdb.h>MyPLinuxÁªÃË
|
¶¨Ò庯Êý | void endservent(void);MyPLinuxÁªÃË
|
º¯Êý˵Ã÷ | endservent()ÓÃÀ´¹Ø±ÕÓÉgetservent()Ëù´ò¿ªµÄÎļþ¡£MyPLinuxÁªÃË
|
·µ»ØÖµ | MyPLinuxÁªÃË
|
·¶Àý | ²Î¿¼getservent()¡£MyPLinuxÁªÃË
|
| ¡¡ |
MyPLinuxÁªÃË
| MyPLinuxÁªÃË getsockopt£¨È¡µÃsocket״̬£© |
Ïà¹Øº¯Êý | setsockoptMyPLinuxÁªÃË
|
±íÍ·Îļþ | #include<sys/types.h>MyPLinuxÁªÃË #include<sys/socket.h>MyPLinuxÁªÃË
|
¶¨Ò庯Êý | int getsockopt(int s,int level,int optname,void* optval,socklen_t* optlen);MyPLinuxÁªÃË
|
º¯Êý˵Ã÷ | getsockopt()»á½«²ÎÊýsËùÖ¸¶¨µÄsocket״̬·µ»Ø¡£²ÎÊýoptname´ú±íÓûÈ¡µÃºÎÖÖÑ¡Ïî״̬£¬¶ø²ÎÊýoptvalÔòÖ¸ÏòÓû±£´æ½á¹ûµÄÄÚ´æµØÖ·£¬²ÎÊýoptlenÔòΪ¸Ã¿Õ¼äµÄ´óС¡£²ÎÊýlevel¡¢optnameÇë²Î¿¼setsockopt()¡£MyPLinuxÁªÃË
|
·µ»ØÖµ | ³É¹¦Ôò·µ»Ø0£¬ÈôÓдíÎóÔò·µ»Ø-1£¬´íÎóÔÒò´æÓÚerrnoMyPLinuxÁªÃË
|
´íÎó´úÂë | EBADF ²ÎÊýs ²¢·ÇºÏ·¨µÄsocket´¦Àí´úÂëMyPLinuxÁªÃË ENOTSOCK ²ÎÊýsΪһÎļþÃèÊö´Ê£¬·ÇsocketMyPLinuxÁªÃË ENOPROTOOPT ²ÎÊýoptnameÖ¸¶¨µÄÑ¡Ïî²»ÕýÈ·MyPLinuxÁªÃË EFAULT ²ÎÊýoptvalÖ¸ÕëÖ¸ÏòÎÞ·¨´æÈ¡µÄÄÚ´æ¿Õ¼äMyPLinuxÁªÃË
|
·¶Àý | #include<sys/types.h>MyPLinuxÁªÃË #include<sys/socket.h>MyPLinuxÁªÃË main()MyPLinuxÁªÃË {MyPLinuxÁªÃË int s,optval,optlen = sizeof(int);MyPLinuxÁªÃË if((s = socket(AF_INET,SOCK_STREAM,0))<0) perror(¡°socket¡±);MyPLinuxÁªÃË getsockopt(s,SOL_SOCKET,SO_TYPE,&optval,&optlen);MyPLinuxÁªÃË printf(¡°optval = %dn¡±,optval);MyPLinuxÁªÃË close(s);}MyPLinuxÁªÃË
|
Ö´ÐÐ | optval = 1 /*SOCK_STREAMµÄ¶¨ÒåÕýÊÇ´ËÖµ*/MyPLinuxÁªÃË
|
| ¡¡ |
MyPLinuxÁªÃË
| MyPLinuxÁªÃË htonl£¨½«32λÖ÷»ú×Ö·û˳Ðòת»»³ÉÍøÂç×Ö·û˳Ðò£© |
Ïà¹Øº¯Êý | htons£¬ntohl£¬ntohsMyPLinuxÁªÃË
|
±íÍ·Îļþ | #include<netinet/in.h>MyPLinuxÁªÃË
|
¶¨Ò庯Êý | unsigned long int htonl(unsigned long int hostlong);MyPLinuxÁªÃË
|
º¯Êý˵Ã÷ | htonl£¨£©ÓÃÀ´½«²ÎÊýÖ¸¶¨µÄ32λhostlong ת»»³ÉÍøÂç×Ö·û˳Ðò¡£MyPLinuxÁªÃË
|
·µ»ØÖµ | ·µ»Ø¶ÔÓ¦µÄÍøÂç×Ö·û˳Ðò¡£MyPLinuxÁªÃË
|
·¶Àý | ²Î¿¼getservbyport()»òconnect()¡£MyPLinuxÁªÃË
|
| ¡¡ |
MyPLinuxÁªÃË
| MyPLinuxÁªÃË htons£¨½«16λÖ÷»ú×Ö·û˳Ðòת»»³ÉÍøÂç×Ö·û˳Ðò£© |
Ïà¹Øº¯Êý | htonl£¬ntohl£¬ntohsMyPLinuxÁªÃË
|
±íÍ·Îļþ | #include<netinet/in.h>MyPLinuxÁªÃË
|
¶¨Ò庯Êý | unsigned short int htons(unsigned short int hostshort);MyPLinuxÁªÃË
|
º¯Êý˵Ã÷ | htons()ÓÃÀ´½«²ÎÊýÖ¸¶¨µÄ16λhostshortת»»³ÉÍøÂç×Ö·û˳Ðò¡£MyPLinuxÁªÃË
|
·µ»ØÖµ | ·µ»Ø¶ÔÓ¦µÄÍøÂç×Ö·û˳Ðò¡£MyPLinuxÁªÃË
|
·¶Àý | ²Î¿¼connect()¡£MyPLinuxÁªÃË
|
| ¡¡ |
MyPLinuxÁªÃË
| MyPLinuxÁªÃË inet_addr£¨½«ÍøÂçµØÖ·×ª³É¶þ½øÖƵÄÊý×Ö£© |
Ïà¹Øº¯Êý | inet_aton£¬inet_ntoaMyPLinuxÁªÃË
|
±íÍ·Îļþ | #include<sys/socket.h>MyPLinuxÁªÃË #include<netinet/in.h>MyPLinuxÁªÃË #include<arpa/inet.h>MyPLinuxÁªÃË
|
¶¨Ò庯Êý | unsigned long int inet_addr(const char *cp);MyPLinuxÁªÃË
|
º¯Êý˵Ã÷ | inet_addr()ÓÃÀ´½«²ÎÊýcpËùÖ¸µÄÍøÂçµØÖ·×Ö·û´®×ª»»³ÉÍøÂçËùʹÓõĶþ½øÖÆÊý×Ö¡£ÍøÂçµØÖ·×Ö·û´®ÊÇÒÔÊý×ֺ͵ã×é³ÉµÄ×Ö·û´®£¬ÀýÈç:¡°163.13.132.68¡±¡£MyPLinuxÁªÃË
|
·µ»ØÖµ | ³É¹¦Ôò·µ»Ø¶ÔÓ¦µÄÍøÂç¶þ½øÖƵÄÊý×Ö£¬Ê§°Ü·µ»Ø-1¡
LinuxÁªÃËÊÕ¼¯ÕûÀí ,תÌùÇë±êÃ÷ÔʼÁ´½Ó,ÈçÓÐÈκÎÒÉÎÊ»¶ÓÀ´±¾Õ¾LinuxÂÛ̳ÌÖÂÛ |
|
|
|
|