📄 net_8h-source.html
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><html><head><meta http-equiv="Content-Type" content="text/html;charset=iso-8859-1"><title>Procyon AVRlib: net/net.h Source File</title><link href="dox.css" rel="stylesheet" type="text/css"></head><body><!-- Generated by Doxygen 1.4.2 --><div class="qindex"><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="dirs.html">Directories</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></div><div class="nav"><a class="el" href="dir_000001.html">net</a></div><h1>net.h</h1><a href="net_8h.html">Go to the documentation of this file.</a><div class="fragment"><pre class="fragment">00001 <span class="comment">/*! \file net.h \brief Network support library. */</span>00002 <span class="comment">//*****************************************************************************</span>00003 <span class="comment">//</span>00004 <span class="comment">// File Name : 'net.h'</span>00005 <span class="comment">// Title : Network support library</span>00006 <span class="comment">// Author : Pascal Stang</span>00007 <span class="comment">// Created : 8/30/2004</span>00008 <span class="comment">// Revised : 7/3/2005</span>00009 <span class="comment">// Version : 0.1</span>00010 <span class="comment">// Target MCU : Atmel AVR series</span>00011 <span class="comment">// Editor Tabs : 4</span>00012 <span class="comment">//</span><span class="comment"></span>00013 <span class="comment">/// \ingroup network</span>00014 <span class="comment">/// \defgroup net Network support library (net.c)</span>00015 <span class="comment">/// \code #include "net/net.h" \endcode</span>00016 <span class="comment">/// \par Description</span>00017 <span class="comment">/// This is a general network support library including a multitude of </span>00018 <span class="comment">/// structure definitions for various types of network packets, functions</span>00019 <span class="comment">/// and macros for switching byte order, and an RFC-compliant function</span>00020 <span class="comment">/// for calculating checksums.</span>00021 <span class="comment"></span><span class="comment">//</span>00022 <span class="comment">// This code is distributed under the GNU Public License</span>00023 <span class="comment">// which can be found at http://www.gnu.org/licenses/gpl.txt</span>00024 <span class="comment">//*****************************************************************************</span><span class="comment"></span>00025 <span class="comment">//@{</span>00026 <span class="comment"></span>00027 <span class="preprocessor">#ifndef NET_H</span>00028 <span class="preprocessor"></span><span class="preprocessor">#define NET_H</span>00029 <span class="preprocessor"></span>00030 <span class="preprocessor">#include <inttypes.h></span>00031 <span class="preprocessor">#include "<a class="code" href="global_8h.html">global.h</a>"</span>00032 00033 <span class="comment">// Representation of a 48-bit Ethernet address.</span>00034 <span class="keyword">struct </span>netEthAddr00035 {00036 uint8_t addr[6];00037 } <a class="code" href="group__dhcp.html#ga41">GNUC_PACKED</a>;00038 00039 <span class="comment">// The Ethernet header</span>00040 <span class="keyword">struct </span>netEthHeader00041 {00042 <span class="keyword">struct </span>netEthAddr dest;00043 <span class="keyword">struct </span>netEthAddr src;00044 uint16_t type;00045 } <a class="code" href="group__dhcp.html#ga41">GNUC_PACKED</a>;00046 00047 <span class="preprocessor">#define ETH_HEADER_LEN 14</span>00048 <span class="preprocessor"></span>00049 <span class="preprocessor">#define ETHTYPE_ARP 0x0806</span>00050 <span class="preprocessor"></span><span class="preprocessor">#define ETHTYPE_IP 0x0800</span>00051 <span class="preprocessor"></span><span class="preprocessor">#define ETHTYPE_IP6 0x86dd </span>00052 <span class="preprocessor"></span>00053 <span class="comment">// The ARP header</span>00054 <span class="keyword">struct </span>netArpHeader00055 {00056 uint16_t hwtype;00057 uint16_t protocol;00058 uint8_t hwlen;00059 uint8_t protolen;00060 uint16_t opcode;00061 <span class="keyword">struct </span>netEthAddr shwaddr;00062 uint32_t sipaddr;00063 <span class="keyword">struct </span>netEthAddr dhwaddr;00064 uint32_t dipaddr; 00065 } <a class="code" href="group__dhcp.html#ga41">GNUC_PACKED</a>;00066 00067 <span class="preprocessor">#define ARP_OPCODE_REQUEST 1</span>00068 <span class="preprocessor"></span><span class="preprocessor">#define ARP_OPCODE_REPLY 2</span>00069 <span class="preprocessor"></span><span class="preprocessor">#define ARP_HWTYPE_ETH 1</span>00070 <span class="preprocessor"></span>00071 <span class="comment">// The IP header</span>00072 <span class="keyword">struct </span>netIpHeader00073 {00074 uint8_t vhl;00075 uint8_t tos;00076 uint16_t len;00077 uint16_t ipid;00078 uint16_t ipoffset;00079 uint8_t ttl;00080 uint8_t proto;00081 uint16_t ipchksum;00082 uint32_t srcipaddr;00083 uint32_t destipaddr;00084 } <a class="code" href="group__dhcp.html#ga41">GNUC_PACKED</a>;00085 <span class="preprocessor">#define IP_HEADER_LEN 20</span>00086 <span class="preprocessor"></span>00087 <span class="preprocessor">#define IP_PROTO_ICMP 1</span>00088 <span class="preprocessor"></span><span class="preprocessor">#define IP_PROTO_TCP 6</span>00089 <span class="preprocessor"></span><span class="preprocessor">#define IP_PROTO_UDP 17</span>00090 <span class="preprocessor"></span>00091 <span class="comment">// The ICMP header</span>00092 <span class="keyword">struct </span>netIcmpHeader00093 {00094 uint8_t type;00095 uint8_t icode;00096 uint16_t icmpchksum;00097 uint16_t id;00098 uint16_t seqno;00099 } <a class="code" href="group__dhcp.html#ga41">GNUC_PACKED</a>;00100 <span class="preprocessor">#define ICMP_HEADER_LEN 8</span>00101 <span class="preprocessor"></span>00102 <span class="preprocessor">#define ICMP_TYPE_ECHOREPLY 0</span>00103 <span class="preprocessor"></span><span class="preprocessor">#define ICMP_TYPE_ECHOREQUEST 8</span>00104 <span class="preprocessor"></span>00105 <span class="comment">// The UDP header</span>00106 <span class="keyword">struct </span>netUdpHeader00107 {00108 uint16_t srcport;00109 uint16_t destport;00110 uint16_t udplen;00111 uint16_t udpchksum;00112 } <a class="code" href="group__dhcp.html#ga41">GNUC_PACKED</a>;00113 <span class="preprocessor">#define UDP_HEADER_LEN 8</span>00114 <span class="preprocessor"></span>00115 <span class="comment">// The TCP header</span>00116 <span class="keyword">struct </span>netTcpHeader00117 {00118 uint16_t srcport;00119 uint16_t destport;00120 uint32_t seqno;00121 uint32_t ackno;00122 uint8_t tcpoffset;00123 uint8_t flags;00124 uint16_t wnd;00125 uint16_t tcpchksum;00126 uint16_t urgp;00127 <span class="comment">// uint8_t optdata[4];</span>00128 } <a class="code" href="group__dhcp.html#ga41">GNUC_PACKED</a>;00129 <span class="preprocessor">#define TCP_HEADER_LEN 20</span>00130 <span class="preprocessor"></span>00131 <span class="preprocessor">#define TCP_FLAGS_FIN 0x01</span>00132 <span class="preprocessor"></span><span class="preprocessor">#define TCP_FLAGS_SYN 0x02</span>00133 <span class="preprocessor"></span><span class="preprocessor">#define TCP_FLAGS_RST 0x04</span>00134 <span class="preprocessor"></span><span class="preprocessor">#define TCP_FLAGS_PSH 0x08</span>00135 <span class="preprocessor"></span><span class="preprocessor">#define TCP_FLAGS_ACK 0x10</span>00136 <span class="preprocessor"></span><span class="preprocessor">#define TCP_FLAGS_URG 0x20</span>00137 <span class="preprocessor"></span>00138 <span class="comment">// Ethernet/ARP header</span>00139 <span class="keyword">struct </span>netEthArpHeader00140 {00141 <span class="keyword">struct </span>netEthHeader eth;00142 <span class="keyword">struct </span>netArpHeader arp;00143 } <a class="code" href="group__dhcp.html#ga41">GNUC_PACKED</a>;00144 00145 <span class="comment">// Ethernet/IP header</span>00146 <span class="keyword">struct </span>netEthIpHeader00147 {00148 <span class="keyword">struct </span>netEthHeader eth;00149 <span class="keyword">struct </span>netIpHeader ip;00150 } <a class="code" href="group__dhcp.html#ga41">GNUC_PACKED</a>;00151 00152 <span class="comment">// The IP header</span>00153 <span class="keyword">typedef</span> <span class="keyword">struct </span>netIpHeader ip_hdr;00154 00155 <span class="comment">// The IP/TCP headers</span>00156 <span class="keyword">typedef</span> <span class="keyword">struct</span>00157 <span class="keyword"></span>{00158 <span class="keyword">struct </span>netIpHeader ip;00159 <span class="keyword">struct </span>netTcpHeader tcp;00160 } tcpip_hdr;00161 00162 <span class="comment">// The IP/ICMP headers</span>00163 <span class="keyword">typedef</span> <span class="keyword">struct </span>{00164 <span class="keyword">struct </span>netIpHeader ip;00165 <span class="keyword">struct </span>netIcmpHeader icmp;00166 } icmpip_hdr;00167 00168 00169 <span class="comment">// The UDP and IP headers</span>00170 <span class="keyword">typedef</span> <span class="keyword">struct </span>{00171 <span class="keyword">struct </span>netIpHeader ip;00172 <span class="keyword">struct </span>netUdpHeader udp;00173 } udpip_hdr;00174 00175 <span class="comment"></span>00176 <span class="comment">//! Convert dot-notation IP address into 32-bit word.</span>00177 <span class="comment">/// Example: IPDOT(192l,168l,1l,1l)</span><a name="l00178"></a><a class="code" href="group__net.html#ga32">00178</a> <span class="comment"></span><span class="preprocessor">#define IPDOT(a,b,c,d) ((a<<24)|(b<<16)|(c<<8)|(d))</span>00179 <span class="preprocessor"></span><span class="comment"></span>00180 <span class="comment">//! Host-to-Network SHORT (16-bit) byte-order swap (macro).</span><a name="l00181"></a><a class="code" href="group__net.html#ga33">00181</a> <span class="comment"></span><span class="preprocessor">#define HTONS(s) ((s<<8) | (s>>8))</span>00182 <span class="preprocessor"></span><span class="comment">//! Host-to-Network LONG (32-bit) byte-order swap (macro).</span><a name="l00183"></a><a class="code" href="group__net.html#ga34">00183</a> <span class="comment"></span><span class="preprocessor">#define HTONL(l) ((l<<24) | ((l&0x00FF0000l)>>8) | ((l&0x0000FF00l)<<8) | (l>>24))</span>00184 <span class="preprocessor"></span><span class="comment"></span>00185 <span class="comment">//! Host-to-Network SHORT (16-bit) byte-order swap (function).</span>00186 <span class="comment"></span>uint16_t <a class="code" href="group__net.html#ga2">htons</a>(uint16_t val);<span class="comment"></span>00187 <span class="comment">//! Host-to-Network LONG (32-bit) byte-order swap (function).</span>00188 <span class="comment"></span>uint32_t <a class="code" href="group__net.html#ga3">htonl</a>(uint32_t val);00189 <span class="comment"></span>00190 <span class="comment">//! Calculate IP-style checksum from data.</span>00191 <span class="comment"></span>uint16_t <a class="code" href="group__net.html#ga4">netChecksum</a>(<span class="keywordtype">void</span> *data, uint16_t len);00192 <span class="comment"></span>00193 <span class="comment">//! Print Ethernet address in XX:XX:XX:XX:XX:XX format.</span>00194 <span class="comment"></span><span class="keywordtype">void</span> <a class="code" href="group__net.html#ga5">netPrintEthAddr</a>(<span class="keyword">struct</span> netEthAddr* ethaddr);<span class="comment"></span>00195 <span class="comment">//! Print IP address in dot notation.</span>00196 <span class="comment"></span><span class="keywordtype">void</span> <a class="code" href="group__net.html#ga6">netPrintIPAddr</a>(uint32_t ipaddr);<span class="comment"></span>00197 <span class="comment">//! Print Ethernet header information.</span>00198 <span class="comment"></span><span class="keywordtype">void</span> <a class="code" href="group__net.html#ga7">netPrintEthHeader</a>(<span class="keyword">struct</span> netEthHeader* eth_hdr);<span class="comment"></span>00199 <span class="comment">//! Print IP header information.</span>00200 <span class="comment"></span><span class="keywordtype">void</span> <a class="code" href="group__net.html#ga8">netPrintIpHeader</a>(<span class="keyword">struct</span> netIpHeader* ipheader);<span class="comment"></span>00201 <span class="comment">//! Print TCP header information.</span>00202 <span class="comment"></span><span class="keywordtype">void</span> <a class="code" href="group__net.html#ga9">netPrintTcpHeader</a>(<span class="keyword">struct</span> netTcpHeader* tcpheader);00203 00204 <span class="preprocessor">#endif</span>00205 <span class="preprocessor"></span><span class="comment">//@}</span>00206 <span class="comment"></span></pre></div><hr size="1"><address style="align: right;"><small>Generated on Sun Oct 29 03:41:07 2006 for Procyon AVRlib by <a href="http://www.doxygen.org/index.html"><img src="doxygen.png" alt="doxygen" align="middle" border="0"></a> 1.4.2 </small></address></body></html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -