File:  [ELWIX - Embedded LightWeight unIX -] / embedaddon / libnet / doc / html / libnet-macros_8h_source.html
Revision 1.1.1.1 (vendor branch): download - view: text, annotated - select for diffs - revision graph
Mon Jul 22 11:54:41 2013 UTC (11 years, 5 months ago) by misho
Branches: libnet, MAIN
CVS tags: v1_1_6p5, v1_1_6p4, v1_1_6p0, v1_1_6, HEAD
1.1.6

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<title>libnet: libnet-macros.h Source File</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>
<link href="doxygen.css" rel="stylesheet" type="text/css"/>
</head>
<body>
<!-- Generated by Doxygen 1.7.4 -->
<div id="top">
<div id="titlearea">
<table cellspacing="0" cellpadding="0">
 <tbody>
 <tr style="height: 56px;">
  <td style="padding-left: 0.5em;">
   <div id="projectname">libnet&#160;<span id="projectnumber">1.1</span></div>
  </td>
 </tr>
 </tbody>
</table>
</div>
  <div id="navrow1" class="tabs">
    <ul class="tablist">
      <li><a href="index.html"><span>Main&#160;Page</span></a></li>
      <li class="current"><a href="files.html"><span>Files</span></a></li>
    </ul>
  </div>
  <div id="navrow2" class="tabs2">
    <ul class="tablist">
      <li><a href="files.html"><span>File&#160;List</span></a></li>
      <li><a href="globals.html"><span>Globals</span></a></li>
    </ul>
  </div>
<div class="header">
  <div class="headertitle">
<div class="title">libnet-macros.h</div>  </div>
</div>
<div class="contents">
<a href="libnet-macros_8h.html">Go to the documentation of this file.</a><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/*</span>
<a name="l00002"></a>00002 <span class="comment"> *  $Id: libnet-macros_8h_source.html,v 1.1.1.1 2013/07/22 11:54:41 misho Exp $</span>
<a name="l00003"></a>00003 <span class="comment"> *</span>
<a name="l00004"></a>00004 <span class="comment"> *  libnet-macros.h - Network routine library macro header file</span>
<a name="l00005"></a>00005 <span class="comment"> *</span>
<a name="l00006"></a>00006 <span class="comment"> *  Copyright (c) 1998 - 2004 Mike D. Schiffman &lt;mike@infonexus.com&gt;</span>
<a name="l00007"></a>00007 <span class="comment"> *  All rights reserved.</span>
<a name="l00008"></a>00008 <span class="comment"> *</span>
<a name="l00009"></a>00009 <span class="comment"> * Redistribution and use in source and binary forms, with or without</span>
<a name="l00010"></a>00010 <span class="comment"> * modification, are permitted provided that the following conditions</span>
<a name="l00011"></a>00011 <span class="comment"> * are met:</span>
<a name="l00012"></a>00012 <span class="comment"> * 1. Redistributions of source code must retain the above copyright</span>
<a name="l00013"></a>00013 <span class="comment"> *    notice, this list of conditions and the following disclaimer.</span>
<a name="l00014"></a>00014 <span class="comment"> * 2. Redistributions in binary form must reproduce the above copyright</span>
<a name="l00015"></a>00015 <span class="comment"> *    notice, this list of conditions and the following disclaimer in the</span>
<a name="l00016"></a>00016 <span class="comment"> *    documentation and/or other materials provided with the distribution.</span>
<a name="l00017"></a>00017 <span class="comment"> *</span>
<a name="l00018"></a>00018 <span class="comment"> * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS&#39;&#39; AND</span>
<a name="l00019"></a>00019 <span class="comment"> * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE</span>
<a name="l00020"></a>00020 <span class="comment"> * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE</span>
<a name="l00021"></a>00021 <span class="comment"> * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE</span>
<a name="l00022"></a>00022 <span class="comment"> * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL</span>
<a name="l00023"></a>00023 <span class="comment"> * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS</span>
<a name="l00024"></a>00024 <span class="comment"> * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)</span>
<a name="l00025"></a>00025 <span class="comment"> * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT</span>
<a name="l00026"></a>00026 <span class="comment"> * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY</span>
<a name="l00027"></a>00027 <span class="comment"> * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF</span>
<a name="l00028"></a>00028 <span class="comment"> * SUCH DAMAGE.</span>
<a name="l00029"></a>00029 <span class="comment"> *</span>
<a name="l00030"></a>00030 <span class="comment"> */</span>
<a name="l00031"></a>00031 
<a name="l00032"></a>00032 <span class="preprocessor">#ifndef __LIBNET_MACROS_H</span>
<a name="l00033"></a>00033 <span class="preprocessor"></span><span class="preprocessor">#define __LIBNET_MACROS_H</span>
<a name="l00034"></a>00034 <span class="preprocessor"></span>
<a name="l00039"></a>00039 <span class="comment">/* for systems without snprintf */</span>
<a name="l00040"></a>00040 <span class="preprocessor">#if defined(NO_SNPRINTF)</span>
<a name="l00041"></a>00041 <span class="preprocessor"></span><span class="preprocessor">#define snprintf(buf, len, args...) sprintf(buf, ##args)</span>
<a name="l00042"></a>00042 <span class="preprocessor"></span><span class="preprocessor">#endif</span>
<a name="l00043"></a>00043 <span class="preprocessor"></span>
<a name="l00044"></a>00044 
<a name="l00049"></a><a class="code" href="libnet-macros_8h.html#ac67cb6e9b00fd492cc3a9247e9477d87">00049</a> <span class="preprocessor">#define LIBNET_DONT_RESOLVE 0</span>
<a name="l00050"></a>00050 <span class="preprocessor"></span>
<a name="l00055"></a><a class="code" href="libnet-macros_8h.html#a6733960f6981f1930b2d1a489df89cc7">00055</a> <span class="preprocessor">#define LIBNET_RESOLVE      1</span>
<a name="l00056"></a>00056 <span class="preprocessor"></span>
<a name="l00060"></a><a class="code" href="libnet-macros_8h.html#a5ff9536ca9bbe6f73f69bec817962742">00060</a> <span class="preprocessor">#define LIBNET_ON   0</span>
<a name="l00061"></a>00061 <span class="preprocessor"></span>
<a name="l00065"></a><a class="code" href="libnet-macros_8h.html#af87da67c016a9791d256c2d71bf0b0ac">00065</a> <span class="preprocessor">#define LIBNET_OFF  1</span>
<a name="l00066"></a>00066 <span class="preprocessor"></span>
<a name="l00070"></a>00070 <span class="preprocessor">#ifndef IN6ADDR_ERROR_INIT</span>
<a name="l00071"></a><a class="code" href="libnet-macros_8h.html#a9c76fe8da8e411fe1db9f75583dc1b8a">00071</a> <span class="preprocessor"></span><span class="preprocessor">#define IN6ADDR_ERROR_INIT { { { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, \</span>
<a name="l00072"></a>00072 <span class="preprocessor">                                 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, \</span>
<a name="l00073"></a>00073 <span class="preprocessor">                                 0xff, 0xff } } }</span>
<a name="l00074"></a>00074 <span class="preprocessor"></span><span class="preprocessor">#endif</span>
<a name="l00075"></a>00075 <span class="preprocessor"></span>
<a name="l00079"></a><a class="code" href="libnet-macros_8h.html#a96a6017948aa76e5a5d415c3227348df">00079</a> <span class="preprocessor">#define LIBNET_PR2          0</span>
<a name="l00080"></a>00080 <span class="preprocessor"></span><span class="preprocessor">#define LIBNET_PR8          1</span>
<a name="l00081"></a>00081 <span class="preprocessor"></span><span class="preprocessor">#define LIBNET_PR16         2</span>
<a name="l00082"></a>00082 <span class="preprocessor"></span><span class="preprocessor">#define LIBNET_PRu16        3</span>
<a name="l00083"></a>00083 <span class="preprocessor"></span><span class="preprocessor">#define LIBNET_PR32         4</span>
<a name="l00084"></a>00084 <span class="preprocessor"></span><span class="preprocessor">#define LIBNET_PRu32        5</span>
<a name="l00085"></a>00085 <span class="preprocessor"></span><span class="preprocessor">#define LIBNET_PRAND_MAX    0xffffffff</span>
<a name="l00086"></a>00086 <span class="preprocessor"></span>
<a name="l00090"></a><a class="code" href="libnet-macros_8h.html#ac7301c95aa36d66e8904979650b5189d">00090</a> <span class="preprocessor">#define LIBNET_MAX_PACKET   0xffff</span>
<a name="l00091"></a>00091 <span class="preprocessor"></span><span class="preprocessor">#ifndef IP_MAXPACKET</span>
<a name="l00092"></a>00092 <span class="preprocessor"></span><span class="preprocessor">#define IP_MAXPACKET        0xffff</span>
<a name="l00093"></a>00093 <span class="preprocessor"></span><span class="preprocessor">#endif</span>
<a name="l00094"></a>00094 <span class="preprocessor"></span>
<a name="l00095"></a>00095 
<a name="l00096"></a>00096 <span class="comment">/* ethernet addresses are 6 octets long */</span>
<a name="l00097"></a>00097 <span class="preprocessor">#ifndef ETHER_ADDR_LEN</span>
<a name="l00098"></a>00098 <span class="preprocessor"></span><span class="preprocessor">#define ETHER_ADDR_LEN      0x6</span>
<a name="l00099"></a>00099 <span class="preprocessor"></span><span class="preprocessor">#endif</span>
<a name="l00100"></a>00100 <span class="preprocessor"></span>
<a name="l00101"></a>00101 <span class="comment">/* FDDI addresses are 6 octets long */</span>
<a name="l00102"></a>00102 <span class="preprocessor">#ifndef FDDI_ADDR_LEN</span>
<a name="l00103"></a>00103 <span class="preprocessor"></span><span class="preprocessor">#define FDDI_ADDR_LEN       0x6</span>
<a name="l00104"></a>00104 <span class="preprocessor"></span><span class="preprocessor">#endif</span>
<a name="l00105"></a>00105 <span class="preprocessor"></span>
<a name="l00106"></a>00106 <span class="comment">/* token ring addresses are 6 octets long */</span>
<a name="l00107"></a>00107 <span class="preprocessor">#ifndef TOKEN_RING_ADDR_LEN</span>
<a name="l00108"></a>00108 <span class="preprocessor"></span><span class="preprocessor">#define TOKEN_RING_ADDR_LEN 0x6</span>
<a name="l00109"></a>00109 <span class="preprocessor"></span><span class="preprocessor">#endif</span>
<a name="l00110"></a>00110 <span class="preprocessor"></span>
<a name="l00111"></a>00111 <span class="comment">/* LLC Organization Code is 3 bytes long */</span>
<a name="l00112"></a>00112 <span class="preprocessor">#define LIBNET_ORG_CODE_SIZE  0x3</span>
<a name="l00113"></a>00113 <span class="preprocessor"></span>
<a name="l00117"></a><a class="code" href="libnet-macros_8h.html#a2d720375e2ef5a85a62d6069283a5223">00117</a> <span class="preprocessor">#define LIBNET_ERRBUF_SIZE      0x100</span>
<a name="l00118"></a>00118 <span class="preprocessor"></span>
<a name="l00122"></a><a class="code" href="libnet-macros_8h.html#ae9cd154f8cb482809ee456b6ac43dea5">00122</a> <span class="preprocessor">#define LIBNET_MAXOPTION_SIZE   0x28</span>
<a name="l00123"></a>00123 <span class="preprocessor"></span>
<a name="l00124"></a>00124 <span class="comment">/* some BSD variants have this endianess problem */</span>
<a name="l00125"></a>00125 <span class="preprocessor">#if (LIBNET_BSD_BYTE_SWAP)</span>
<a name="l00126"></a>00126 <span class="preprocessor"></span><span class="preprocessor">#define FIX(n)      ntohs(n)</span>
<a name="l00127"></a>00127 <span class="preprocessor"></span><span class="preprocessor">#define UNFIX(n)    htons(n)</span>
<a name="l00128"></a>00128 <span class="preprocessor"></span><span class="preprocessor">#else</span>
<a name="l00129"></a>00129 <span class="preprocessor"></span><span class="preprocessor">#define FIX(n)      (n)</span>
<a name="l00130"></a>00130 <span class="preprocessor"></span><span class="preprocessor">#define UNFIX(n)    (n)</span>
<a name="l00131"></a>00131 <span class="preprocessor"></span><span class="preprocessor">#endif</span>
<a name="l00132"></a>00132 <span class="preprocessor"></span>
<a name="l00133"></a>00133 <span class="comment">/* used internally for packet builders */</span>
<a name="l00134"></a>00134 <span class="preprocessor">#define LIBNET_DO_PAYLOAD(l, p)                                              \</span>
<a name="l00135"></a>00135 <span class="preprocessor">if (payload_s &amp;&amp; !payload)                                                   \</span>
<a name="l00136"></a>00136 <span class="preprocessor">{                                                                            \</span>
<a name="l00137"></a>00137 <span class="preprocessor">    snprintf(l-&gt;err_buf, LIBNET_ERRBUF_SIZE,                                 \</span>
<a name="l00138"></a>00138 <span class="preprocessor">            &quot;%s(): payload inconsistency\n&quot;, __func__);                      \</span>
<a name="l00139"></a>00139 <span class="preprocessor">    goto bad;                                                                \</span>
<a name="l00140"></a>00140 <span class="preprocessor">}                                                                            \</span>
<a name="l00141"></a>00141 <span class="preprocessor">if (payload_s)                                                               \</span>
<a name="l00142"></a>00142 <span class="preprocessor">{                                                                            \</span>
<a name="l00143"></a>00143 <span class="preprocessor">    n = libnet_pblock_append(l, p, payload, payload_s);                      \</span>
<a name="l00144"></a>00144 <span class="preprocessor">    if (n == (uint32_t) - 1)                                                 \</span>
<a name="l00145"></a>00145 <span class="preprocessor">    {                                                                        \</span>
<a name="l00146"></a>00146 <span class="preprocessor">        goto bad;                                                            \</span>
<a name="l00147"></a>00147 <span class="preprocessor">    }                                                                        \</span>
<a name="l00148"></a>00148 <span class="preprocessor">}                                                                            \</span>
<a name="l00149"></a>00149 <span class="preprocessor"></span>
<a name="l00150"></a>00150 <span class="preprocessor"></span>
<a name="l00151"></a>00151 <span class="comment">/* used internally for checksum stuff */</span>
<a name="l00152"></a>00152 <span class="preprocessor">#define LIBNET_CKSUM_CARRY(x) \</span>
<a name="l00153"></a>00153 <span class="preprocessor">    (x = (x &gt;&gt; 16) + (x &amp; 0xffff), (~(x + (x &gt;&gt; 16)) &amp; 0xffff))</span>
<a name="l00154"></a>00154 <span class="preprocessor"></span>
<a name="l00155"></a>00155 <span class="comment">/* used interally for OSPF stuff */</span>
<a name="l00156"></a>00156 <span class="preprocessor">#define LIBNET_OSPF_AUTHCPY(x, y) \</span>
<a name="l00157"></a>00157 <span class="preprocessor">    memcpy((uint8_t *)x, (uint8_t *)y, sizeof(y))</span>
<a name="l00158"></a>00158 <span class="preprocessor"></span><span class="preprocessor">#define LIBNET_OSPF_CKSUMBUF(x, y) \</span>
<a name="l00159"></a>00159 <span class="preprocessor">    memcpy((uint8_t *)x, (uint8_t *)y, sizeof(y))  </span>
<a name="l00160"></a>00160 <span class="preprocessor"></span>
<a name="l00161"></a>00161 <span class="comment">/* used internally for NTP leap indicator, version, and mode */</span>
<a name="l00162"></a>00162 <span class="preprocessor">#define LIBNET_NTP_DO_LI_VN_MODE(li, vn, md) \</span>
<a name="l00163"></a>00163 <span class="preprocessor">    ((uint8_t)((((li) &lt;&lt; 6) &amp; 0xc0) | (((vn) &lt;&lt; 3) &amp; 0x38) | ((md) &amp; 0x7)))</span>
<a name="l00164"></a>00164 <span class="preprocessor"></span>
<a name="l00165"></a>00165 <span class="comment">/* Not all systems have IFF_LOOPBACK */</span>
<a name="l00166"></a>00166 <span class="preprocessor">#ifdef IFF_LOOPBACK</span>
<a name="l00167"></a>00167 <span class="preprocessor"></span><span class="preprocessor">#define LIBNET_ISLOOPBACK(p) ((p)-&gt;ifr_flags &amp; IFF_LOOPBACK)</span>
<a name="l00168"></a>00168 <span class="preprocessor"></span><span class="preprocessor">#else</span>
<a name="l00169"></a>00169 <span class="preprocessor"></span><span class="preprocessor">#define LIBNET_ISLOOPBACK(p) (strcmp((p)-&gt;ifr_name, &quot;lo&quot;) == 0)</span>
<a name="l00170"></a>00170 <span class="preprocessor"></span><span class="preprocessor">#endif</span>
<a name="l00171"></a>00171 <span class="preprocessor"></span>
<a name="l00172"></a>00172 <span class="comment">/* advanced mode check */</span>
<a name="l00173"></a>00173 <span class="preprocessor">#define LIBNET_ISADVMODE(x) (x &amp; 0x08)</span>
<a name="l00174"></a>00174 <span class="preprocessor"></span>
<a name="l00175"></a>00175 <span class="comment">/* context queue macros and constants */</span>
<a name="l00176"></a>00176 <span class="preprocessor">#define LIBNET_LABEL_SIZE   64</span>
<a name="l00177"></a>00177 <span class="preprocessor"></span><span class="preprocessor">#define LIBNET_LABEL_DEFAULT &quot;cardshark&quot;</span>
<a name="l00178"></a>00178 <span class="preprocessor"></span><span class="preprocessor">#define CQ_LOCK_UNLOCKED    (u_int)0x00000000</span>
<a name="l00179"></a>00179 <span class="preprocessor"></span><span class="preprocessor">#define CQ_LOCK_READ        (u_int)0x00000001</span>
<a name="l00180"></a>00180 <span class="preprocessor"></span><span class="preprocessor">#define CQ_LOCK_WRITE       (u_int)0x00000002</span>
<a name="l00181"></a>00181 <span class="preprocessor"></span>
<a name="l00187"></a><a class="code" href="libnet-macros_8h.html#af36eb84eee10c525720134cfadb50a3e">00187</a> <span class="preprocessor">#define for_each_context_in_cq(l) \</span>
<a name="l00188"></a>00188 <span class="preprocessor">    for (l = libnet_cq_head(); libnet_cq_last(); l = libnet_cq_next())</span>
<a name="l00189"></a>00189 <span class="preprocessor"></span>
<a name="l00190"></a>00190 <span class="comment">/* return 1 if write lock is set on cq */</span>
<a name="l00191"></a>00191 <span class="preprocessor">#define cq_is_wlocked() (l_cqd.cq_lock &amp; CQ_LOCK_WRITE)</span>
<a name="l00192"></a>00192 <span class="preprocessor"></span>
<a name="l00193"></a>00193 <span class="comment">/* return 1 if read lock is set on cq */</span>
<a name="l00194"></a>00194 <span class="preprocessor">#define cq_is_rlocked() (l_cqd.cq_lock &amp; CQ_LOCK_READ)</span>
<a name="l00195"></a>00195 <span class="preprocessor"></span>
<a name="l00196"></a>00196 <span class="comment">/* return 1 if any lock is set on cq */</span>
<a name="l00197"></a>00197 <span class="preprocessor">#define cq_is_locked() (l_cqd.cq_lock &amp; (CQ_LOCK_READ | CQ_LOCK_WRITE))</span>
<a name="l00198"></a>00198 <span class="preprocessor"></span>
<a name="l00199"></a>00199 <span class="comment">/* check if a context queue is locked */</span>
<a name="l00200"></a>00200 <span class="preprocessor">#define check_cq_lock(x) (l_cqd.cq_lock &amp; x)</span>
<a name="l00201"></a>00201 <span class="preprocessor"></span>
<a name="l00202"></a>00202 <span class="preprocessor">#endif  </span><span class="comment">/* __LIBNET_MACROS_H */</span>
<a name="l00203"></a>00203 
<a name="l00204"></a>00204 <span class="comment">/* EOF */</span>
</pre></div></div>
</div>
<hr class="footer"/><address class="footer"><small>Generated on Thu Mar 29 2012 14:19:18 for libnet by&#160;
<a href="http://www.doxygen.org/index.html">
<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.7.4 </small></address>
</body>
</html>

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>