📄 udp_8c.html
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"><html><head><meta http-equiv="Content-Type" content="text/html;charset=iso-8859-1"><title>udp.c File Reference</title><link href="doxygen.css" rel="stylesheet" type="text/css"></head><body><!-- Generated by Doxygen 1.2.18 --><center><a class="qindex" href="main.html">Main Page</a> <a class="qindex" href="modules.html">Modules</a> <a class="qindex" href="annotated.html">Data Structures</a> <a class="qindex" href="files.html">File List</a> <a class="qindex" href="functions.html">Data Fields</a> <a class="qindex" href="globals.html">Globals</a> <a class="qindex" href="pages.html">Related Pages</a> <a class="qindex" href="examples.html">Examples</a> </center><hr><h1>/opentcp/udp.c File Reference</h1><hr><a name="_details"></a><h2>Detailed Description</h2> <dl compact><dt><b>Author: </b></dt><dd> <ul><li> Jari Lahti (<a href="mailto:jari.lahti@violasystems.com">jari.lahti@violasystems.com</a>) </ul></dl><dl compact><dt><b>Version: </b></dt><dd>1.0 </dl><dl compact><dt><b>Date: </b></dt><dd>15.7.2002 </dl><dl compact><dt><b><a class="el" href="bug.html#_bug000024">Bug: </a></b></dt><dd></dl> <dl compact><dt><b>Warning: </b></dt><dd> </dl><dl compact><dt><b><a class="el" href="todo.html#_todo000026">Todo: </a></b></dt><dd><ul><li> Send ICMP Destination Unreachable when receiving UDP packets to non-existent UDP ports.</dl></ul>OpenTCP UDP implementation. All functions necessary for UDP packet processing are present here. Note that only a small subset of these functions must be used for "normal" applications that are using the UDP for communciation. For function declarations and lots of other usefull stuff see <a class="el" href="tcp__ip_8h.html">inet/tcp_ip.h</a>.<p>For examples how to use UDP and write applications that communicate using UDP see inet/demo/main_demo.c and inet/demo/udp_demo.c.<p><p>Definition in file <a class="el" href="udp_8c-source.html">udp.c</a>.<p><a href="udp_8c-source.html">Go to the source code of this file.</a><table border=0 cellpadding=0 cellspacing=0><tr><td></td></tr><tr><td colspan=2><br><h2>Functions</h2></td></tr><tr><td nowrap align=right valign=top>INT8 </td><td valign=bottom><a class="el" href="udp_8c.html#a2">udp_init</a> (void)</td></tr><tr><td> </td><td><font size=-1><em>Initialize UDP socket pool.</em> <a href="#a2"></a><em></em></font><br><br></td></tr><tr><td nowrap align=right valign=top>INT8 </td><td valign=bottom><a class="el" href="udp_8c.html#a3">udp_getsocket</a> (UINT8 tos, INT32(*listener)(INT8, UINT8, UINT32, UINT16, UINT16, UINT16), UINT8 opts)</td></tr><tr><td> </td><td><font size=-1><em>Allocate a free socket in UDP socket pool.</em> <a href="#a3"></a><em></em></font><br><br></td></tr><tr><td nowrap align=right valign=top>INT8 </td><td valign=bottom><a class="el" href="udp_8c.html#a4">udp_releasesocket</a> (INT8 sochandle)</td></tr><tr><td> </td><td><font size=-1><em>Release a given socket.</em> <a href="#a4"></a><em></em></font><br><br></td></tr><tr><td nowrap align=right valign=top>INT8 </td><td valign=bottom><a class="el" href="udp_8c.html#a5">udp_open</a> (INT8 sochandle, UINT16 locport)</td></tr><tr><td> </td><td><font size=-1><em>Open a given UDP socket for communication.</em> <a href="#a5"></a><em></em></font><br><br></td></tr><tr><td nowrap align=right valign=top>INT8 </td><td valign=bottom><a class="el" href="udp_8c.html#a6">udp_close</a> (INT8 sochandle)</td></tr><tr><td> </td><td><font size=-1><em>Close given socket for communication.</em> <a href="#a6"></a><em></em></font><br><br></td></tr><tr><td nowrap align=right valign=top>INT16 </td><td valign=bottom><a class="el" href="udp_8c.html#a7">udp_send</a> (INT8 sochandle, UINT32 remip, UINT16 remport, UINT8 *buf, UINT16 blen, UINT16 dlen)</td></tr><tr><td> </td><td><font size=-1><em>Send data to remote host using given UDP socket.</em> <a href="#a7"></a><em></em></font><br><br></td></tr><tr><td nowrap align=right valign=top>INT16 </td><td valign=bottom><a class="el" href="udp_8c.html#a8">process_udp_in</a> (struct <a class="el" href="structip__frame.html">ip_frame</a> *frame, UINT16 len)</td></tr><tr><td> </td><td><font size=-1><em>Process received UDP frame.</em> <a href="#a8"></a><em></em></font><br><br></td></tr><tr><td nowrap align=right valign=top>UINT16 </td><td valign=bottom><a class="el" href="udp_8c.html#a9">udp_getfreeport</a> (void)</td></tr><tr><td> </td><td><font size=-1><em>Returns next free (not used) local port number.</em> <a href="#a9"></a><em></em></font><br><br></td></tr><tr><td colspan=2><br><h2>Variables</h2></td></tr><tr><td nowrap align=right valign=top><a class="el" href="structucb.html">ucb</a> </td><td valign=bottom><a class="el" href="udp_8c.html#a0">udp_socket</a> [NO_OF_UDPSOCKETS]</td></tr><tr><td> </td><td><font size=-1><em>UDP table holding socket parameters for every UDP socket.</em> <a href="#a0"></a><em></em></font><br><br></td></tr><tr><td nowrap align=right valign=top><a class="el" href="structudp__frame.html">udp_frame</a> </td><td valign=bottom><a class="el" href="udp_8c.html#a1">received_udp_packet</a></td></tr><tr><td> </td><td><font size=-1><em>Used for storing field information about the received UDP packet.</em> <a href="#a1"></a><em></em></font><br><br></td></tr></table><hr><h2>Function Documentation</h2><a name="a2" doxytag="udp.c::udp_init"></a><p><table width="100%" cellpadding="2" cellspacing="0" border="0"> <tr> <td class="md"> <table cellpadding="0" cellspacing="0" border="0"> <tr> <td class="md" nowrap valign="top"> INT8 udp_init </td> <td class="md" valign="top">( </td> <td class="md" nowrap valign="top">void </td> <td class="mdname1" valign="top" nowrap> </td> <td class="md" valign="top">) </td> <td class="md" nowrap></td> </tr> </table> </td> </tr></table><table cellspacing=5 cellpadding=0 border=0> <tr> <td> </td> <td><p><dl compact><dt><b>Author: </b></dt><dd> <ul><li> Jari Lahti (<a href="mailto:jari.lahti@violasystems.com">jari.lahti@violasystems.com</a>) </ul></dl><dl compact><dt><b>Date: </b></dt><dd>26.07.2002 </dl><dl compact><dt><b>Returns: </b></dt><dd> <ul><li> -1 - Error <li> >0 - Number of UDP sockets initialized </ul></dl><dl compact><dt><b>Warning: </b></dt><dd> <ul><li> This function <b>must</b> be invoked before any other UDP-related function is called</ul></dl>This function initializes UDP socket pool to get everything into a known state at startup. <p>Definition at line <a class="el" href="udp_8c-source.html#l00118">118</a> of file <a class="el" href="udp_8c-source.html">udp.c</a>.<p>References <a class="el" href="tcp__ip_8h-source.html#l00525">ucb::locport</a>, <a class="el" href="tcp__ip_8h-source.html#l00539">ucb::opts</a>, <a class="el" href="tcp__ip_8h-source.html#l00516">ucb::state</a>, <a class="el" href="tcp__ip_8h-source.html#l00523">ucb::tos</a>, <a class="el" href="tcp__ip_8h-source.html#l00140">UDP_OPT_CHECK_CS</a>, <a class="el" href="tcp__ip_8h-source.html#l00132">UDP_OPT_SEND_CS</a>, and <a class="el" href="tcp__ip_8h-source.html#l00249">UDP_STATE_FREE</a>. </td> </tr></table><a name="a3" doxytag="udp.c::udp_getsocket"></a><p><table width="100%" cellpadding="2" cellspacing="0" border="0"> <tr> <td class="md"> <table cellpadding="0" cellspacing="0" border="0"> <tr> <td class="md" nowrap valign="top"> INT8 udp_getsocket </td> <td class="md" valign="top">( </td> <td class="md" nowrap valign="top">UINT8 </td> <td class="mdname" nowrap> <em>tos</em>, </td> </tr> <tr> <td></td> <td></td> <td class="md" nowrap>INT32(* </td> <td class="mdname" nowrap> <em>listener</em>)(INT8, UINT8, UINT32, UINT16, UINT16, UINT16), </td> </tr> <tr> <td></td> <td></td> <td class="md" nowrap>UINT8 </td> <td class="mdname" nowrap> <em>opts</em></td> </tr> <tr> <td></td> <td class="md">) </td> <td class="md" colspan="2"></td> </tr> </table> </td> </tr></table><table cellspacing=5 cellpadding=0 border=0> <tr> <td> </td> <td><p><dl compact><dt><b>Author: </b></dt><dd> <ul><li> Jari Lahti (<a href="mailto:jari.lahti@violasystems.com">jari.lahti@violasystems.com</a>) </ul></dl><dl compact><dt><b>Date: </b></dt><dd>26.07.2002 </dl><dl compact><dt><b>Parameters: </b></dt><dd><table border=0 cellspacing=2 cellpadding=0><tr><td valign=top><em>tos</em> </td><td>type of service for socket. For now nothing implemented so 0. </td></tr><tr><td valign=top><em>listener</em> </td><td>pointer to callback function that will be invoked by the TCP/IP stack to inform socket application of UDP_DATA_ARRIVAL event (for now only this, in future maybe others!) </td></tr><tr><td valign=top><em>opts</em> </td><td>Options for checksum generation & inspection. Can be one of the following: <ul><li> <a class="el" href="tcp__ip_8h.html#a4">UDP_OPT_NONE</a> <li> <a class="el" href="tcp__ip_8h.html#a5">UDP_OPT_SEND_CS</a> <li> <a class="el" href="tcp__ip_8h.html#a6">UDP_OPT_CHECK_CS</a> <li> <a class="el" href="tcp__ip_8h.html#a5">UDP_OPT_SEND_CS</a> | <a class="el" href="tcp__ip_8h.html#a6">UDP_OPT_CHECK_CS</a> </ul></td></tr></table></dl><dl compact><dt><b>Returns: </b></dt><dd> <ul><li> -1 - Error <li> >=0 - Handle to reserved socket</ul></dl>Invoke this function to try to obtain a free socket from UDP socket pool. Function returns a handle to the free socket that is later used for accessing the allocated socket. <p>Definition at line <a class="el" href="udp_8c-source.html#l00175">175</a> of file <a class="el" href="udp_8c-source.html">udp.c</a>.<p>References <a class="el" href="tcp__ip_8h-source.html#l00525">ucb::locport</a>, <a class="el" href="tcp__ip_8h-source.html#l00539">ucb::opts</a>, <a class="el" href="tcp__ip_8h-source.html#l00516">ucb::state</a>, <a class="el" href="tcp__ip_8h-source.html#l00523">ucb::tos</a>, <a class="el" href="tcp__ip_8h-source.html#l00140">UDP_OPT_CHECK_CS</a>, <a class="el" href="tcp__ip_8h-source.html#l00132">UDP_OPT_SEND_CS</a>, <a class="el" href="tcp__ip_8h-source.html#l00258">UDP_STATE_CLOSED</a>, and <a class="el" href="tcp__ip_8h-source.html#l00249">UDP_STATE_FREE</a>.<p>Referenced by <a class="el" href="bootp_8c-source.html#l00108">bootpc_init()</a>, <a class="el" href="dhcpc_8c-source.html#l00158">dhcpc_init()</a>, <a class="el" href="dns_8c-source.html#l00108">dns_init()</a>, and <a class="el" href="tftps_8c-source.html#l00136">tftps_init()</a>. </td> </tr></table><a name="a4" doxytag="udp.c::udp_releasesocket"></a><p><table width="100%" cellpadding="2" cellspacing="0" border="0"> <tr> <td class="md"> <table cellpadding="0" cellspacing="0" border="0"> <tr> <td class="md" nowrap valign="top"> INT8 udp_releasesocket </td> <td class="md" valign="top">( </td> <td class="md" nowrap valign="top">INT8 </td> <td class="mdname1" valign="top" nowrap> <em>sochandle</em> </td> <td class="md" valign="top">) </td> <td class="md" nowrap></td> </tr> </table> </td> </tr></table><table cellspacing=5 cellpadding=0 border=0> <tr> <td> </td> <td><p><dl compact><dt><b>Author: </b></dt><dd> <ul><li> Jari Lahti (<a href="mailto:jari.lahti@violasystems.com">jari.lahti@violasystems.com</a>) </ul></dl><dl compact><dt><b>Date: </b></dt><dd>26.07.2002 </dl><dl compact><dt><b>Parameters: </b></dt><dd><table border=0 cellspacing=2 cellpadding=0><tr><td valign=top><em>sochandle</em> </td><td>handle of UDP socket to be released </td></tr></table></dl><dl compact><dt><b>Returns: </b></dt><dd> <ul><li> -1 - error <li> >=0 - OK (returns handle to release socket)</ul></dl>This function releases UDP socket. This means that the socket entry is marked as free and all of the ucb fields are initialized to default values. <p>Definition at line <a class="el" href="udp_8c-source.html#l00244">244</a> of file <a class="el" href="udp_8c-source.html">udp.c</a>.<p>References <a class="el" href="tcp__ip_8h-source.html#l00525">ucb::locport</a>, <a class="el" href="tcp__ip_8h-source.html#l00539">ucb::opts</a>, <a class="el" href="tcp__ip_8h-source.html#l00516">ucb::state</a>, <a class="el" href="tcp__ip_8h-source.html#l00523">ucb::tos</a>, <a class="el" href="tcp__ip_8h-source.html#l00140">UDP_OPT_CHECK_CS</a>, <a class="el" href="tcp__ip_8h-source.html#l00132">UDP_OPT_SEND_CS</a>, and <a class="el" href="tcp__ip_8h-source.html#l00249">UDP_STATE_FREE</a>. </td> </tr></table><a name="a5" doxytag="udp.c::udp_open"></a><p><table width="100%" cellpadding="2" cellspacing="0" border="0"> <tr> <td class="md"> <table cellpadding="0" cellspacing="0" border="0"> <tr> <td class="md" nowrap valign="top"> INT8 udp_open </td> <td class="md" valign="top">( </td> <td class="md" nowrap valign="top">INT8 </td> <td class="mdname" nowrap> <em>sochandle</em>, </td> </tr> <tr> <td></td> <td></td> <td class="md" nowrap>UINT16 </td> <td class="mdname" nowrap> <em>locport</em></td> </tr> <tr> <td></td> <td class="md">) </td> <td class="md" colspan="2"></td> </tr> </table> </td> </tr></table><table cellspacing=5 cellpadding=0 border=0> <tr> <td> </td> <td><p><dl compact><dt><b>Author: </b></dt><dd> <ul><li> Jari Lahti (<a href="mailto:jari.lahti@violasystems.com">jari.lahti@violasystems.com</a>) </ul></dl><dl compact><dt><b>Date: </b></dt><dd>26.07.2002 </dl><dl compact><dt><b>Parameters: </b></dt><dd><table border=0 cellspacing=2 cellpadding=0><tr><td valign=top><em>sochandle</em> </td><td>handle to socket to be opened </td></tr><tr><td valign=top><em>locport</em> </td><td>local port number </td></tr></table></dl><dl compact><dt><b>Returns: </b></dt><dd> <ul><li> -1 - Error <li> >=0 - Handle to opened socket</ul></dl>This function binds local port to given UDP socket and opens the socket (virtually) in order to enable communication. <p>Definition at line <a class="el" href="udp_8c-source.html#l00291">291</a> of file <a class="el" href="udp_8c-source.html">udp.c</a>.<p>References <a class="el" href="tcp__ip_8h-source.html#l00525">ucb::locport</a>, <a class="el" href="tcp__ip_8h-source.html#l00516">ucb::state</a>, <a class="el" href="udp_8c-source.html#l00684">udp_getfreeport()</a>, and <a class="el" href="tcp__ip_8h-source.html#l00266">UDP_STATE_OPENED</a>.<p>Referenced by <a class="el" href="bootp_8c-source.html#l00108">bootpc_init()</a>, <a class="el" href="dhcpc_8c-source.html#l00158">dhcpc_init()</a>, <a class="el" href="dns_8c-source.html#l00108">dns_init()</a>, and <a class="el" href="tftps_8c-source.html#l00136">tftps_init()</a>. </td> </tr></table><a name="a6" doxytag="udp.c::udp_close"></a><p><table width="100%" cellpadding="2" cellspacing="0" border="0"> <tr> <td class="md"> <table cellpadding="0" cellspacing="0" border="0"> <tr> <td class="md" nowrap valign="top"> INT8 udp_close </td> <td class="md" valign="top">( </td> <td class="md" nowrap valign="top">INT8 </td> <td class="mdname1" valign="top" nowrap> <em>sochandle</em> </td> <td class="md" valign="top">) </td> <td class="md" nowrap></td> </tr>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -