亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關于我們
? 蟲蟲下載站

?? syscalls.html

?? Beej的socket教材
?? HTML
?? 第 1 頁 / 共 3 頁
字號:
></DIV><DIVCLASS="sect2"><H2CLASS="sect2"><ANAME="closedown">4.8. <TTCLASS="function">close()</TT> and<TTCLASS="function">shutdown()</TT>--Get outta my face!</A></H2><P>Whew!  You've been <TTCLASS="function">send()</TT>ing and<TTCLASS="function">recv()</TT>ing data all day long, and you've had it.You're ready to close the connection on your socket descriptor.  This iseasy.  You can just use the regular Unix file descriptor<TTCLASS="function">close()</TT> function:</P><TABLEBORDER="0"BGCOLOR="#E0E0E0"WIDTH="100%"><TR><TD><PRECLASS="programlisting">&#13;    close(sockfd); </PRE></TD></TR></TABLE><P>This will prevent any more reads and writes to the socket.  Anyoneattempting to read or write the socket on the remote end will receive anerror.</P><P>Just in case you want a little more control over how the socketcloses, you can use the <TTCLASS="function">shutdown()</TT> function.  Itallows you to cut off communication in a certain direction, or both ways(just like <TTCLASS="function">close()</TT> does.)  Synopsis:</P><TABLEBORDER="0"BGCOLOR="#E0E0E0"WIDTH="100%"><TR><TD><PRECLASS="programlisting">&#13;    int shutdown(int sockfd, int how); </PRE></TD></TR></TABLE><P><TTCLASS="parameter"><I>sockfd</I></TT> is the socket file descriptor youwant to shutdown, and <TTCLASS="parameter"><I>how</I></TT> is one of thefollowing:</P><P></P><UL><LI><P><TTCLASS="constant">0</TT> -- Further receives aredisallowed</P></LI><LI><P><TTCLASS="constant">1</TT> -- Further sends aredisallowed</P></LI><LI><P><TTCLASS="constant">2</TT> -- Further sends and receives aredisallowed (like <TTCLASS="function">close()</TT>)</P></LI></UL><P><TTCLASS="function">shutdown()</TT> returns <TTCLASS="constant">0</TT> onsuccess, and <TTCLASS="constant">-1</TT> on error (with<TTCLASS="parameter"><I>errno</I></TT> set accordingly.)</P><P>If you deign to use <TTCLASS="function">shutdown()</TT> on unconnecteddatagram sockets, it will simply make the socket unavailable for further<TTCLASS="function">send()</TT> and <TTCLASS="function">recv()</TT> calls(remember that you can use these if you <TTCLASS="function">connect()</TT>your datagram socket.)</P><P>It's important to note that <TTCLASS="function">shutdown()</TT>doesn't actually close the file descriptor--it just changes itsusability.  To free a socket descriptor, you need to use<TTCLASS="function">close()</TT>.</P><P>Nothing to it.</P></DIV><DIVCLASS="sect2"><H2CLASS="sect2"><ANAME="getpeername">4.9. <TTCLASS="function">getpeername()</TT>--Who are you?</A></H2><P>This function is so easy.</P><P>It's so easy, I almost didn't give it it's own section.  But hereit is anyway.</P><P>The function <TTCLASS="function">getpeername()</TT> will tell you who is at the other endof a connected stream socket.  The synopsis:</P><TABLEBORDER="0"BGCOLOR="#E0E0E0"WIDTH="100%"><TR><TD><PRECLASS="programlisting">&#13;    #include &#60;sys/socket.h&#62;    int getpeername(int sockfd, struct sockaddr *addr, int *addrlen); </PRE></TD></TR></TABLE><P><TTCLASS="parameter"><I>sockfd</I></TT> is the descriptor of the connectedstream socket, <TTCLASS="parameter"><I>addr</I></TT> is a pointer to a<TTCLASS="type">struct sockaddr</TT> (or a <TTCLASS="type">struct sockaddr_in</TT>) thatwill hold the information about the other side of the connection, and<TTCLASS="parameter"><I>addrlen</I></TT> is a pointer to an <TTCLASS="type">int</TT>, thatshould be initialized to <TTCLASS="computeroutput">sizeof(structsockaddr)</TT>.</P><P>The function returns <TTCLASS="constant">-1</TT> on error and sets<TTCLASS="parameter"><I>errno</I></TT> accordingly.</P><P>Once you have their address, you can use<TTCLASS="function">inet_ntoa()</TT> or <TTCLASS="function">gethostbyaddr()</TT>to print or get more information.  No, you can't get their login name.(Ok, ok.  If the other computer is running an ident daemon, this ispossible.  This, however, is beyond the scope of this document.  Checkout <AHREF="http://www.rfc-editor.org/rfc/rfc1413.txt"TARGET="_top">RFC-1413</A> for moreinfo.)</P></DIV><DIVCLASS="sect2"><H2CLASS="sect2"><ANAME="gethostname">4.10. <TTCLASS="function">gethostname()</TT>--Who am I?</A></H2><P>Even easier than <TTCLASS="function">getpeername()</TT> is thefunction <TTCLASS="function">gethostname()</TT>.  It returns the name of thecomputer that your program is running on.  The name can then be used by<TTCLASS="function">gethostbyname()</TT>, below, to determine the IP addressof your local machine.</P><P>What could be more fun?  I could think of a few things, but theydon't pertain to socket programming.  Anyway, here's thebreakdown:</P><TABLEBORDER="0"BGCOLOR="#E0E0E0"WIDTH="100%"><TR><TD><PRECLASS="programlisting">&#13;    #include &#60;unistd.h&#62;    int gethostname(char *hostname, size_t size); </PRE></TD></TR></TABLE><P>The arguments are simple: <TTCLASS="parameter"><I>hostname</I></TT> is apointer to an array of chars that will contain the hostname upon thefunction's return, and <TTCLASS="parameter"><I>size</I></TT> is the length inbytes of the <TTCLASS="parameter"><I>hostname</I></TT> array.</P><P>The function returns <TTCLASS="constant">0</TT> on successfulcompletion, and <TTCLASS="constant">-1</TT> on error, setting<TTCLASS="parameter"><I>errno</I></TT> as usual.</P></DIV><DIVCLASS="sect2"><H2CLASS="sect2"><ANAME="dns">4.11. DNS--You say "whitehouse.gov", I say "198.137.240.92"</A></H2><P>In case you don't know what DNS is, it stands for "Domain NameService".  In a nutshell, you tell it what the human-readable address isfor a site, and it'll give you the IP address (so you can use it with<TTCLASS="function">bind()</TT>, <TTCLASS="function">connect()</TT>,<TTCLASS="function">sendto()</TT>, or whatever you need it for.)  This way,when someone enters:</P><TABLEBORDER="0"BGCOLOR="#E0E0E0"WIDTH="100%"><TR><TD><PRECLASS="screen">&#13;    <TTCLASS="prompt">$</TT> <BCLASS="command">telnet whitehouse.gov</B></PRE></TD></TR></TABLE><P><BCLASS="command">telnet</B> can find out that it needs to<TTCLASS="function">connect()</TT> to "198.137.240.92".</P><P>But how does it work?  You'll be using the function<TTCLASS="function">gethostbyname()</TT>:</P><TABLEBORDER="0"BGCOLOR="#E0E0E0"WIDTH="100%"><TR><TD><PRECLASS="programlisting">&#13;    #include &#60;netdb.h&#62;        struct hostent *gethostbyname(const char *name); </PRE></TD></TR></TABLE><P>As you see, it returns a pointer to a <TTCLASS="type">struct hostent</TT>,the layout of which is as follows:</P><TABLEBORDER="0"BGCOLOR="#E0E0E0"WIDTH="100%"><TR><TD><PRECLASS="programlisting">&#13;    struct hostent {        char    *h_name;        char    **h_aliases;        int     h_addrtype;        int     h_length;        char    **h_addr_list;    };    #define h_addr h_addr_list[0] </PRE></TD></TR></TABLE><P>And here are the descriptions of the fields in the <TTCLASS="type">structhostent</TT>:</P><P></P><UL><LI><P><TTCLASS="parameter"><I>h_name</I></TT> -- Official name of thehost.</P></LI><LI><P><TTCLASS="parameter"><I>h_aliases</I></TT> -- A NULL-terminatedarray of alternate names for the host.</P></LI><LI><P><TTCLASS="parameter"><I>h_addrtype</I></TT> -- The type of addressbeing returned; usually<TTCLASS="parameter"><I>AF_INET</I></TT>.</P></LI><LI><P><TTCLASS="parameter"><I>h_length</I></TT> -- The length of theaddress in bytes.</P></LI><LI><P><TTCLASS="parameter"><I>h_addr_list</I></TT> -- A zero-terminatedarray of network addresses for the host.  Host addresses are in NetworkByte Order.</P></LI><LI><P><TTCLASS="parameter"><I>h_addr</I></TT> -- The first address in<TTCLASS="parameter"><I>h_addr_list</I></TT>.</P></LI></UL><P><TTCLASS="function">gethostbyname()</TT> returns a pointer to thefilled <TTCLASS="type">struct hostent</TT>, or NULL on error.  (But<TTCLASS="parameter"><I>errno</I></TT> is <EM>not</EM>set--<EM><TTCLASS="parameter"><I>h_errno</I></TT></EM> is set instead.See <TTCLASS="function">herror()</TT>, below.)</P><P>But how is it used?  Sometimes (as we find from reading computermanuals), just spewing the information at the reader is not enough.This function is certainly easier to use than it looks.</P><P><AHREF="http://www.ecst.csuchico.edu/~beej/guide/net/examples/getip.c"TARGET="_top">Here's an exampleprogram</A>:</P><TABLEBORDER="0"BGCOLOR="#E0E0E0"WIDTH="100%"><TR><TD><PRECLASS="programlisting">&#13;    /*    ** getip.c -- a hostname lookup demo    */    #include &#60;stdio.h&#62;    #include &#60;stdlib.h&#62;    #include &#60;errno.h&#62;    #include &#60;netdb.h&#62;    #include &#60;sys/types.h&#62;    #include &#60;sys/socket.h&#62;    #include &#60;netinet/in.h&#62;    #include &#60;arpa/inet.h&#62;    int main(int argc, char *argv[])    {        struct hostent *h;        if (argc != 2) {  // error check the command line            fprintf(stderr,"usage: getip address\n");            exit(1);        }        if ((h=gethostbyname(argv[1])) == NULL) {  // get the host info            herror("gethostbyname");            exit(1);        }        printf("Host name  : %s\n", h-&#62;h_name);        printf("IP Address : %s\n", inet_ntoa(*((struct in_addr *)h-&#62;h_addr)));              return 0;    } </PRE></TD></TR></TABLE><P>With <TTCLASS="function">gethostbyname()</TT>, you can't use<TTCLASS="function">perror()</TT> to print error message (since<TTCLASS="parameter"><I>errno</I></TT> is not used).  Instead, call<TTCLASS="function">herror()</TT>.</P><P>It's pretty straightforward.  You simply pass the string thatcontains the machine name ("whitehouse.gov") to<TTCLASS="function">gethostbyname()</TT>, and then grab the information outof the returned <TTCLASS="type">struct hostent</TT>.</P><P>The only possible weirdness might be in the printing of the IPaddress, above.  <TTCLASS="parameter"><I>h-&#62;h_addr</I></TT> is a<TTCLASS="type">char*</TT>, but <TTCLASS="function">inet_ntoa()</TT> wants a<TTCLASS="type">struct in_addr</TT> passed to it.  So I cast<TTCLASS="parameter"><I>h-&#62;h_addr</I></TT> to a <TTCLASS="type">struct in_addr*</TT>,then dereference it to get at the data.</P></DIV></DIV><DIVCLASS="NAVFOOTER"><HRALIGN="LEFT"WIDTH="100%"><TABLESUMMARY="Footer navigation table"WIDTH="100%"BORDER="0"CELLPADDING="0"CELLSPACING="0"><TR><TDWIDTH="33%"ALIGN="left"VALIGN="top"><AHREF="structs.html">Prev</A></TD><TDWIDTH="34%"ALIGN="center"VALIGN="top"><AHREF="index.html">Home</A></TD><TDWIDTH="33%"ALIGN="right"VALIGN="top"><AHREF="clientserver.html">Next</A></TD></TR><TR><TDWIDTH="33%"ALIGN="left"VALIGN="top"><TTCLASS="type">struct</TT>s and Data Handling</TD><TDWIDTH="34%"ALIGN="center"VALIGN="top">&nbsp;</TD><TDWIDTH="33%"ALIGN="right"VALIGN="top">Client-Server Background</TD></TR></TABLE></DIV></BODY></HTML>

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
色婷婷国产精品综合在线观看| 亚洲欧美另类小说视频| 午夜久久久影院| 国产欧美日本一区视频| 精油按摩中文字幕久久| 欧美色爱综合网| 亚洲自拍另类综合| 欧美日韩一级大片网址| 亚洲综合成人在线| 欧美伦理影视网| 午夜精品爽啪视频| 在线观看av一区| 日韩综合小视频| 日韩欧美国产成人一区二区| 麻豆精品一区二区综合av| 成人免费在线视频| 99在线热播精品免费| 欧美精品一区二区在线观看| 精品一区二区三区蜜桃| 久久影院视频免费| 国产一区二区视频在线播放| 久久蜜桃一区二区| 不卡欧美aaaaa| 亚洲在线视频一区| 欧美一区二区在线观看| 日本亚洲免费观看| 久久久久九九视频| 国产盗摄一区二区| 国产嫩草影院久久久久| 欧美综合一区二区| 国产成人8x视频一区二区| 亚洲小说春色综合另类电影| 2020日本不卡一区二区视频| 91免费视频观看| 久久99久久久久久久久久久| 亚洲少妇最新在线视频| 欧美一区二区观看视频| 99re66热这里只有精品3直播| 免费在线看一区| 久久电影网电视剧免费观看| 一区二区中文视频| 日韩欧美一区二区在线视频| 色综合天天综合给合国产| 久久精品国产亚洲一区二区三区| 伊人色综合久久天天| 久久蜜臀精品av| 欧美一区二区三区的| 99精品偷自拍| 国产成人高清视频| 美女尤物国产一区| 图片区小说区区亚洲影院| 成人欧美一区二区三区白人| 一个色综合av| 中文字幕欧美激情一区| 久久综合资源网| 在线成人av网站| 欧美日韩另类国产亚洲欧美一级| www.亚洲激情.com| 国产91在线看| 国产福利一区在线观看| 美女视频黄免费的久久| 日韩高清在线一区| 亚洲sss视频在线视频| 一区二区三区四区av| 亚洲三级在线免费观看| 久久久www免费人成精品| 中文字幕亚洲一区二区va在线| 久久久另类综合| 精品国产一区二区在线观看| 日韩欧美在线网站| 日韩视频123| 日韩欧美一二三四区| 91精品国产综合久久精品性色 | 欧美福利一区二区| 在线看日韩精品电影| 色婷婷av一区二区三区之一色屋| 北岛玲一区二区三区四区| 精品国产自在久精品国产| 日韩欧美一二三四区| 日韩免费性生活视频播放| 精品日韩在线观看| 久久综合色鬼综合色| 久久久久久久久99精品| 欧美国产亚洲另类动漫| 日韩理论电影院| 亚洲精品国产精华液| 亚洲香蕉伊在人在线观| 性欧美大战久久久久久久久| 日韩电影在线观看电影| 另类小说欧美激情| 国产成人在线看| 欧美一区二区黄| 久久综合九色综合欧美就去吻| 国产亚洲欧美日韩在线一区| 国产精品理论片在线观看| 亚洲免费三区一区二区| 午夜国产精品影院在线观看| 美女精品一区二区| 国产不卡高清在线观看视频| 色综合咪咪久久| 777亚洲妇女| 国产区在线观看成人精品| 国产精品第四页| 日韩中文字幕麻豆| 国产成人精品一区二区三区四区| 日韩精品一区二| 久久久精品天堂| 一区二区高清在线| 蜜桃视频免费观看一区| 成人免费毛片片v| 欧美午夜视频网站| xfplay精品久久| 亚洲嫩草精品久久| 亚洲一区免费观看| 日本亚洲电影天堂| 久久99精品久久久久久国产越南| 国产成人在线网站| 日韩精品综合一本久道在线视频| 国产蜜臀av在线一区二区三区| 一区二区三区成人| 国产在线精品一区二区不卡了| 91麻豆福利精品推荐| 欧美一区二区三区四区五区| 国产精品久久久久三级| 五月天激情小说综合| 成人高清视频在线观看| 在线电影欧美成精品| 亚洲欧美一区二区不卡| 黄网站免费久久| 欧美色男人天堂| 国产精品欧美一级免费| 麻豆国产精品视频| 久久午夜国产精品| 视频在线观看一区| 91免费视频网| 中日韩免费视频中文字幕| 麻豆视频一区二区| 欧美日韩一区国产| 亚洲美女免费在线| 成人一区二区三区视频 | 天堂成人国产精品一区| 懂色av一区二区三区蜜臀 | 国产黄色精品视频| 中文字幕久久午夜不卡| 日本亚洲欧美天堂免费| 91激情五月电影| 亚洲视频一二三区| 国产不卡免费视频| 久久久久久久性| 国产一区二区在线电影| 欧美变态凌虐bdsm| 喷白浆一区二区| 91麻豆精品国产91久久久使用方法| 亚洲乱码国产乱码精品精可以看 | 色乱码一区二区三区88| 亚洲视频一二三| 91精品国产色综合久久| 爽好多水快深点欧美视频| 在线一区二区三区做爰视频网站| 国产精品国模大尺度视频| 成人av影视在线观看| 国产欧美一区二区三区在线看蜜臀| 国产一区在线观看视频| 2020国产精品| 国产成a人无v码亚洲福利| 中文字幕精品三区| eeuss鲁片一区二区三区在线看| 国产人伦精品一区二区| 成人国产亚洲欧美成人综合网 | 欧美日韩一区二区三区在线| 亚洲人成网站影音先锋播放| 成人性生交大片免费| 国产精品欧美一区喷水| 色综合咪咪久久| 亚洲一区二区视频| 在线91免费看| 麻豆高清免费国产一区| 精品国产乱码91久久久久久网站| 国产精品中文字幕欧美| 欧美国产精品一区二区| 一本到三区不卡视频| 亚洲一区二区av在线| 日韩视频在线一区二区| 国产美女在线观看一区| 国产精品乱人伦一区二区| 91香蕉视频在线| 91在线丨porny丨国产| 亚洲精品亚洲人成人网| 欧美男人的天堂一二区| 精品一区二区三区蜜桃| 中文字幕亚洲在| 欧美人妇做爰xxxⅹ性高电影| 久久成人精品无人区| 国产欧美一区二区精品性| 一道本成人在线| 蜜乳av一区二区三区| 国产精品人人做人人爽人人添| 欧美色手机在线观看| 国产综合色在线视频区| 亚洲精品欧美专区|