Sophie

Sophie

distrib > Mandriva > 2010.0 > i586 > media > contrib-release > by-pkgid > 29c369053a983cc5d8c880dc6e0a2237 > files > 522

libdtn-devel-2.6.0-2mdv2009.1.i586.rpm

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html><head><meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
<title>DTN Reference Implementation: RIBDTLV.cc 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.5.8 -->
<div class="navigation" id="top">
  <div class="tabs">
    <ul>
      <li><a href="main.html"><span>Main&nbsp;Page</span></a></li>
      <li><a href="namespaces.html"><span>Namespaces</span></a></li>
      <li><a href="annotated.html"><span>Classes</span></a></li>
      <li class="current"><a href="files.html"><span>Files</span></a></li>
    </ul>
  </div>
  <div class="tabs">
    <ul>
      <li><a href="files.html"><span>File&nbsp;List</span></a></li>
      <li><a href="globals.html"><span>File&nbsp;Members</span></a></li>
    </ul>
  </div>
<h1>RIBDTLV.cc</h1><a href="RIBDTLV_8cc.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"> *    Copyright 2007 Baylor University</span>
<a name="l00003"></a>00003 <span class="comment"> *</span>
<a name="l00004"></a>00004 <span class="comment"> *    Licensed under the Apache License, Version 2.0 (the "License");</span>
<a name="l00005"></a>00005 <span class="comment"> *    you may not use this file except in compliance with the License.</span>
<a name="l00006"></a>00006 <span class="comment"> *    You may obtain a copy of the License at</span>
<a name="l00007"></a>00007 <span class="comment"> *</span>
<a name="l00008"></a>00008 <span class="comment"> *        http://www.apache.org/licenses/LICENSE-2.0</span>
<a name="l00009"></a>00009 <span class="comment"> *</span>
<a name="l00010"></a>00010 <span class="comment"> *    Unless required by applicable law or agreed to in writing, software</span>
<a name="l00011"></a>00011 <span class="comment"> *    distributed under the License is distributed on an "AS IS" BASIS,</span>
<a name="l00012"></a>00012 <span class="comment"> *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.</span>
<a name="l00013"></a>00013 <span class="comment"> *    See the License for the specific language governing permissions and</span>
<a name="l00014"></a>00014 <span class="comment"> *    limitations under the License.</span>
<a name="l00015"></a>00015 <span class="comment"> */</span>
<a name="l00016"></a>00016 
<a name="l00017"></a>00017 <span class="preprocessor">#include &lt;arpa/inet.h&gt;</span> <span class="comment">// for hton[ls] and ntoh[ls]</span>
<a name="l00018"></a>00018 <span class="preprocessor">#include "<a class="code" href="Util_8h.html">Util.h</a>"</span>
<a name="l00019"></a>00019 <span class="preprocessor">#include "<a class="code" href="RIBDTLV_8h.html">RIBDTLV.h</a>"</span>
<a name="l00020"></a>00020 
<a name="l00021"></a>00021 <span class="keyword">namespace </span>prophet
<a name="l00022"></a>00022 {
<a name="l00023"></a>00023 
<a name="l00024"></a><a class="code" href="classprophet_1_1RIBDTLV.html#e25bbe32fd51babaeea0dcb6dde4155c">00024</a> <a class="code" href="classprophet_1_1RIBDTLV.html#21d749e043b5c6ee6787418475ccd740" title="Constructor.">RIBDTLV::RIBDTLV</a>(<span class="keyword">const</span> <a class="code" href="classprophet_1_1Dictionary.html" title="Utility class to facilitate converting to and from routing string (endpoint ID) and...">Dictionary</a>&amp; ribd)
<a name="l00025"></a>00025     : <a class="code" href="classprophet_1_1BaseTLV.html" title="The Prophet I-D (March 2006) dictates five bytecodes for router state exchange messages...">BaseTLV</a>(<a class="code" href="classprophet_1_1BaseTLV.html" title="The Prophet I-D (March 2006) dictates five bytecodes for router state exchange messages...">BaseTLV</a>::RIBD_TLV), ribd_(ribd)
<a name="l00026"></a>00026 {
<a name="l00027"></a>00027     <a class="code" href="classprophet_1_1BaseTLV.html#4c0a7b24b795bafb52c16b24a6188823" title="serialized length of TLV, mutable so it can be assigned by serialize() const">length_</a>  = <a class="code" href="classprophet_1_1RIBDTLV.html#0462e2f66d58cf097d5d759e9d3d2e27">RIBDTLVHeaderSize</a>;
<a name="l00028"></a>00028     <a class="code" href="classprophet_1_1BaseTLV.html#4c0a7b24b795bafb52c16b24a6188823" title="serialized length of TLV, mutable so it can be assigned by serialize() const">length_</a> += <a class="code" href="classprophet_1_1RIBDTLV.html#5aab54c6e1a12bb1846b2a3f299d1ff6" title="mapping from destination id string to numeric id (sid)">ribd_</a>.<a class="code" href="classprophet_1_1Dictionary.html#250334386542b62223dc658ecceacf66" title="Helper function for serializing, where RASsz is the sizeof(RoutingAddressString)...">guess_ribd_size</a>(<a class="code" href="classprophet_1_1RIBDTLV.html#557314304a9645a753d24f5580dbd61c">RoutingAddressStringSize</a>);
<a name="l00029"></a>00029 }
<a name="l00030"></a>00030 
<a name="l00031"></a><a class="code" href="classprophet_1_1RIBDTLV.html#21d749e043b5c6ee6787418475ccd740">00031</a> <a class="code" href="classprophet_1_1RIBDTLV.html#21d749e043b5c6ee6787418475ccd740" title="Constructor.">RIBDTLV::RIBDTLV</a>()
<a name="l00032"></a>00032     : <a class="code" href="classprophet_1_1BaseTLV.html" title="The Prophet I-D (March 2006) dictates five bytecodes for router state exchange messages...">BaseTLV</a>(<a class="code" href="classprophet_1_1BaseTLV.html" title="The Prophet I-D (March 2006) dictates five bytecodes for router state exchange messages...">BaseTLV</a>::RIBD_TLV) {}
<a name="l00033"></a>00033 
<a name="l00034"></a>00034 <span class="keywordtype">size_t</span>
<a name="l00035"></a><a class="code" href="classprophet_1_1RIBDTLV.html#cb9d5d3a603d208a7c4d880e4b8cb7a7">00035</a> <a class="code" href="classprophet_1_1RIBDTLV.html#cb9d5d3a603d208a7c4d880e4b8cb7a7" title="Serialize destination ID out to buffer bp, size len, using struct RoutingAddressString;...">RIBDTLV::write_ras_entry</a>(u_int16_t sid,
<a name="l00036"></a>00036                          <span class="keyword">const</span> std::string&amp; dest_id,
<a name="l00037"></a>00037                          u_char* bp, <span class="keywordtype">size_t</span> <a class="code" href="num2sdnv_8c.html#fed088663f8704004425cdae2120b9b3">len</a>)<span class="keyword"> const</span>
<a name="l00038"></a>00038 <span class="keyword"></span>{
<a name="l00039"></a>00039     <span class="comment">// weed out the oddball</span>
<a name="l00040"></a>00040     <span class="keywordflow">if</span> (bp == NULL) <span class="keywordflow">return</span> 0;
<a name="l00041"></a>00041 
<a name="l00042"></a>00042     <span class="comment">// align length of dest_id to 4 byte boundary</span>
<a name="l00043"></a>00043     <span class="keywordtype">size_t</span> copylen = <a class="code" href="Announce_8h.html#10fb10f052238243f08749f41a8374a6">FOUR_BYTE_ALIGN</a>(dest_id.length());
<a name="l00044"></a>00044 
<a name="l00045"></a>00045     <span class="comment">// make sure the lengths match up with the provided buffer</span>
<a name="l00046"></a>00046     <span class="keywordflow">if</span> (<a class="code" href="classprophet_1_1RIBDTLV.html#557314304a9645a753d24f5580dbd61c">RoutingAddressStringSize</a> + copylen &gt; len) <span class="keywordflow">return</span> 0;
<a name="l00047"></a>00047 
<a name="l00048"></a>00048     <span class="comment">// initialize to sizeof overhead</span>
<a name="l00049"></a>00049     <span class="keywordtype">size_t</span> retval = <a class="code" href="classprophet_1_1RIBDTLV.html#557314304a9645a753d24f5580dbd61c">RoutingAddressStringSize</a>;
<a name="l00050"></a>00050 
<a name="l00051"></a>00051     <span class="comment">// start writing out to buffer</span>
<a name="l00052"></a>00052     <a class="code" href="structprophet_1_1RIBDTLV_1_1RoutingAddressString.html" title="Routing Address String (entry in RIBD above) p.">RoutingAddressString</a>* ras = (<a class="code" href="structprophet_1_1RIBDTLV_1_1RoutingAddressString.html" title="Routing Address String (entry in RIBD above) p.">RoutingAddressString</a>*) bp;
<a name="l00053"></a>00053     ras-&gt;<a class="code" href="structprophet_1_1RIBDTLV_1_1RoutingAddressString.html#713200363e4314adbc2c1181edc8e849" title="16 bit identifier that is constant for the duration of a session.">string_id</a> = htons(sid);
<a name="l00054"></a>00054     ras-&gt;<a class="code" href="structprophet_1_1RIBDTLV_1_1RoutingAddressString.html#4c1852711eac29dd49196e937d54f30f" title="Length of Address String.">length</a>    = dest_id.length() &amp; 0xff;
<a name="l00055"></a>00055     memcpy(&amp;ras-&gt;<a class="code" href="structprophet_1_1RIBDTLV_1_1RoutingAddressString.html#db156862432ba05aa81ababf76ec355a">ra_string</a>[0],dest_id.c_str(),dest_id.length());
<a name="l00056"></a>00056     retval += copylen; <span class="comment">// 32-bit alignment</span>
<a name="l00057"></a>00057 
<a name="l00058"></a>00058     <span class="comment">// zero out slack, if any</span>
<a name="l00059"></a>00059     <span class="keywordflow">while</span> (copylen-- &gt; ras-&gt;<a class="code" href="structprophet_1_1RIBDTLV_1_1RoutingAddressString.html#4c1852711eac29dd49196e937d54f30f" title="Length of Address String.">length</a>)
<a name="l00060"></a>00060         ras-&gt;<a class="code" href="structprophet_1_1RIBDTLV_1_1RoutingAddressString.html#db156862432ba05aa81ababf76ec355a">ra_string</a>[copylen] = <span class="charliteral">'\0'</span>;
<a name="l00061"></a>00061 
<a name="l00062"></a>00062     <span class="keywordflow">return</span> retval;
<a name="l00063"></a>00063 }
<a name="l00064"></a>00064 
<a name="l00065"></a>00065 <span class="keywordtype">size_t</span>
<a name="l00066"></a><a class="code" href="classprophet_1_1RIBDTLV.html#9b26b15fa1b5286d40b7eba91a8d39e6">00066</a> <a class="code" href="classprophet_1_1RIBDTLV.html#9b26b15fa1b5286d40b7eba91a8d39e6" title="Virtual from BaseTLV.">RIBDTLV::serialize</a>(u_char* bp, <span class="keywordtype">size_t</span> <a class="code" href="num2sdnv_8c.html#fed088663f8704004425cdae2120b9b3">len</a>)<span class="keyword"> const</span>
<a name="l00067"></a>00067 <span class="keyword"></span>{
<a name="l00068"></a>00068     <span class="comment">// weed out the oddball</span>
<a name="l00069"></a>00069     <span class="keywordflow">if</span> (bp == NULL) <span class="keywordflow">return</span> 0;
<a name="l00070"></a>00070     <span class="keywordflow">if</span> (<a class="code" href="classprophet_1_1BaseTLV.html#88263c57b5c2760ece631ce8943c6249" title="typecode for this TLV">typecode_</a> != <a class="code" href="classprophet_1_1BaseTLV.html#37c3690d6040c870b40fa0436b67b09de5615891dad0b40891a124fcff00f562">BaseTLV::RIBD_TLV</a>) <span class="keywordflow">return</span> 0;
<a name="l00071"></a>00071 
<a name="l00072"></a>00072     <span class="comment">// estimate final size of TLV, check length of inbound buffer</span>
<a name="l00073"></a>00073     <span class="keywordtype">size_t</span> ribd_sz = <a class="code" href="classprophet_1_1RIBDTLV.html#5aab54c6e1a12bb1846b2a3f299d1ff6" title="mapping from destination id string to numeric id (sid)">ribd_</a>.<a class="code" href="classprophet_1_1Dictionary.html#250334386542b62223dc658ecceacf66" title="Helper function for serializing, where RASsz is the sizeof(RoutingAddressString)...">guess_ribd_size</a>(<a class="code" href="classprophet_1_1RIBDTLV.html#557314304a9645a753d24f5580dbd61c">RoutingAddressStringSize</a>);
<a name="l00074"></a>00074     <span class="keywordflow">if</span> (ribd_sz + <a class="code" href="classprophet_1_1RIBDTLV.html#0462e2f66d58cf097d5d759e9d3d2e27">RIBDTLVHeaderSize</a> &gt; len) <span class="keywordflow">return</span> 0;
<a name="l00075"></a>00075 
<a name="l00076"></a>00076     <span class="comment">// initialize accounting</span>
<a name="l00077"></a>00077     <span class="keywordtype">size_t</span> ribd_entry_count = 0;
<a name="l00078"></a>00078     <a class="code" href="classprophet_1_1BaseTLV.html#4c0a7b24b795bafb52c16b24a6188823" title="serialized length of TLV, mutable so it can be assigned by serialize() const">length_</a> = 0;
<a name="l00079"></a>00079     <a class="code" href="structprophet_1_1RIBDTLV_1_1RIBDTLVHeader.html" title="Routing Information Base Dictionary TLV  p.">RIBDTLVHeader</a>* hdr = (<a class="code" href="structprophet_1_1RIBDTLV_1_1RIBDTLVHeader.html" title="Routing Information Base Dictionary TLV  p.">RIBDTLVHeader</a>*) bp;
<a name="l00080"></a>00080     memset(hdr,0,<a class="code" href="classprophet_1_1RIBDTLV.html#0462e2f66d58cf097d5d759e9d3d2e27">RIBDTLVHeaderSize</a>);
<a name="l00081"></a>00081 
<a name="l00082"></a>00082     <span class="comment">// write out to buffer, skipping header (for now)</span>
<a name="l00083"></a>00083     bp += <a class="code" href="classprophet_1_1RIBDTLV.html#0462e2f66d58cf097d5d759e9d3d2e27">RIBDTLVHeaderSize</a>;
<a name="l00084"></a>00084     <a class="code" href="classprophet_1_1BaseTLV.html#4c0a7b24b795bafb52c16b24a6188823" title="serialized length of TLV, mutable so it can be assigned by serialize() const">length_</a> += <a class="code" href="classprophet_1_1RIBDTLV.html#0462e2f66d58cf097d5d759e9d3d2e27">RIBDTLVHeaderSize</a>;
<a name="l00085"></a>00085 
<a name="l00086"></a>00086     <span class="comment">// write out individual RIBD entries </span>
<a name="l00087"></a>00087     <span class="keywordflow">for</span> (<a class="code" href="classprophet_1_1Dictionary.html#80622a2076a9267f6131aadb9f865e05">Dictionary::const_iterator</a> i = <a class="code" href="classprophet_1_1RIBDTLV.html#5aab54c6e1a12bb1846b2a3f299d1ff6" title="mapping from destination id string to numeric id (sid)">ribd_</a>.<a class="code" href="classprophet_1_1Dictionary.html#01530ae50e9191b36cc2b56593725584" title="Iterators.">begin</a>(); i != <a class="code" href="classprophet_1_1RIBDTLV.html#5aab54c6e1a12bb1846b2a3f299d1ff6" title="mapping from destination id string to numeric id (sid)">ribd_</a>.<a class="code" href="classprophet_1_1Dictionary.html#de4bd30ae5e6a17e1acb4c1730432d62" title="Iterators.">end</a>(); i++)
<a name="l00088"></a>00088     {
<a name="l00089"></a>00089         <span class="comment">// shouldn't happen, but test anyways</span>
<a name="l00090"></a>00090         <span class="keywordflow">if</span> ((*i).first &lt; 2)
<a name="l00091"></a>00091             <span class="keywordflow">continue</span>; <span class="comment">// local and remote peers are implied as 0 and 1</span>
<a name="l00092"></a>00092 
<a name="l00093"></a>00093         <span class="keywordtype">size_t</span> bytes_written = 0;
<a name="l00094"></a>00094         <span class="keywordflow">if</span> ((bytes_written =
<a name="l00095"></a>00095                     <a class="code" href="classprophet_1_1RIBDTLV.html#cb9d5d3a603d208a7c4d880e4b8cb7a7" title="Serialize destination ID out to buffer bp, size len, using struct RoutingAddressString;...">write_ras_entry</a>((*i).first,(*i).second,bp,len)) == 0)
<a name="l00096"></a>00096             <span class="keywordflow">break</span>;
<a name="l00097"></a>00097 
<a name="l00098"></a>00098         bp      += bytes_written;
<a name="l00099"></a>00099         len     -= bytes_written;
<a name="l00100"></a>00100         <a class="code" href="classprophet_1_1BaseTLV.html#4c0a7b24b795bafb52c16b24a6188823" title="serialized length of TLV, mutable so it can be assigned by serialize() const">length_</a> += bytes_written;
<a name="l00101"></a>00101 
<a name="l00102"></a>00102         ribd_entry_count++;
<a name="l00103"></a>00103     }
<a name="l00104"></a>00104 
<a name="l00105"></a>00105     <span class="comment">// fill in header for amounts successfully written </span>
<a name="l00106"></a>00106     hdr-&gt;<a class="code" href="structprophet_1_1RIBDTLV_1_1RIBDTLVHeader.html#43114f03deec1bfa2bb37b0f0bb6519c" title="defined as 0xA0">type</a>        = <a class="code" href="classprophet_1_1BaseTLV.html#37c3690d6040c870b40fa0436b67b09de5615891dad0b40891a124fcff00f562">BaseTLV::RIBD_TLV</a>;
<a name="l00107"></a>00107     hdr-&gt;<a class="code" href="structprophet_1_1RIBDTLV_1_1RIBDTLVHeader.html#3b05833660096f57f2f528e34d24f087" title="TBD.">flags</a>       = 0;
<a name="l00108"></a>00108     hdr-&gt;<a class="code" href="structprophet_1_1RIBDTLV_1_1RIBDTLVHeader.html#b5d39018a3b13ab586784983910dbec7" title="Length of the TLV in octets, including the TLV header and any nested TLVs.">length</a>      = htons(<a class="code" href="classprophet_1_1BaseTLV.html#4c0a7b24b795bafb52c16b24a6188823" title="serialized length of TLV, mutable so it can be assigned by serialize() const">length_</a>);
<a name="l00109"></a>00109     hdr-&gt;<a class="code" href="structprophet_1_1RIBDTLV_1_1RIBDTLVHeader.html#0f61decb561ee7299a3c769b72637d76" title="Number of entries in the database.">entry_count</a> = htons(ribd_entry_count);
<a name="l00110"></a>00110 
<a name="l00111"></a>00111     <span class="keywordflow">return</span> <a class="code" href="classprophet_1_1BaseTLV.html#4c0a7b24b795bafb52c16b24a6188823" title="serialized length of TLV, mutable so it can be assigned by serialize() const">length_</a>;
<a name="l00112"></a>00112 }
<a name="l00113"></a>00113 
<a name="l00114"></a>00114 <span class="keywordtype">size_t</span>
<a name="l00115"></a><a class="code" href="classprophet_1_1RIBDTLV.html#9d4063bccf8158d2b46d84689bc5739d">00115</a> <a class="code" href="classprophet_1_1RIBDTLV.html#9d4063bccf8158d2b46d84689bc5739d" title="Deserialize RoutingAddressString struct from transport into memory, setting *sid...">RIBDTLV::read_ras_entry</a>(u_int16_t* sid,
<a name="l00116"></a>00116                         std::string&amp; dest_id,
<a name="l00117"></a>00117                         <span class="keyword">const</span> u_char* bp, <span class="keywordtype">size_t</span> <a class="code" href="num2sdnv_8c.html#fed088663f8704004425cdae2120b9b3">len</a>)
<a name="l00118"></a>00118 {
<a name="l00119"></a>00119     <span class="comment">// weed out the oddball</span>
<a name="l00120"></a>00120     <span class="keywordflow">if</span> (sid == NULL || bp == NULL) <span class="keywordflow">return</span> 0;
<a name="l00121"></a>00121 
<a name="l00122"></a>00122     <span class="comment">// reject too-tight bounds</span>
<a name="l00123"></a>00123     <span class="keywordflow">if</span> (<a class="code" href="classprophet_1_1RIBDTLV.html#557314304a9645a753d24f5580dbd61c">RoutingAddressStringSize</a> &gt; len) <span class="keywordflow">return</span> 0;
<a name="l00124"></a>00124 
<a name="l00125"></a>00125     <a class="code" href="structprophet_1_1RIBDTLV_1_1RoutingAddressString.html" title="Routing Address String (entry in RIBD above) p.">RoutingAddressString</a>* ras = (<a class="code" href="structprophet_1_1RIBDTLV_1_1RoutingAddressString.html" title="Routing Address String (entry in RIBD above) p.">RoutingAddressString</a>*) bp;
<a name="l00126"></a>00126 
<a name="l00127"></a>00127     <span class="comment">// initialize to sizeof overhead</span>
<a name="l00128"></a>00128     <span class="keywordtype">size_t</span> retval = <a class="code" href="classprophet_1_1RIBDTLV.html#557314304a9645a753d24f5580dbd61c">RoutingAddressStringSize</a>;
<a name="l00129"></a>00129 
<a name="l00130"></a>00130     <span class="comment">// must be even multiple of 4 bytes</span>
<a name="l00131"></a>00131     <span class="keywordtype">size_t</span> copylen = <a class="code" href="Announce_8h.html#10fb10f052238243f08749f41a8374a6">FOUR_BYTE_ALIGN</a>(ras-&gt;<a class="code" href="structprophet_1_1RIBDTLV_1_1RoutingAddressString.html#4c1852711eac29dd49196e937d54f30f" title="Length of Address String.">length</a>);
<a name="l00132"></a>00132 
<a name="l00133"></a>00133     <span class="comment">// make sure the lengths match up</span>
<a name="l00134"></a>00134     <span class="keywordflow">if</span> (copylen &gt; len - retval) <span class="keywordflow">return</span> retval;
<a name="l00135"></a>00135 
<a name="l00136"></a>00136     <span class="comment">// read into memory</span>
<a name="l00137"></a>00137     *sid = ntohs(ras-&gt;<a class="code" href="structprophet_1_1RIBDTLV_1_1RoutingAddressString.html#713200363e4314adbc2c1181edc8e849" title="16 bit identifier that is constant for the duration of a session.">string_id</a>); 
<a name="l00138"></a>00138     dest_id.assign((<span class="keywordtype">char</span>*)&amp;ras-&gt;<a class="code" href="structprophet_1_1RIBDTLV_1_1RoutingAddressString.html#db156862432ba05aa81ababf76ec355a">ra_string</a>[0],ras-&gt;<a class="code" href="structprophet_1_1RIBDTLV_1_1RoutingAddressString.html#4c1852711eac29dd49196e937d54f30f" title="Length of Address String.">length</a>);
<a name="l00139"></a>00139 
<a name="l00140"></a>00140     <span class="comment">// count what we read</span>
<a name="l00141"></a>00141     retval += copylen;
<a name="l00142"></a>00142 
<a name="l00143"></a>00143     <span class="keywordflow">return</span> retval;
<a name="l00144"></a>00144 }
<a name="l00145"></a>00145 
<a name="l00146"></a>00146 <span class="keywordtype">bool</span>
<a name="l00147"></a><a class="code" href="classprophet_1_1RIBDTLV.html#e5e6e89ef24b6bfa3c5d0ee0c97f3f55">00147</a> <a class="code" href="classprophet_1_1RIBDTLV.html#e5e6e89ef24b6bfa3c5d0ee0c97f3f55" title="Virtual from BaseTLV.">RIBDTLV::deserialize</a>(<span class="keyword">const</span> u_char* bp, <span class="keywordtype">size_t</span> <a class="code" href="num2sdnv_8c.html#fed088663f8704004425cdae2120b9b3">len</a>)
<a name="l00148"></a>00148 {
<a name="l00149"></a>00149     <a class="code" href="structprophet_1_1RIBDTLV_1_1RIBDTLVHeader.html" title="Routing Information Base Dictionary TLV  p.">RIBDTLVHeader</a>* hdr = (<a class="code" href="structprophet_1_1RIBDTLV_1_1RIBDTLVHeader.html" title="Routing Information Base Dictionary TLV  p.">RIBDTLVHeader</a>*) bp;
<a name="l00150"></a>00150 
<a name="l00151"></a>00151     <span class="comment">// weed out the oddball</span>
<a name="l00152"></a>00152     <span class="keywordflow">if</span> (bp == NULL) <span class="keywordflow">return</span> <span class="keyword">false</span>;
<a name="l00153"></a>00153 
<a name="l00154"></a>00154     <span class="comment">// Enforce typecode expectation</span>
<a name="l00155"></a>00155     <span class="keywordflow">if</span> (hdr-&gt;<a class="code" href="structprophet_1_1RIBDTLV_1_1RIBDTLVHeader.html#43114f03deec1bfa2bb37b0f0bb6519c" title="defined as 0xA0">type</a> != <a class="code" href="classprophet_1_1BaseTLV.html#37c3690d6040c870b40fa0436b67b09de5615891dad0b40891a124fcff00f562">RIBD_TLV</a>) <span class="keywordflow">return</span> <span class="keyword">false</span>;
<a name="l00156"></a>00156 
<a name="l00157"></a>00157     <span class="comment">// Inbound buffer must be at least as big as the overhead</span>
<a name="l00158"></a>00158     <span class="keywordflow">if</span> (len &lt; <a class="code" href="classprophet_1_1RIBDTLV.html#0462e2f66d58cf097d5d759e9d3d2e27">RIBDTLVHeaderSize</a>) <span class="keywordflow">return</span> <span class="keyword">false</span>;
<a name="l00159"></a>00159 
<a name="l00160"></a>00160     <span class="comment">// Fail out if lengths don't match up</span>
<a name="l00161"></a>00161     <a class="code" href="classprophet_1_1BaseTLV.html#4c0a7b24b795bafb52c16b24a6188823" title="serialized length of TLV, mutable so it can be assigned by serialize() const">length_</a> = ntohs(hdr-&gt;<a class="code" href="structprophet_1_1RIBDTLV_1_1RIBDTLVHeader.html#b5d39018a3b13ab586784983910dbec7" title="Length of the TLV in octets, including the TLV header and any nested TLVs.">length</a>);
<a name="l00162"></a>00162     <span class="keywordflow">if</span> (len &lt; <a class="code" href="classprophet_1_1BaseTLV.html#4c0a7b24b795bafb52c16b24a6188823" title="serialized length of TLV, mutable so it can be assigned by serialize() const">length_</a>) <span class="keywordflow">return</span> <span class="keyword">false</span>;
<a name="l00163"></a>00163 
<a name="l00164"></a>00164     <a class="code" href="classprophet_1_1BaseTLV.html#31f1ebbf538b5b28c42e49e1eef6a34e" title="TLV-specific flags.">flags_</a>  = hdr-&gt;<a class="code" href="structprophet_1_1RIBDTLV_1_1RIBDTLVHeader.html#3b05833660096f57f2f528e34d24f087" title="TBD.">flags</a>;
<a name="l00165"></a>00165 
<a name="l00166"></a>00166     <span class="keywordtype">size_t</span> ribd_entry_count = ntohs(hdr-&gt;<a class="code" href="structprophet_1_1RIBDTLV_1_1RIBDTLVHeader.html#0f61decb561ee7299a3c769b72637d76" title="Number of entries in the database.">entry_count</a>);
<a name="l00167"></a>00167 
<a name="l00168"></a>00168     <span class="comment">// Now that the header is parsed, move past to the first RIBD entry</span>
<a name="l00169"></a>00169     bp += <a class="code" href="classprophet_1_1RIBDTLV.html#0462e2f66d58cf097d5d759e9d3d2e27">RIBDTLVHeaderSize</a>;
<a name="l00170"></a>00170 
<a name="l00171"></a>00171     <span class="keywordtype">size_t</span> amt_read = <a class="code" href="classprophet_1_1RIBDTLV.html#0462e2f66d58cf097d5d759e9d3d2e27">RIBDTLVHeaderSize</a>;
<a name="l00172"></a>00172     len -= <a class="code" href="classprophet_1_1RIBDTLV.html#0462e2f66d58cf097d5d759e9d3d2e27">RIBDTLVHeaderSize</a>;
<a name="l00173"></a>00173 
<a name="l00174"></a>00174     u_int16_t sid;
<a name="l00175"></a>00175     std::string dest_id;
<a name="l00176"></a>00176     <a class="code" href="classprophet_1_1RIBDTLV.html#5aab54c6e1a12bb1846b2a3f299d1ff6" title="mapping from destination id string to numeric id (sid)">ribd_</a>.<a class="code" href="classprophet_1_1Dictionary.html#dc4702ba4c07259ab17cedaa48786723" title="Wipe out dictionary and prepare to deserialize new one.">clear</a>();
<a name="l00177"></a>00177     <span class="keywordflow">while</span> (ribd_entry_count-- &gt; 0)
<a name="l00178"></a>00178     {
<a name="l00179"></a>00179         <span class="comment">// deserialize RAS from buffer</span>
<a name="l00180"></a>00180         <span class="keywordtype">size_t</span> bytes_read = <a class="code" href="classprophet_1_1RIBDTLV.html#9d4063bccf8158d2b46d84689bc5739d" title="Deserialize RoutingAddressString struct from transport into memory, setting *sid...">read_ras_entry</a>(&amp;sid,dest_id,bp,len);
<a name="l00181"></a>00181 
<a name="l00182"></a>00182         <span class="comment">// abort on error</span>
<a name="l00183"></a>00183         <span class="keywordflow">if</span> (bytes_read == 0) <span class="keywordflow">break</span>;
<a name="l00184"></a>00184 
<a name="l00185"></a>00185         <span class="comment">// store this dictionary entry</span>
<a name="l00186"></a>00186         <span class="keywordflow">if</span>(<a class="code" href="classprophet_1_1RIBDTLV.html#5aab54c6e1a12bb1846b2a3f299d1ff6" title="mapping from destination id string to numeric id (sid)">ribd_</a>.<a class="code" href="classprophet_1_1Dictionary.html#4f785ed38d15266fd52f82bfe2a3259a" title="Assign dest_id to arbitrary id (used by TLV deserialization); return true upon success...">assign</a>(dest_id,sid) == <span class="keyword">false</span>) <span class="keywordflow">break</span>;
<a name="l00187"></a>00187 
<a name="l00188"></a>00188         len      -= bytes_read;
<a name="l00189"></a>00189         bp       += bytes_read;
<a name="l00190"></a>00190         amt_read += bytes_read;
<a name="l00191"></a>00191     }
<a name="l00192"></a>00192 
<a name="l00193"></a>00193     <span class="keywordflow">return</span> (amt_read == <a class="code" href="classprophet_1_1BaseTLV.html#4c0a7b24b795bafb52c16b24a6188823" title="serialized length of TLV, mutable so it can be assigned by serialize() const">length_</a>);
<a name="l00194"></a>00194 }
<a name="l00195"></a>00195 
<a name="l00196"></a>00196 <span class="keyword">const</span> <a class="code" href="classprophet_1_1Dictionary.html" title="Utility class to facilitate converting to and from routing string (endpoint ID) and...">Dictionary</a>&amp;
<a name="l00197"></a><a class="code" href="classprophet_1_1RIBDTLV.html#f61522c27a15c1321df154b44392459b">00197</a> <a class="code" href="classprophet_1_1RIBDTLV.html#f61522c27a15c1321df154b44392459b" title="Accessor.">RIBDTLV::ribd</a>(<span class="keyword">const</span> std::string&amp; sender, <span class="keyword">const</span> std::string&amp; receiver)
<a name="l00198"></a>00198 {
<a name="l00199"></a>00199     <a class="code" href="classprophet_1_1RIBDTLV.html#5aab54c6e1a12bb1846b2a3f299d1ff6" title="mapping from destination id string to numeric id (sid)">ribd_</a>.<a class="code" href="classprophet_1_1Dictionary.html#4f785ed38d15266fd52f82bfe2a3259a" title="Assign dest_id to arbitrary id (used by TLV deserialization); return true upon success...">assign</a>(sender,0);
<a name="l00200"></a>00200     <a class="code" href="classprophet_1_1RIBDTLV.html#5aab54c6e1a12bb1846b2a3f299d1ff6" title="mapping from destination id string to numeric id (sid)">ribd_</a>.<a class="code" href="classprophet_1_1Dictionary.html#4f785ed38d15266fd52f82bfe2a3259a" title="Assign dest_id to arbitrary id (used by TLV deserialization); return true upon success...">assign</a>(receiver,1);
<a name="l00201"></a>00201     <span class="keywordflow">return</span> <a class="code" href="classprophet_1_1RIBDTLV.html#5aab54c6e1a12bb1846b2a3f299d1ff6" title="mapping from destination id string to numeric id (sid)">ribd_</a>;
<a name="l00202"></a>00202 }
<a name="l00203"></a>00203 
<a name="l00204"></a>00204 }; <span class="comment">// namespace prophet</span>
</pre></div></div>
<hr size="1"><address style="text-align: right;"><small>Generated on Fri Jan 30 09:26:57 2009 for DTN Reference Implementation by&nbsp;
<a href="http://www.doxygen.org/index.html">
<img src="doxygen.png" alt="doxygen" align="middle" border="0"></a> 1.5.8 </small></address>
</body>
</html>