| Line No. | Rev | Author | Line |
|---|---|---|---|
| 1 | 6 | kaklik | <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> |
| 2 | <html><head><meta http-equiv="Content-Type" content="text/html;charset=iso-8859-1"> |
||
| 3 | <title>Procyon AVRlib: net/net.h Source File</title> |
||
| 4 | <link href="dox.css" rel="stylesheet" type="text/css"> |
||
| 5 | </head><body> |
||
| 6 | <!-- Generated by Doxygen 1.4.2 --> |
||
| 7 | <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> |
||
| 8 | <div class="nav"> |
||
| 9 | <a class="el" href="dir_000001.html">net</a></div> |
||
| 10 | <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> |
||
| 11 | 00002 <span class="comment">//*****************************************************************************</span> |
||
| 12 | 00003 <span class="comment">//</span> |
||
| 13 | 00004 <span class="comment">// File Name : 'net.h'</span> |
||
| 14 | 00005 <span class="comment">// Title : Network support library</span> |
||
| 15 | 00006 <span class="comment">// Author : Pascal Stang</span> |
||
| 16 | 00007 <span class="comment">// Created : 8/30/2004</span> |
||
| 17 | 00008 <span class="comment">// Revised : 7/3/2005</span> |
||
| 18 | 00009 <span class="comment">// Version : 0.1</span> |
||
| 19 | 00010 <span class="comment">// Target MCU : Atmel AVR series</span> |
||
| 20 | 00011 <span class="comment">// Editor Tabs : 4</span> |
||
| 21 | 00012 <span class="comment">//</span><span class="comment"></span> |
||
| 22 | 00013 <span class="comment">/// \ingroup network</span> |
||
| 23 | 00014 <span class="comment">/// \defgroup net Network support library (net.c)</span> |
||
| 24 | 00015 <span class="comment">/// \code #include "net/net.h" \endcode</span> |
||
| 25 | 00016 <span class="comment">/// \par Description</span> |
||
| 26 | 00017 <span class="comment">/// This is a general network support library including a multitude of </span> |
||
| 27 | 00018 <span class="comment">/// structure definitions for various types of network packets, functions</span> |
||
| 28 | 00019 <span class="comment">/// and macros for switching byte order, and an RFC-compliant function</span> |
||
| 29 | 00020 <span class="comment">/// for calculating checksums.</span> |
||
| 30 | 00021 <span class="comment"></span><span class="comment">//</span> |
||
| 31 | 00022 <span class="comment">// This code is distributed under the GNU Public License</span> |
||
| 32 | 00023 <span class="comment">// which can be found at http://www.gnu.org/licenses/gpl.txt</span> |
||
| 33 | 00024 <span class="comment">//*****************************************************************************</span><span class="comment"></span> |
||
| 34 | 00025 <span class="comment">//@{</span> |
||
| 35 | 00026 <span class="comment"></span> |
||
| 36 | 00027 <span class="preprocessor">#ifndef NET_H</span> |
||
| 37 | 00028 <span class="preprocessor"></span><span class="preprocessor">#define NET_H</span> |
||
| 38 | 00029 <span class="preprocessor"></span> |
||
| 39 | 00030 <span class="preprocessor">#include <inttypes.h></span> |
||
| 40 | 00031 <span class="preprocessor">#include "<a class="code" href="global_8h.html">global.h</a>"</span> |
||
| 41 | 00032 |
||
| 42 | 00033 <span class="comment">// Representation of a 48-bit Ethernet address.</span> |
||
| 43 | 00034 <span class="keyword">struct </span>netEthAddr |
||
| 44 | 00035 { |
||
| 45 | 00036 uint8_t addr[6]; |
||
| 46 | 00037 } <a class="code" href="group__dhcp.html#ga41">GNUC_PACKED</a>; |
||
| 47 | 00038 |
||
| 48 | 00039 <span class="comment">// The Ethernet header</span> |
||
| 49 | 00040 <span class="keyword">struct </span>netEthHeader |
||
| 50 | 00041 { |
||
| 51 | 00042 <span class="keyword">struct </span>netEthAddr dest; |
||
| 52 | 00043 <span class="keyword">struct </span>netEthAddr src; |
||
| 53 | 00044 uint16_t type; |
||
| 54 | 00045 } <a class="code" href="group__dhcp.html#ga41">GNUC_PACKED</a>; |
||
| 55 | 00046 |
||
| 56 | 00047 <span class="preprocessor">#define ETH_HEADER_LEN 14</span> |
||
| 57 | 00048 <span class="preprocessor"></span> |
||
| 58 | 00049 <span class="preprocessor">#define ETHTYPE_ARP 0x0806</span> |
||
| 59 | 00050 <span class="preprocessor"></span><span class="preprocessor">#define ETHTYPE_IP 0x0800</span> |
||
| 60 | 00051 <span class="preprocessor"></span><span class="preprocessor">#define ETHTYPE_IP6 0x86dd </span> |
||
| 61 | 00052 <span class="preprocessor"></span> |
||
| 62 | 00053 <span class="comment">// The ARP header</span> |
||
| 63 | 00054 <span class="keyword">struct </span>netArpHeader |
||
| 64 | 00055 { |
||
| 65 | 00056 uint16_t hwtype; |
||
| 66 | 00057 uint16_t protocol; |
||
| 67 | 00058 uint8_t hwlen; |
||
| 68 | 00059 uint8_t protolen; |
||
| 69 | 00060 uint16_t opcode; |
||
| 70 | 00061 <span class="keyword">struct </span>netEthAddr shwaddr; |
||
| 71 | 00062 uint32_t sipaddr; |
||
| 72 | 00063 <span class="keyword">struct </span>netEthAddr dhwaddr; |
||
| 73 | 00064 uint32_t dipaddr; |
||
| 74 | 00065 } <a class="code" href="group__dhcp.html#ga41">GNUC_PACKED</a>; |
||
| 75 | 00066 |
||
| 76 | 00067 <span class="preprocessor">#define ARP_OPCODE_REQUEST 1</span> |
||
| 77 | 00068 <span class="preprocessor"></span><span class="preprocessor">#define ARP_OPCODE_REPLY 2</span> |
||
| 78 | 00069 <span class="preprocessor"></span><span class="preprocessor">#define ARP_HWTYPE_ETH 1</span> |
||
| 79 | 00070 <span class="preprocessor"></span> |
||
| 80 | 00071 <span class="comment">// The IP header</span> |
||
| 81 | 00072 <span class="keyword">struct </span>netIpHeader |
||
| 82 | 00073 { |
||
| 83 | 00074 uint8_t vhl; |
||
| 84 | 00075 uint8_t tos; |
||
| 85 | 00076 uint16_t len; |
||
| 86 | 00077 uint16_t ipid; |
||
| 87 | 00078 uint16_t ipoffset; |
||
| 88 | 00079 uint8_t ttl; |
||
| 89 | 00080 uint8_t proto; |
||
| 90 | 00081 uint16_t ipchksum; |
||
| 91 | 00082 uint32_t srcipaddr; |
||
| 92 | 00083 uint32_t destipaddr; |
||
| 93 | 00084 } <a class="code" href="group__dhcp.html#ga41">GNUC_PACKED</a>; |
||
| 94 | 00085 <span class="preprocessor">#define IP_HEADER_LEN 20</span> |
||
| 95 | 00086 <span class="preprocessor"></span> |
||
| 96 | 00087 <span class="preprocessor">#define IP_PROTO_ICMP 1</span> |
||
| 97 | 00088 <span class="preprocessor"></span><span class="preprocessor">#define IP_PROTO_TCP 6</span> |
||
| 98 | 00089 <span class="preprocessor"></span><span class="preprocessor">#define IP_PROTO_UDP 17</span> |
||
| 99 | 00090 <span class="preprocessor"></span> |
||
| 100 | 00091 <span class="comment">// The ICMP header</span> |
||
| 101 | 00092 <span class="keyword">struct </span>netIcmpHeader |
||
| 102 | 00093 { |
||
| 103 | 00094 uint8_t type; |
||
| 104 | 00095 uint8_t icode; |
||
| 105 | 00096 uint16_t icmpchksum; |
||
| 106 | 00097 uint16_t id; |
||
| 107 | 00098 uint16_t seqno; |
||
| 108 | 00099 } <a class="code" href="group__dhcp.html#ga41">GNUC_PACKED</a>; |
||
| 109 | 00100 <span class="preprocessor">#define ICMP_HEADER_LEN 8</span> |
||
| 110 | 00101 <span class="preprocessor"></span> |
||
| 111 | 00102 <span class="preprocessor">#define ICMP_TYPE_ECHOREPLY 0</span> |
||
| 112 | 00103 <span class="preprocessor"></span><span class="preprocessor">#define ICMP_TYPE_ECHOREQUEST 8</span> |
||
| 113 | 00104 <span class="preprocessor"></span> |
||
| 114 | 00105 <span class="comment">// The UDP header</span> |
||
| 115 | 00106 <span class="keyword">struct </span>netUdpHeader |
||
| 116 | 00107 { |
||
| 117 | 00108 uint16_t srcport; |
||
| 118 | 00109 uint16_t destport; |
||
| 119 | 00110 uint16_t udplen; |
||
| 120 | 00111 uint16_t udpchksum; |
||
| 121 | 00112 } <a class="code" href="group__dhcp.html#ga41">GNUC_PACKED</a>; |
||
| 122 | 00113 <span class="preprocessor">#define UDP_HEADER_LEN 8</span> |
||
| 123 | 00114 <span class="preprocessor"></span> |
||
| 124 | 00115 <span class="comment">// The TCP header</span> |
||
| 125 | 00116 <span class="keyword">struct </span>netTcpHeader |
||
| 126 | 00117 { |
||
| 127 | 00118 uint16_t srcport; |
||
| 128 | 00119 uint16_t destport; |
||
| 129 | 00120 uint32_t seqno; |
||
| 130 | 00121 uint32_t ackno; |
||
| 131 | 00122 uint8_t tcpoffset; |
||
| 132 | 00123 uint8_t flags; |
||
| 133 | 00124 uint16_t wnd; |
||
| 134 | 00125 uint16_t tcpchksum; |
||
| 135 | 00126 uint16_t urgp; |
||
| 136 | 00127 <span class="comment">// uint8_t optdata[4];</span> |
||
| 137 | 00128 } <a class="code" href="group__dhcp.html#ga41">GNUC_PACKED</a>; |
||
| 138 | 00129 <span class="preprocessor">#define TCP_HEADER_LEN 20</span> |
||
| 139 | 00130 <span class="preprocessor"></span> |
||
| 140 | 00131 <span class="preprocessor">#define TCP_FLAGS_FIN 0x01</span> |
||
| 141 | 00132 <span class="preprocessor"></span><span class="preprocessor">#define TCP_FLAGS_SYN 0x02</span> |
||
| 142 | 00133 <span class="preprocessor"></span><span class="preprocessor">#define TCP_FLAGS_RST 0x04</span> |
||
| 143 | 00134 <span class="preprocessor"></span><span class="preprocessor">#define TCP_FLAGS_PSH 0x08</span> |
||
| 144 | 00135 <span class="preprocessor"></span><span class="preprocessor">#define TCP_FLAGS_ACK 0x10</span> |
||
| 145 | 00136 <span class="preprocessor"></span><span class="preprocessor">#define TCP_FLAGS_URG 0x20</span> |
||
| 146 | 00137 <span class="preprocessor"></span> |
||
| 147 | 00138 <span class="comment">// Ethernet/ARP header</span> |
||
| 148 | 00139 <span class="keyword">struct </span>netEthArpHeader |
||
| 149 | 00140 { |
||
| 150 | 00141 <span class="keyword">struct </span>netEthHeader eth; |
||
| 151 | 00142 <span class="keyword">struct </span>netArpHeader arp; |
||
| 152 | 00143 } <a class="code" href="group__dhcp.html#ga41">GNUC_PACKED</a>; |
||
| 153 | 00144 |
||
| 154 | 00145 <span class="comment">// Ethernet/IP header</span> |
||
| 155 | 00146 <span class="keyword">struct </span>netEthIpHeader |
||
| 156 | 00147 { |
||
| 157 | 00148 <span class="keyword">struct </span>netEthHeader eth; |
||
| 158 | 00149 <span class="keyword">struct </span>netIpHeader ip; |
||
| 159 | 00150 } <a class="code" href="group__dhcp.html#ga41">GNUC_PACKED</a>; |
||
| 160 | 00151 |
||
| 161 | 00152 <span class="comment">// The IP header</span> |
||
| 162 | 00153 <span class="keyword">typedef</span> <span class="keyword">struct </span>netIpHeader ip_hdr; |
||
| 163 | 00154 |
||
| 164 | 00155 <span class="comment">// The IP/TCP headers</span> |
||
| 165 | 00156 <span class="keyword">typedef</span> <span class="keyword">struct</span> |
||
| 166 | 00157 <span class="keyword"></span>{ |
||
| 167 | 00158 <span class="keyword">struct </span>netIpHeader ip; |
||
| 168 | 00159 <span class="keyword">struct </span>netTcpHeader tcp; |
||
| 169 | 00160 } tcpip_hdr; |
||
| 170 | 00161 |
||
| 171 | 00162 <span class="comment">// The IP/ICMP headers</span> |
||
| 172 | 00163 <span class="keyword">typedef</span> <span class="keyword">struct </span>{ |
||
| 173 | 00164 <span class="keyword">struct </span>netIpHeader ip; |
||
| 174 | 00165 <span class="keyword">struct </span>netIcmpHeader icmp; |
||
| 175 | 00166 } icmpip_hdr; |
||
| 176 | 00167 |
||
| 177 | 00168 |
||
| 178 | 00169 <span class="comment">// The UDP and IP headers</span> |
||
| 179 | 00170 <span class="keyword">typedef</span> <span class="keyword">struct </span>{ |
||
| 180 | 00171 <span class="keyword">struct </span>netIpHeader ip; |
||
| 181 | 00172 <span class="keyword">struct </span>netUdpHeader udp; |
||
| 182 | 00173 } udpip_hdr; |
||
| 183 | 00174 |
||
| 184 | 00175 <span class="comment"></span> |
||
| 185 | 00176 <span class="comment">//! Convert dot-notation IP address into 32-bit word.</span> |
||
| 186 | 00177 <span class="comment">/// Example: IPDOT(192l,168l,1l,1l)</span> |
||
| 187 | <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> |
||
| 188 | 00179 <span class="preprocessor"></span><span class="comment"></span> |
||
| 189 | 00180 <span class="comment">//! Host-to-Network SHORT (16-bit) byte-order swap (macro).</span> |
||
| 190 | <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> |
||
| 191 | 00182 <span class="preprocessor"></span><span class="comment">//! Host-to-Network LONG (32-bit) byte-order swap (macro).</span> |
||
| 192 | <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> |
||
| 193 | 00184 <span class="preprocessor"></span><span class="comment"></span> |
||
| 194 | 00185 <span class="comment">//! Host-to-Network SHORT (16-bit) byte-order swap (function).</span> |
||
| 195 | 00186 <span class="comment"></span>uint16_t <a class="code" href="group__net.html#ga2">htons</a>(uint16_t val);<span class="comment"></span> |
||
| 196 | 00187 <span class="comment">//! Host-to-Network LONG (32-bit) byte-order swap (function).</span> |
||
| 197 | 00188 <span class="comment"></span>uint32_t <a class="code" href="group__net.html#ga3">htonl</a>(uint32_t val); |
||
| 198 | 00189 <span class="comment"></span> |
||
| 199 | 00190 <span class="comment">//! Calculate IP-style checksum from data.</span> |
||
| 200 | 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); |
||
| 201 | 00192 <span class="comment"></span> |
||
| 202 | 00193 <span class="comment">//! Print Ethernet address in XX:XX:XX:XX:XX:XX format.</span> |
||
| 203 | 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> |
||
| 204 | 00195 <span class="comment">//! Print IP address in dot notation.</span> |
||
| 205 | 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> |
||
| 206 | 00197 <span class="comment">//! Print Ethernet header information.</span> |
||
| 207 | 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> |
||
| 208 | 00199 <span class="comment">//! Print IP header information.</span> |
||
| 209 | 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> |
||
| 210 | 00201 <span class="comment">//! Print TCP header information.</span> |
||
| 211 | 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); |
||
| 212 | 00203 |
||
| 213 | 00204 <span class="preprocessor">#endif</span> |
||
| 214 | 00205 <span class="preprocessor"></span><span class="comment">//@}</span> |
||
| 215 | 00206 <span class="comment"></span> |
||
| 216 | </pre></div><hr size="1"><address style="align: right;"><small>Generated on Sun Oct 29 03:41:07 2006 for Procyon AVRlib by |
||
| 217 | <a href="http://www.doxygen.org/index.html"> |
||
| 218 | <img src="doxygen.png" alt="doxygen" align="middle" border="0"></a> 1.4.2 </small></address> |
||
| 219 | </body> |
||
| 220 | </html> |
Powered by WebSVN v2.8.3