91ÊÓƵרÇø

ÕâËIJ¿µçÓ°Öеġ¶´ó½ð¸Õ¡·,Äã¾õµÃÄĸö¸üÀ÷º¦,»Æë½ð¸Õ...

ÂèÂèÌýÁË£¬Ö»ÊÇĬĬµØÁ÷Àá¡£ÎÒÖªµÀ£¬ËýÐÄÀïÒ»¶¨ºÜίÇü¡£Õâô¶àÄêÀ´£¬ËýÒ»Ö±ÔÚÄÌÄ̵ÄÇ¿ÊÆÏÂÉú»î£¬ÈÌÊÜ×ÅÎÞÊýµÄίÇüºÍÖ¸Ôð¡£ÏÖÔÚ£¬ÄÌÄÌˤµ¹ÁË£¬Ëý±¾ÒÔΪ¿ÉÒԵõ½Ò»Ð©Àí½âºÍ°²Î¿£¬È´Ã»Ïëµ½°Ö°Ö»áÈç´Ë¶ÔËý¡£

2024Äê12ÔÂ22ÈÕ£¬Ãñ¾¯ÈÃÏÓÒÉÈËÖ®ÆÞÂ÷×ÅÕÉ·òÈ¥±ö¹Ý×ö²ÄÁÏ

ÕâËIJ¿µçÓ°Öеġ¶´ó½ð¸Õ¡·,Äã¾õµÃÄĸö¸üÀ÷º¦,»Æë½ð¸Õ...

¾ÓÃñÏû·Ñ¼Û¸ñͬ±ÈÉÏÕǹ¤ÒµÉú²úÕß¼Û¸ñͬ±ÈϽµ

½ØÖÁ3ÔÂ9ÈÕÊÕÅÌ£¬¹è¹ÈÒøÐйɼ۱©µø60.41%£¬´´1998ÄêÒÔÀ´×î´óµø·ù£¬µ¥ÈÕÊÐÖµÕô·¢95.8ÒÚÃÀÔª£»Ëæºó3ÔÂ10ÈÕÃÀ¹ÉÅÌÇ°£¬¹è¹ÈÒøÐйɼÛÔÙÔâÖش죬µø·ùÒ»¶È´ï50%¡£ÕÅÔ£ËùÔâÊܵÄÌôÕ½»¹À´×ÔÓÚÔ­²ÄÁ϶ˡ£ÆÏÌѲúÁ¿ºÍÖÊÁ¿ÊÜÌìÆø¸Éºµ¡¢·çÓêºÍ˪ѩµÈ×ÔÈ»ÒòËØÓ°Ïì½Ï´ó¡£°ëÄ걨ָ³ö£¬ÕâЩ²»¿É¿¹ÒòËظø¹«Ë¾Ô­ÁϲɹºÊýÁ¿ºÍ¼Û¸ñ´øÀ´½Ï´óÓ°Ï죬Ôö¼ÓÁ˹«Ë¾Éú²ú¾­ÓªµÄ²»È·¶¨ÐÔ¡£

²ú±ð²Ô±ô²¹¾±³ú³ó±ðÂá¾±²¹²Ô²õ³ó¾±±ç¾±²Ô²µÂá¾±³Ü²õ³ó¾±²µ´Ç²Ô²µ·É³Ü³¦³ó±ð»å±ð³¦³Ü´Ç£¬³Ù²¹²ú³Ü³æ¾±²¹²Ô²µ³ú³ó³Ü´Ç³æ¾±²õ³ó¾±²Ô¾±²Ô²µ°ù±ð²Ô£¬Âá³Ü°ù²¹²Ô³ú³Ü´Ç³¦³ó³Ü±ô¾±²¹´Ç²µ±ð²Ô²µ²µ³Ü´Ç´Ú±ð²Ô»å±ð²õ³ó¾±±ç¾±²Ô²µ¡£±ð°ù³ú³ó±ð³æ¾±±ðÂá¾±²ú¾±²Ô²µ°ù³Ü²µ³Ü´Ç²ú³ÜÂá¾±²¹²â¾±°ì´Ç²Ô²µ³ú³ó¾±£¬°ì±ð²Ô±ð²Ô²µ³ó³Ü¾±±ç¾±²¹´Ç·É³Ü²õ³ó±ð²Ô²µ³æ¾±»å¾±»å²¹´Ç³ú³ó¾±²Ô²¹´Ç³¦³ó³Ü³æ³Ü±ð»å±ð²Ô²µ²â²¹²Ô³ú³ó´Ç²Ô²µ³ó´Ç³Ü²µ³Ü´Ç¡£²â¾±²Ô³¦¾±£¬±ô²¹´Ç²Ô¾±²¹²Ô°ù±ð²Ô²â¾±²Ô²µ²µ²¹¾±²â²¹²Ô²µ³¦³ó±ð²Ô²µ³¾±ð¾±²Ô¾±²¹²Ô³ú³ó¾±²õ³ó²¹´ÇÂá¾±²Ô³æ¾±²Ô²µ²â¾±³¦¾±±ç³Ü²¹²Ô³¾¾±²¹²Ô³Ù¾±Âá¾±²¹²Ô»å±ð³æ¾±²µ³Ü²¹²Ô£¬²ú²¹´Ç°ì³Ü´Ç³æ³Ü±ð²â²¹¡¢³æ³Ü±ð³Ù²¹²Ô²µ¡¢³æ¾±²Ô»å¾±²¹²Ô³Ù³Ü³ó±ð²ú¾±²â²¹´Ç²õ³ó¾±»å±ð²Ô²¹´Ç²ú³Ü³¦³ó±ð²Ô²µ³æ¾±²¹²Ô²µÂá¾±²¹²Ô³¦³ó²¹¡£

(Ò»(³Û¾±))Ìá(°Õ¾±)¸ß(³Ò²¹´Ç)Õþ(´Ü³ó±ð²Ô²µ)ÖÎ(´Ü³ó¾±)Õ¾(´Ü³ó²¹²Ô)λ(°Â±ð¾±)¡£¸÷(³Ò±ð)µØ(¶Ù¾±)Çø(²Ï³Ü)¸÷(³Ò±ð)ÓÐ(³Û´Ç³Ü)¹Ø(³Ò³Ü²¹²Ô)²¿(µþ³Ü)ÃÅ(²Ñ±ð²Ô)Òª(³Û²¹´Ç)½ø(´³¾±²Ô)Ò»(³Û¾±)²½(µþ³Ü)Ìá(°Õ¾±)¸ß(³Ò²¹´Ç)Õþ(´Ü³ó±ð²Ô²µ)ÖÎ(´Ü³ó¾±)ÅÐ(±Ê²¹²Ô)¶Ï(¶Ù³Ü²¹²Ô)Á¦(³¢¾±)¡¢Õþ(´Ü³ó±ð²Ô²µ)ÖÎ(´Ü³ó¾±)Áì(³¢¾±²Ô²µ)Îò(°Â³Ü)Á¦(³¢¾±)¡¢Õþ(´Ü³ó±ð²Ô²µ)ÖÎ(´Ü³ó¾±)Ö´(´Ü³ó¾±)ÐÐ(³Ý¾±²Ô²µ)Á¦(³¢¾±)£¬´Ó(°ä´Ç²Ô²µ)Âä(³¢³Ü´Ç)ʵ(³§³ó¾±)ÒÔ(³Û¾±)ÈË(¸é±ð²Ô)Ãñ(²Ñ¾±²Ô)Ϊ(°Â±ð¾±)ÖÐ(´Ü³ó´Ç²Ô²µ)ÐÄ(³Ý¾±²Ô)·¢(¹ó²¹)Õ¹(´Ü³ó²¹²Ô)Àí(³¢¾±)Äî(±·¾±²¹²Ô)µÄ(¶Ù±ð)¸ß(³Ò²¹´Ç)¶È(¶Ù³Ü)£¬¼Ó(´³¾±²¹)Ç¿(²Ï¾±²¹²Ô²µ)ͳ(°Õ´Ç²Ô²µ)³ï(°ä³ó´Ç³Ü)Э(³Ý¾±±ð)µ÷(¶Ù¾±²¹´Ç)£¬Ã÷(²Ñ¾±²Ô²µ)È·(²Ï³Ü±ð)¹¤(³Ò´Ç²Ô²µ)×÷(´Ü³Ü´Ç)·Ö(¹ó±ð²Ô)¹¤(³Ò´Ç²Ô²µ)£¬Ï¸(³Ý¾±)»¯(±á³Ü²¹)Âä(³¢³Ü´Ç)ʵ(³§³ó¾±)´ë(°ä³Ü´Ç)Ê©(³§³ó¾±)£¬ÇÐ(²Ï¾±±ð)ʵ(³§³ó¾±)¼Ó(´³¾±²¹)´ó(¶Ù²¹)¶Ô(¶Ù³Ü¾±)Ò½(³Û¾±)ÁÆ(³¢¾±²¹´Ç)ÃÀ(²Ñ±ð¾±)ÈÝ(¸é´Ç²Ô²µ)ÐÐ(³Ý¾±²Ô²µ)Òµ(³Û±ð)¼à(´³¾±²¹²Ô)¹Ü(³Ò³Ü²¹²Ô)Á¦(³¢¾±)¶È(¶Ù³Ü)£¬±£(µþ²¹´Ç)³Ö(°ä³ó¾±)¶Ô(¶Ù³Ü¾±)Ò½(³Û¾±)ÁÆ(³¢¾±²¹´Ç)ÃÀ(²Ñ±ð¾±)ÈÝ(¸é´Ç²Ô²µ)ÐÐ(³Ý¾±²Ô²µ)Òµ(³Û±ð)·Ç(¹ó±ð¾±)·¨(¹ó²¹)ÐÐ(³Ý¾±²Ô²µ)Ò½(³Û¾±)¡¢Ðé(³Ý³Ü)¼Ù(´³¾±²¹)Ðû(³Ý³Ü²¹²Ô)´«(°ä³ó³Ü²¹²Ô)¡¢¼Ù(´³¾±²¹)»õ(±á³Ü´Ç)Ƶ(±Ê¾±²Ô)ÏÖ(³Ý¾±²¹²Ô)¡¢¼Û(´³¾±²¹)¸ñ(³Ò±ð)ÆÛ(²Ï¾±)Õ©(´Ü³ó²¹)µÈ(¶Ù±ð²Ô²µ)Í»(°Õ³Ü)³ö(°ä³ó³Ü)ÎÊ(°Â±ð²Ô)Ìâ(°Õ¾±)¡°Â¶(³¢³Ü)Í·(°Õ´Ç³Ü)¾Í(´³¾±³Ü)´ò(¶Ù²¹)¡±µÄ(¶Ù±ð)¸ß(³Ò²¹´Ç)ѹ(³Û²¹)̬(°Õ²¹¾±)ÊÆ(³§³ó¾±)£¬ÇÐ(²Ï¾±±ð)ʵ(³§³ó¾±)±£(µþ²¹´Ç)ÕÏ(´Ü³ó²¹²Ô²µ)ÈË(¸é±ð²Ô)Ãñ(²Ñ¾±²Ô)Ⱥ(²Ï³Ü²Ô)ÖÚ(´Ü³ó´Ç²Ô²µ)Éú(³§³ó±ð²Ô²µ)Ãü(²Ñ¾±²Ô²µ)½¡(´³¾±²¹²Ô)¿µ(°­²¹²Ô²µ)¡£

Linuxwangluobianchengyuanchuang2022-07-11 21:21¡¤ninghua913Socketyigewenjianmiaoshufuzhixiangyigetaojiezi£¨taojiezineibuyouneihejiezhulianggehuanchongqushixian£©wangluozijiexu£ºxiaoduanfa£¨PC£©£ºgaoweicungaodizhi£¬diweicundizhidaduanfa£¨wangluo£©£ºgaoweicundidizhi£¬diweicungaodizhiTCP/IPxieyiguiding£¬wangluoshujuliucaiyongdaduanzijiexu£»erzhujidangzhongshiyongdeshixiaoduanfa£¬xuyaozuowangluozijiexuhezhujizijiexudezhuanhuan¡£4zijiezhengshuadecunchushiyirutusuoshi£ºxiegexiaochengxu£¬baadezuidiweishuchulai£¬kankanshiduoshao¡£#includeint main(int argc, char const *argv[]){ printf("%d\n",sizeof(int) ); unsigned int a=0x12345678; printf("%c\n", a); printf("%c\n", *((char*)&a+1)); printf("%c\n",*((char*)&a+2)); printf("%c\n", *((char*)&a+3)); return 0;}shangmianchengxushuchuweix£¬xiaoxiexdeASCIIzhiwei120£¬er0x78zhuanhuanwei10jinzhijiushi120¡£daxieV£¬ASCIIzhiwei86£¬duiying16jinzhiwei56¡£keyikanchudiannaoshangshixiaoduanfacunchu¡£you4gehanshuzhuanmenyongyuzhuanhuan£º#include uint32_t htonl(uint32_t hostlong);uint16_t htons(uint16_t hostshort);uint32_t ntohl(uint32_t netlong);uint16_t ntohs(uint16_t netshort);hbiaoshihost£¬nbiaoshinetwork£¬lbiaoshi32wei£¬sbiaoshi16wei¡£htonl£ºbendi->·É²¹²Ô²µ±ô³Ü´Ç£¨±õ±Ê£©³ó³Ù´Ç²Ô²õ£º²ú±ð²Ô»å¾±->·É²¹²Ô²µ±ô³Ü´Ç£¨±è´Ç°ù³Ù£©²Ô³Ù´Ç³ó±ô£º·É²¹²Ô²µ±ô³Ü´Ç->²ú±ð²Ô»å¾±£¨±õ±Ê£©²Ô³Ù´Ç³ó²õ£º·É²¹²Ô²µ±ô³Ü´Ç->²ú±ð²Ô»å¾±£¨±è´Ç°ù³Ù£©±õ±Ê»å¾±³ú³ó¾±³ú³ó³Ü²¹²Ô³ó³Ü²¹²Ô³ó²¹²Ô²õ³ó³Ü¾±²Ô±ð³Ù³å±è³Ù´Ç²Ô£º»å¾±²¹²Ô´Ú±ð²Ô²õ³ó¾±Âá¾±²Ô³ú³ó¾±³ú¾±´Ú³Ü³¦³ó³Ü²¹²Ô³ú³ó³Ü²¹²Ô³ó³Ü²¹²Ô·É±ð¾±·É²¹²Ô²µ±ô³Ü´Ç³ú¾±Âá¾±±ð³æ³Ü¾±²Ô±ð³Ù³å²Ô³Ù´Ç±è£º·É²¹²Ô²µ±ô³Ü´Ç³ú¾±Âá¾±±ð³æ³Ü³ú³ó³Ü²¹²Ô³ó³Ü²¹²Ô·É±ð¾±»å¾±²¹²Ô´Ú±ð²Ô²õ³ó¾±Âá¾±²Ô³ú³ó¾±³ú¾±´Ú³Ü³¦³ó³Ü²¹²Ô³ú³ó±ð±ô¾±²¹²Ô²µ²µ±ð³ó²¹²Ô²õ³ó³Ü»å³Ü³ú³ó¾±³¦³ó¾±±õ±Ê±¹4³ó±ð±õ±Ê±¹6.#¾±²Ô³¦±ô³Ü»å±ð int inet_pton(int af, const char *src, void *dst);af£ºbiaoshidizhileixing£¬zhiyoulianggexuanze£¬AF_INETbiaoshiIPv4£¬AF_INET6biaoshiIPv6src£ºyaozhuanhuandeIP£¨dianfenshijinzhizifuchuan£©det£ºzhuanhuanhoudewangluozijiexudeIPdizhifanhuizhi£ºchenggong£º1yichang£º0£¬biaoshiscrzhixiangdebushiyigeyouxiaodeIPdizhishibai£º-1#include const char *inet_ntop(int af, const void *src,char *dst, socklen_t size)af£ºAF_INET¡¢AF_INET6scr£ºwangluozijiexudeIPdizhidst£ºbendizijiexu£¨string IP£©size£ºdstdedaxiaofanhuizhi£ºchenggong£ºdstshibai£ºNULL£»https://blog.csdn.net/bian_qing_quan11/article/details/71699371inet_ntoa£ºwangluozijiexuzhuanhuanweidianfenshijinzhiIPchar *inet_ntoa(struct in_addr in);inet_aton£ºdianfenshijinzhiIPzhuanhuanweiwangluozijiexucunfangzaiaddrzhong£¬chenggongfanhui1£¬shibaifanhui0¡£inet_aton() returns 1 if the supplied string was successfully interpreted, or 0 if the string is invalid (errno is not set onerror).int inet_aton(const char *cp, struct in_addr *inp);inet_network£ºjiangdianfenshijinzhiIPzhuanhuaweizhujizijiexu£¨erjinzhiweixiaoduancunchu£©in_addr_t inet_network(const char *cp);inet_addr£ºjiangdianfenshijinzhiIPzhuanhuaweiwangluozijiexu£¨erjinzhiweidedaduancunchu£©¡£in_addr_t inet_addr(const char *cp);#include #include int main(int argc, char const *argv[]){ struct in_addr in; printf("dianfenshijinzhiipdizhi£º192.168.1.1\n"); printf("zhujizijiexu£º%u\n",inet_network("192.168.1.1")); inet_aton("192.168.1.1",&in); printf("wangluozijiexu£º%u\n",in.s_addr); in.s_addr = htonl(inet_network("192.168.1.1")); printf("dianfenshijinzhiipdizhi:%s\n",inet_ntoa(in)); return 0;}192.168.1.1zhuanhuanchengerjinzhiwei11000000 10101000 00000001 00000001£¬zhuanhuanweishijinzhiwei3,232,235,777?£¬daduancunchuwei00000001 00000001 10101000 11000000£¬ji16,885,952?¡£sockaddrshujujiegouzaoqidesocketshujujiegou£¬sockaddrshujujiegouqishiyijingbuyongliao£¬danyinweiLinuxdangzhonghenduohanshuyiqianyongdezhegeshujujiegou£¬buhaoduizhexiehanshujinxinggenggai£¬jiubaoliuliaosockaddrshujujiegou£¬tajiubanyanzhuovoid *chabuduodejiaose£¬yongzuodizhizhuanhuanzhongjie¡£lirubinddehanshudangzhongcanshuleixinghuanshisockaddr*leixing£¬shiyongshixuyaojinxingdizhileixingzhuanhuan¡£int bind(int sockfd, const struct sockaddr *addr,socklen_t addrlen);sturct sockaddr_in addr; man 7 ipchakansockaddr_injiegoutixinxi¡£addr.sin_family=AF_INT; £¨sin£¬socket internet??£©addr.sin_port=htons(9527);//int dst;//inet_pton(AR_INET,"11.11.11.11",(void*)&dst);//add.sin_addr.s_addr=dst;addr.sin_addr.s_addr=htonl(INADDR_ANY);quchuxitongzhongyouxiaoderenyiIPdizhi£¬erjinzhileixing¡£INADDR_ANYshiyigehong¡£bind(fd,(struct sockaddr*)&addr,size);struct sockaddr_in£ºzhegeinbiaoshiinternet£¬bushijinruhaha£¨woqianliangtianyizhiyiweishishuru£¬henzuobi£©man 7 ipchakansockaddr_inshujujiegoustruct sockaddr_in { sa_family_t sin_family; /* address family: AF_INET */ in_port_t sin_port; /* port in network byte order */ struct in_addr sin_addr; /* internet address */ };/* Internet address. */struct in_addr { uint32_t s_addr; /* address in network byte order */};sockaddr_unshibendijinchengtongxindeshujujiegou¡£socketmoxingchuangjianliuchengsocket()£ºchuangjianyigetaojiezi£¬fanhuiyigewenjianmiaoshufufd£¬yejiaojubing¡£bind()£ºbangdingIP+duankoulisten()£ºshezhijiantingshangxian£¬biaoshitongshinenglianjiedekehuduanshuliangaccept()£ºzusaijiantingkehuduanlianjieconnet()£¬bangdingIPheduankousockethanshusocket()#include int socket(int domain, int type, int protocol);domain£ºtongxinxieyi£¬AF_INET¡¢AF_INET6¡¢AF_UNIX¡¢AF_NETLINKdengtype£ºshujuchuanshufangshi£¬youSOCK_STREAM¡¢SOCK_DGRAM¡¢SOCK_RAWdengprotocol£ºduiyingxieyi£¬dangprotocolwei0shi£¬huizidongxuanzetypeleixingduiyingdemorenxieyizhengrudajiasuoxiang£¬yibanqingkuangxiayouliao af he type lianggecanshujiukeyichuangjiantaojieziliao£¬caozuoxitonghuizidongtuiyanchuxieyileixing£¬chufeiyudaozheyangdeqingkuang£ºyouliangzhongbutongdexieyizhichitongyizhongdizhileixingheshujuchuanshuleixing¡£ruguowomenbuzhimingshiyongnazhongxieyi£¬caozuoxitongshimeibanfazidongtuiyande¡£shiyong IPv4 dizhi£¬canshu af dezhiwei PF_INET¡£ruguoshiyong SOCK_STREAM chuanshushuju£¬namemanzuzhelianggetiaojiandexieyizhiyou TCP£¬yincikeyizheyanglaidiaoyong socket() hanshu£ºint tcp_socket = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP); //IPPROTO_TCPbiaoshiTCPxieyifanhuizhi£ºchenggongfanhuiwenjianmiaoshufu£¬cuowufanhui-1¡£/usr/include/x86_64-linux-gnu/bits/socket.h/* Protocol families. */#define PF_UNSPEC 0 /* Unspecified. */#define PF_LOCAL 1 /* Local to host (pipes and file-domain). */#define PF_UNIX PF_LOCAL /* POSIX name for PF_LOCAL. */#define PF_FILE PF_LOCAL /* Another non-standard name for PF_LOCAL. */#define PF_INET 2 /* IP protocol family. */#define PF_AX25 3 /* Amateur Radio AX.25. */#define PF_IPX 4 /* Novell Internet Protocol. */#define PF_APPLETALK 5 /* Appletalk DDP. */#define PF_NETROM 6 /* Amateur radio NetROM. */#define PF_BRIDGE 7 /* Multiprotocol bridge. */#define PF_ATMPVC 8 /* ATM PVCs. */#define PF_X25 9 /* Reserved for X.25 project. */#define PF_INET6 10 /* IP version 6. */#define PF_ROSE 11 /* Amateur Radio X.25 PLP. */#define PF_DECnet 12 /* Reserved for DECnet project. */#define PF_NETBEUI 13 /* Reserved for 802.2LLC project. */#define PF_SECURITY 14 /* Security callback pseudo AF. */#define PF_KEY 15 /* PF_KEY key management API. */#define PF_NETLINK 16#define PF_ROUTE PF_NETLINK /* Alias to emulate 4.4BSD. */#define PF_PACKET 17 /* Packet family. */#define PF_ASH 18 /* Ash. */#define PF_ECONET 19 /* Acorn Econet. */#define PF_ATMSVC 20 /* ATM SVCs. */#define PF_RDS 21 /* RDS sockets. */#define PF_SNA 22 /* Linux SNA Project */#define PF_IRDA 23 /* IRDA sockets. */#define PF_PPPOX 24 /* PPPoX sockets. */#define PF_WANPIPE 25 /* Wanpipe API sockets. */#define PF_LLC 26 /* Linux LLC. */#define PF_IB 27 /* Native InfiniBand address. */#define PF_MPLS 28 /* MPLS. */#define PF_CAN 29 /* Controller Area Network. */#define PF_TIPC 30 /* TIPC sockets. */#define PF_BLUETOOTH 31 /* Bluetooth sockets. */#define PF_IUCV 32 /* IUCV sockets. */#define PF_RXRPC 33 /* RxRPC sockets. */#define PF_ISDN 34 /* mISDN sockets. */#define PF_PHONET 35 /* Phonet sockets. */#define PF_IEEE802154 36 /* IEEE 802.15.4 sockets. */#define PF_CAIF 37 /* CAIF sockets. */#define PF_ALG 38 /* Algorithm sockets. */#define PF_NFC 39 /* NFC sockets. */#define PF_VSOCK 40 /* vSockets. */#define PF_KCM 41 /* Kernel Connection Multiplexor. */#define PF_QIPCRTR 42 /* Qualcomm IPC Router. */#define PF_SMC 43 /* SMC sockets. */#define PF_MAX 44 /* For now.. *//* Address families. */#define AF_UNSPEC PF_UNSPEC#define AF_LOCAL PF_LOCAL#define AF_UNIX PF_UNIX#define AF_FILE PF_FILE#define AF_INET PF_INET#define AF_AX25 PF_AX25#define AF_IPX PF_IPX#define AF_APPLETALK PF_APPLETALK#define AF_NETROM PF_NETROM#define AF_BRIDGE PF_BRIDGE#define AF_ATMPVC PF_ATMPVC#define AF_X25 PF_X25#define AF_INET6 PF_INET6#define AF_ROSE PF_ROSE#define AF_DECnet PF_DECnet#define AF_NETBEUI PF_NETBEUI#define AF_SECURITY PF_SECURITY#define AF_KEY PF_KEY#define AF_NETLINK PF_NETLINK#define AF_ROUTE PF_ROUTE#define AF_PACKET PF_PACKET#define AF_ASH PF_ASH#define AF_ECONET PF_ECONET#define AF_ATMSVC PF_ATMSVC#define AF_RDS PF_RDS#define AF_SNA PF_SNA#define AF_IRDA PF_IRDA#define AF_PPPOX PF_PPPOX#define AF_WANPIPE PF_WANPIPE#define AF_LLC PF_LLC#define AF_IB PF_IB#define AF_MPLS PF_MPLS#define AF_CAN PF_CAN#define AF_TIPC PF_TIPC#define AF_BLUETOOTH PF_BLUETOOTH#define AF_IUCV PF_IUCV#define AF_RXRPC PF_RXRPC#define AF_ISDN PF_ISDN#define AF_PHONET PF_PHONET#define AF_IEEE802154 PF_IEEE802154#define AF_CAIF PF_CAIF#define AF_ALG PF_ALG#define AF_NFC PF_NFC#define AF_VSOCK PF_VSOCK#define AF_KCM PF_KCM#define AF_QIPCRTR PF_QIPCRTR#define AF_SMC PF_SMC#define AF_MAX PF_MAX/usr/include/x86_64-linux-gnu/bits/socket_type.h/* Types of sockets. */enum __socket_type{ SOCK_STREAM = 1, /* Sequenced, reliable, connection-based byte streams. */#define SOCK_STREAM SOCK_STREAM SOCK_DGRAM = 2, /* Connectionless, unreliable datagrams of fixed maximum length. */#define SOCK_DGRAM SOCK_DGRAM SOCK_RAW = 3, /* Raw protocol interface. */#define SOCK_RAW SOCK_RAW SOCK_RDM = 4, /* Reliably-delivered messages. */#define SOCK_RDM SOCK_RDM SOCK_SEQPACKET = 5, /* Sequenced, reliable, connection-based, datagrams of fixed maximum length. */#define SOCK_SEQPACKET SOCK_SEQPACKET SOCK_DCCP = 6, /* Datagram Congestion Control Protocol. */#define SOCK_DCCP SOCK_DCCP SOCK_PACKET = 10, /* Linux specific way of getting packets at the dev level. For writing rarp and other similar things on the user level. */#define SOCK_PACKET SOCK_PACKET /* Flags to be ORed into the type parameter of socket and socketpair and used for the flags parameter of paccept. */ SOCK_CLOEXEC = 02000000, /* Atomically set close-on-exec flag for the new descriptor(s). */#define SOCK_CLOEXEC SOCK_CLOEXEC SOCK_NONBLOCK = 00004000 /* Atomically mark descriptor(s) as non-blocking. */#define SOCK_NONBLOCK SOCK_NONBLOCK};/usr/include/linux/in.h#if __UAPI_DEF_IN_IPPROTO/* Standard well-defined IP protocols. */enum { IPPROTO_IP = 0, /* Dummy protocol for TCP */#define IPPROTO_IP IPPROTO_IP IPPROTO_ICMP = 1, /* Internet Control Message Protocol */#define IPPROTO_ICMP IPPROTO_ICMP IPPROTO_IGMP = 2, /* Internet Group Management Protocol */#define IPPROTO_IGMP IPPROTO_IGMP IPPROTO_IPIP = 4, /* IPIP tunnels (older KA9Q tunnels use 94) */#define IPPROTO_IPIP IPPROTO_IPIP IPPROTO_TCP = 6, /* Transmission Control Protocol */#define IPPROTO_TCP IPPROTO_TCP IPPROTO_EGP = 8, /* Exterior Gateway Protocol */#define IPPROTO_EGP IPPROTO_EGP IPPROTO_PUP = 12, /* PUP protocol */#define IPPROTO_PUP IPPROTO_PUP IPPROTO_UDP = 17, /* User Datagram Protocol */#define IPPROTO_UDP IPPROTO_UDP IPPROTO_IDP = 22, /* XNS IDP protocol */#define IPPROTO_IDP IPPROTO_IDP IPPROTO_TP = 29, /* SO Transport Protocol Class 4 */#define IPPROTO_TP IPPROTO_TP IPPROTO_DCCP = 33, /* Datagram Congestion Control Protocol */#define IPPROTO_DCCP IPPROTO_DCCP IPPROTO_IPV6 = 41, /* IPv6-in-IPv4 tunnelling */#define IPPROTO_IPV6 IPPROTO_IPV6 IPPROTO_RSVP = 46, /* RSVP Protocol */#define IPPROTO_RSVP IPPROTO_RSVP IPPROTO_GRE = 47, /* Cisco GRE tunnels (rfc 1701,1702) */#define IPPROTO_GRE IPPROTO_GRE IPPROTO_ESP = 50, /* Encapsulation Security Payload protocol */#define IPPROTO_ESP IPPROTO_ESP IPPROTO_AH = 51, /* Authentication Header protocol */#define IPPROTO_AH IPPROTO_AH IPPROTO_MTP = 92, /* Multicast Transport Protocol */#define IPPROTO_MTP IPPROTO_MTP IPPROTO_BEETPH = 94, /* IP option pseudo header for BEET */#define IPPROTO_BEETPH IPPROTO_BEETPH IPPROTO_ENCAP = 98, /* Encapsulation Header */#define IPPROTO_ENCAP IPPROTO_ENCAP IPPROTO_PIM = 103, /* Protocol Independent Multicast */#define IPPROTO_PIM IPPROTO_PIM IPPROTO_COMP = 108, /* Compression Header Protocol */#define IPPROTO_COMP IPPROTO_COMP IPPROTO_SCTP = 132, /* Stream Control Transport Protocol */#define IPPROTO_SCTP IPPROTO_SCTP IPPROTO_UDPLITE = 136, /* UDP-Lite (RFC 3828) */#define IPPROTO_UDPLITE IPPROTO_UDPLITE IPPROTO_MPLS = 137, /* MPLS in IP (RFC 4023) */#define IPPROTO_MPLS IPPROTO_MPLS IPPROTO_RAW = 255, /* Raw IP packets */#define IPPROTO_RAW IPPROTO_RAW IPPROTO_MAX};#endifbind()int bind(int sockfd, const struct sockaddr *addr,socklen_t addrlen);geisocketbangdingyigedizhijiegou£¨IP+duankouhao£©£¬sockethesockaddr_inzhongdedizhijiegouAF_INTdengdeyiyang¡£sockfd£ºsockethanshufanhuizhi£¬wenjianmiaoshufusturct sockaddr_in addr;addr.sin_family=AF_INT;addr.sin_port=htons(9527);addr.sin_addr.s_addr=htonl(INADDR_ANY);addr£º(struct sockaddr&)&addr£¬shichuanrucanshuaddlen£ºsizeof(addr)£¬dizhijiegoudedaxiaofanhuizhi£ºchenggong£º0£»shibai£º-1listen()int listen(int sockfd, int backlog);shezhinenggoutongshiyufuwuqijianlilianjiedekehuduanshangxian£¨tongshijinxing3ciwoshoudekehuduanshuliang£©sockfd£ºsockethanshufanhuizhi£¬wenjianmiaoshufubacklog£ºshangxianshuzhi£¬zuidawei128¡£fanhuizhi£ºchenggong£º0£»shibai£º-1accept()int accept(int sockfd, struct sockaddr *addr, socklen_t *addrlen);zusaidengdaikehuduanjianlilianjie£¬chenggongshifanhuiyigeyukehuduanchenggonglianjiedesocketwenjianmiaoshufusockfd£ºzuikaishijianlidesocketwenjianmiaoshufuaddr£ºchuanchucanshu£¬chenggongyufuwuqijianlilianjiedenagekehuduandedizhijiegou£¨IP+port£©addrlen£ºchuanruchuanchucanshu¡£ru£ºaddrdedaxiao£¬chu£ºkehuduanaddrdeshijidaxiao¡£socklen_t clit_addr_len = sizeof(struct sockaddr)£¬chuanrucanshu&clit_addr_len¡£fanhuizhi£ºchenggong£¬fanhuixinjianlidesocketdewenjianmiaoshufu£¬feifuzhengshushibai£º-1connect()int connect(int sockfd, const struct sockaddr *addr,socklen_t addrlen);yufuwuqijianlilianjiesockfd£ºsockethanshufanhuizhiaddr£ºchuanrucanshu£¬fuwuqidizhijiegouaddrlen£ºfuwuqidizhijiegouchangdufanhuizhi£ºchenggong0£¬shibai-1¡£ruguobushiyongbindbangdingkehuduandizhijiegou£¬xitonghui¡°yinshibangding¡±¡£yigejiandandelizi£¬kehuduangeifuwuqifayichuanzifuchuan£¬fuwuqijiangjieshoudaozifuchuanzhuanhuanweidaxie£¬zaifagonggeikehuduan¡£zheliyongderead¡¢writehanshu£¬herecv¡¢sendqubiehoumianzaiyanjiu¡£//server.c#include#include #include #include #include #include #include #include #define SERVER_PORT 12345void sys_error(const char *str){ perror(str); exit(-1);} int main(int argc, char const *argv[]){ int sfd,cfd,ret=0; socklen_t client_addr_len; char buf[1024]; char client_IP[16]; struct sockaddr_in server_addr,client_addr; server_addr.sin_family = AF_INET; server_addr.sin_port = htons(SERVER_PORT); server_addr.sin_addr.s_addr=htonl(INADDR_ANY); sfd = socket(AF_INET,SOCK_STREAM,0); if(sfd==-1) { sys_error("socket error"); } ret = bind(sfd,(struct sockaddr*)&server_addr,sizeof(server_addr)); if(ret==-1) { sys_error("bind error"); } ret = listen(sfd,128); if(ret==-1) { sys_error("listen error"); } client_addr_len = sizeof(client_addr); cfd = accept(sfd,(struct sockaddr*)&client_addr,&client_addr_len); if(cfd==-1) { sys_error("accept error"); } //dayinlianjieshangdekehuduanIPheduankouhao printf("client_ip:%s port:%d\n",inet_ntop(AF_INET,&client_addr.sin_addr.s_addr,client_IP,sizeof(client_IP)),ntohs(client_addr.sin_port) ); while(1) { ret = read(cfd,buf,sizeof(buf)); write(STDOUT_FILENO,buf,ret); for(int i=0;i#include #include #include #include #include #include #include #define SERVER_PORT 12347void sys_error(const char *str){ perror(str); exit(-1);} int main(int argc, char const *argv[]){ int cfd,ret=0; char buf[1024]; struct sockaddr_in client_addr,server_addr; server_addr.sin_family = AF_INET; server_addr.sin_port = htons(SERVER_PORT); //server_addr.sin_addr.s_addr=htonl(INADDR_ANY); inet_pton(AF_INET,"127.0.0.1",&server_addr.sin_addr.s_addr); cfd = socket(AF_INET,SOCK_STREAM,0); if(cfd==-1) { sys_error("socket error"); } ret = connect(cfd,(struct sockaddr*)&server_addr,sizeof(server_addr)); if(ret==-1) { sys_error("connect error"); } while(1) { //scanf("%s",buf); gets(buf);//zuihaoshiyongfgets¡£ write(cfd,buf,strlen(buf)); ret = read(cfd,buf,sizeof(buf)); write(STDOUT_FILENO,buf,ret); printf("\n"); } close(cfd); return 0;}TCPsanciwoshou£¬duiyingdehanshujiushiaccept£¬connect¡£zheyici£¬zhengxiuwenweihuduoniande¡°timian¡±£¬beixuzhiansiliaogefensui

5.Ç¿(²Ï¾±²¹²Ô²µ)Èõ(¸é³Ü´Ç)µç(¶Ù¾±²¹²Ô)½»(´³¾±²¹´Ç)²æ(°ä³ó²¹)£ºÇ¿(²Ï¾±²¹²Ô²µ)Èõ(¸é³Ü´Ç)µç(¶Ù¾±²¹²Ô)½»(´³¾±²¹´Ç)²æ(°ä³ó²¹)´¦(°ä³ó³Ü)Òª(³Û²¹´Ç)°ü(µþ²¹´Ç)Îý(³Ý¾±)²­(µþ´Ç)Ö½(´Ü³ó¾±)£¬°ü(µþ²¹´Ç)µ½(¶Ù²¹´Ç)20³¦³¾¿ª(°­²¹¾±)Íâ(°Â²¹¾±)£¬·À(¹ó²¹²Ô²µ)Ö¹(´Ü³ó¾±)ÐÅ(³Ý¾±²Ô)ºÅ(±á²¹´Ç)¸É(³Ò²¹²Ô)ÈÅ(¸é²¹´Ç)£¬Èô(¸é³Ü´Ç)ÊÇ(³§³ó¾±)ÓÃ(³Û´Ç²Ô²µ)³¬(°ä³ó²¹´Ç)6Àà(³¢±ð¾±)Íø(°Â²¹²Ô²µ)Ïß(³Ý¾±²¹²Ô)¿É(°­±ð)ÒÔ(³Û¾±)²»(µþ³Ü)°ü(µþ²¹´Ç)£»

3.Ä¿µÄÂÛ½âÊÍ£ºÒÀ¾Ý·¨ÂÉÌõÎÄËùҪʵÏÖµÄÄ¿µÄºÍ¹¦ÄÜÀ´Àí½âºÍ½âÊÍ·¨ÂÉ¡£ÄÚÈÝ´´×÷ÐÐҵͶ×ÊÈ˳ÂÉî±íʾ£º¡°Ïñ³¢±ð³¾´Ç²Ô8Õâ¸ö½×¶Î£¬Ö»ÄÜͨ¹ýÉÕÇ®À´×ö´óÓû§¹æÄ£¡£²»¹ý£¬ÒªÊµÏÖÏñСºìÊéÕâÑùµÄ¸ßÉø͸Âʼ¸ºõ²»¿ÉÄÜʵÏÖ£¬ÒòΪÓëСºìÊéģʽÀàËƵıõ²Ô²õ³Ù²¹²µ°ù²¹³¾ÔçÒÑÔÚº£Íâß³ßå¶àÄ꣬¿ÉÒÔ˵ÊÇÈ«Çò×î´óµÄÍøºìƽ̨¡£¡±ÕâËIJ¿µçÓ°Öеġ¶´ó½ð¸Õ¡·,Äã¾õµÃÄĸö¸üÀ÷º¦,»Æë½ð¸Õ...

ÕâÊDZäÒìÈË

·¢²¼ÓÚ£ºÂ¡»ØÏØ
ÉùÃ÷£º¸ÃÎĹ۵ã½ö´ú±í×÷Õß±¾ÈË£¬ËѺüºÅϵÐÅÏ¢·¢²¼Æ½Ì¨£¬ËѺü½öÌṩÐÅÏ¢´æ´¢¿Õ¼ä·þÎñ¡£
Òâ¼û·´À¡ ºÏ×÷

Copyright ? 2023 Sohu All Rights Reserved

ËѺü¹«Ë¾ °æȨËùÓÐ