Sophie

Sophie

distrib > Mandriva > 2009.0 > i586 > by-pkgid > d9faa203c2b0b6fbb179d93daaea81b7 > files > 148

libdtn-devel-2.6.0-1mdv2009.0.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: BundleTLV.cc Source File</title>
<link href="doxygen.css" rel="stylesheet" type="text/css">
<link href="tabs.css" rel="stylesheet" type="text/css">
</head><body>
<!-- Generated by Doxygen 1.5.6 -->
<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>
<h1>BundleTLV.cc</h1><a href="BundleTLV_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="BundleTLV_8h.html">BundleTLV.h</a>"</span>
<a name="l00019"></a>00019 
<a name="l00020"></a>00020 <span class="keyword">namespace </span>prophet
<a name="l00021"></a>00021 {
<a name="l00022"></a>00022 
<a name="l00023"></a><a class="code" href="classprophet_1_1BundleTLV.html#eeadbbb84b780c5d390a9f1e6318c850">00023</a> <span class="keywordtype">size_t</span> <a class="code" href="classprophet_1_1BundleTLV.html#eeadbbb84b780c5d390a9f1e6318c850" title="Serialize BundleOfferTLVEntry out to no more than len bytes of buffer; return bytes...">BundleTLV::write_bundle_entry</a>(u_int32_t cts, u_int32_t seq,
<a name="l00024"></a>00024                                      u_int16_t sid, <span class="keywordtype">bool</span> <a class="code" href="dtncat_8c.html#160881851a33309c0106503ac4d14d96">custody</a>,
<a name="l00025"></a>00025                                      <span class="keywordtype">bool</span> accept, <span class="keywordtype">bool</span> ack,
<a name="l00026"></a>00026                                      <a class="code" href="classprophet_1_1BundleTLVEntry.html#ba508cc555c3c88394dc4659c7e0d321" title="A BundleTLVEntry can represent either an OFFER or a RESPONSE, depending on what is...">BundleTLVEntry::bundle_entry_t</a> type, 
<a name="l00027"></a>00027                                      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="l00028"></a>00028 <span class="keyword"></span>{
<a name="l00029"></a>00029     <span class="comment">// weed out the oddball</span>
<a name="l00030"></a>00030     <span class="keywordflow">if</span> (bp == NULL) <span class="keywordflow">return</span> 0;
<a name="l00031"></a>00031     <span class="keywordflow">if</span> (type == <a class="code" href="classprophet_1_1BundleTLVEntry.html#ba508cc555c3c88394dc4659c7e0d3215a1a084212865f78c542f8c458201a19" title="no valid type has been specified">BundleTLVEntry::UNDEFINED</a>) <span class="keywordflow">return</span> 0;
<a name="l00032"></a>00032 
<a name="l00033"></a>00033     <span class="comment">// check that lengths match up</span>
<a name="l00034"></a>00034     <span class="keywordflow">if</span> (<a class="code" href="classprophet_1_1BundleTLV.html#a7921e77cc4c5585d79932a24b8a7927">BundleEntrySize</a> &gt; len) <span class="keywordflow">return</span> 0;
<a name="l00035"></a>00035 
<a name="l00036"></a>00036     <span class="comment">// start writing out to buffer</span>
<a name="l00037"></a>00037     <a class="code" href="structprophet_1_1BundleTLV_1_1BundleEntry.html" title="Bundle Offer/Response Entry p.">BundleEntry</a>* b = (<a class="code" href="structprophet_1_1BundleTLV_1_1BundleEntry.html" title="Bundle Offer/Response Entry p.">BundleEntry</a>*) bp;
<a name="l00038"></a>00038     memset(b, 0, <a class="code" href="classprophet_1_1BundleTLV.html#a7921e77cc4c5585d79932a24b8a7927">BundleEntrySize</a>);
<a name="l00039"></a>00039     <span class="keywordflow">if</span> (custody) b-&gt;<a class="code" href="structprophet_1_1BundleTLV_1_1BundleEntry.html#ec6a1db808161d1ef23f1ec53bbef43f" title="The encoding of the B_Flags in the request are:     Flag 0: Custody Offered 0b1 ...">b_flags</a> |= <a class="code" href="classprophet_1_1BundleTLV.html#1d398f4325d6d724d3e807cc9dd25a2b0e2665233fe415bb8a081d2e4aea1be9" title="custody offered or accepted on this bundle">CUSTODY</a>;
<a name="l00040"></a>00040     <span class="keywordflow">if</span> (accept)  b-&gt;<a class="code" href="structprophet_1_1BundleTLV_1_1BundleEntry.html#ec6a1db808161d1ef23f1ec53bbef43f" title="The encoding of the B_Flags in the request are:     Flag 0: Custody Offered 0b1 ...">b_flags</a> |= <a class="code" href="classprophet_1_1BundleTLV.html#1d398f4325d6d724d3e807cc9dd25a2bb1f7b9b43eb9277a9e6e42a569736a6e" title="this bundle is accepted for relay">ACCEPTED</a>;
<a name="l00041"></a>00041     <span class="keywordflow">if</span> (ack)     b-&gt;<a class="code" href="structprophet_1_1BundleTLV_1_1BundleEntry.html#ec6a1db808161d1ef23f1ec53bbef43f" title="The encoding of the B_Flags in the request are:     Flag 0: Custody Offered 0b1 ...">b_flags</a> |= <a class="code" href="classprophet_1_1BundleTLV.html#1d398f4325d6d724d3e807cc9dd25a2b15802a3008fb408e9a7c395c05e12084" title="Prophet ACK for this bundle.">ACK</a>;
<a name="l00042"></a>00042     b-&gt;<a class="code" href="structprophet_1_1BundleTLV_1_1BundleEntry.html#4ff9113e4adc4a078890ca02338326e3" title="ID string of the destination of the bundle as predefined in the dictionary TLV.">dest_string_id</a>     = htons(sid);
<a name="l00043"></a>00043     b-&gt;<a class="code" href="structprophet_1_1BundleTLV_1_1BundleEntry.html#5110f61f9c020aaae4cce60884968404" title="This bundle&amp;#39;s creation timestamp.">creation_timestamp</a> = htonl(cts);
<a name="l00044"></a>00044     b-&gt;<a class="code" href="structprophet_1_1BundleTLV_1_1BundleEntry.html#7f76d6a9e04deee6afa7bae73100f825" title="NOT IN SPEC.">seqno</a>              = htonl(seq);
<a name="l00045"></a>00045 
<a name="l00046"></a>00046     <span class="keywordflow">return</span> <a class="code" href="classprophet_1_1BundleTLV.html#a7921e77cc4c5585d79932a24b8a7927">BundleEntrySize</a>;
<a name="l00047"></a>00047 }
<a name="l00048"></a>00048 
<a name="l00049"></a><a class="code" href="classprophet_1_1BundleTLV.html#4fe36522dccc0c81046b72e54d02d05c">00049</a> <span class="keywordtype">size_t</span> BundleTLV::read_bundle_entry(u_int32_t *cts, u_int32_t *seq,
<a name="l00050"></a>00050                                     u_int16_t *sid, <span class="keywordtype">bool</span> *<a class="code" href="dtncat_8c.html#160881851a33309c0106503ac4d14d96">custody</a>,
<a name="l00051"></a>00051                                     <span class="keywordtype">bool</span> *accept, <span class="keywordtype">bool</span> *ack,
<a name="l00052"></a>00052                                     <a class="code" href="classprophet_1_1BundleTLVEntry.html#ba508cc555c3c88394dc4659c7e0d321" title="A BundleTLVEntry can represent either an OFFER or a RESPONSE, depending on what is...">BundleTLVEntry::bundle_entry_t</a> *type,
<a name="l00053"></a>00053                                     <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="l00054"></a>00054 {
<a name="l00055"></a>00055     <span class="comment">// weed out the oddball</span>
<a name="l00056"></a>00056     <span class="keywordflow">if</span> (bp      == NULL ||
<a name="l00057"></a>00057         cts     == NULL ||
<a name="l00058"></a>00058         seq     == NULL ||
<a name="l00059"></a>00059         sid     == NULL ||
<a name="l00060"></a>00060         custody == NULL ||
<a name="l00061"></a>00061         accept  == NULL ||
<a name="l00062"></a>00062         ack     == NULL ||
<a name="l00063"></a>00063         type    == NULL)   <span class="keywordflow">return</span> 0;
<a name="l00064"></a>00064 
<a name="l00065"></a>00065     <span class="comment">// check that lengths match up</span>
<a name="l00066"></a>00066     <span class="keywordflow">if</span> (<a class="code" href="classprophet_1_1BundleTLV.html#a7921e77cc4c5585d79932a24b8a7927">BundleEntrySize</a> &gt; len) <span class="keywordflow">return</span> 0;
<a name="l00067"></a>00067 
<a name="l00068"></a>00068     <span class="comment">// start reading in the entry</span>
<a name="l00069"></a>00069     <a class="code" href="structprophet_1_1BundleTLV_1_1BundleEntry.html" title="Bundle Offer/Response Entry p.">BundleEntry</a>* b = (<a class="code" href="structprophet_1_1BundleTLV_1_1BundleEntry.html" title="Bundle Offer/Response Entry p.">BundleEntry</a>*) bp;
<a name="l00070"></a>00070     u_int8_t <a class="code" href="classprophet_1_1BaseTLV.html#85ccaab1420732e2f1e327798b8899ed" title="Accessors.">flags</a> = b-&gt;<a class="code" href="structprophet_1_1BundleTLV_1_1BundleEntry.html#ec6a1db808161d1ef23f1ec53bbef43f" title="The encoding of the B_Flags in the request are:     Flag 0: Custody Offered 0b1 ...">b_flags</a> &amp; 0xff; <span class="comment">// mask out one byte</span>
<a name="l00071"></a>00071     *custody = ((flags &amp; <a class="code" href="classprophet_1_1BundleTLV.html#1d398f4325d6d724d3e807cc9dd25a2b0e2665233fe415bb8a081d2e4aea1be9" title="custody offered or accepted on this bundle">CUSTODY</a>)  == <a class="code" href="classprophet_1_1BundleTLV.html#1d398f4325d6d724d3e807cc9dd25a2b0e2665233fe415bb8a081d2e4aea1be9" title="custody offered or accepted on this bundle">CUSTODY</a>);
<a name="l00072"></a>00072     *accept  = ((flags &amp; <a class="code" href="classprophet_1_1BundleTLV.html#1d398f4325d6d724d3e807cc9dd25a2bb1f7b9b43eb9277a9e6e42a569736a6e" title="this bundle is accepted for relay">ACCEPTED</a>) == <a class="code" href="classprophet_1_1BundleTLV.html#1d398f4325d6d724d3e807cc9dd25a2bb1f7b9b43eb9277a9e6e42a569736a6e" title="this bundle is accepted for relay">ACCEPTED</a>);
<a name="l00073"></a>00073     *ack     = ((flags &amp; <a class="code" href="classprophet_1_1BundleTLV.html#1d398f4325d6d724d3e807cc9dd25a2b15802a3008fb408e9a7c395c05e12084" title="Prophet ACK for this bundle.">ACK</a>)      == <a class="code" href="classprophet_1_1BundleTLV.html#1d398f4325d6d724d3e807cc9dd25a2b15802a3008fb408e9a7c395c05e12084" title="Prophet ACK for this bundle.">ACK</a>);
<a name="l00074"></a>00074     <span class="comment">// infer whether OFFER or RESPONSE</span>
<a name="l00075"></a>00075     *type = <a class="code" href="classprophet_1_1BundleTLVEntry.html#a183aaa6d8be0194a725569221b7cfc1" title="Utility function to decipher which Bundle_X_Entry type based on the combination of...">BundleTLVEntry::decode_flags</a>(*custody,*accept,*ack);
<a name="l00076"></a>00076     *sid = ntohs(b-&gt;<a class="code" href="structprophet_1_1BundleTLV_1_1BundleEntry.html#4ff9113e4adc4a078890ca02338326e3" title="ID string of the destination of the bundle as predefined in the dictionary TLV.">dest_string_id</a>);
<a name="l00077"></a>00077     *cts = ntohl(b-&gt;<a class="code" href="structprophet_1_1BundleTLV_1_1BundleEntry.html#5110f61f9c020aaae4cce60884968404" title="This bundle&amp;#39;s creation timestamp.">creation_timestamp</a>);
<a name="l00078"></a>00078     *seq = ntohl(b-&gt;<a class="code" href="structprophet_1_1BundleTLV_1_1BundleEntry.html#7f76d6a9e04deee6afa7bae73100f825" title="NOT IN SPEC.">seqno</a>);
<a name="l00079"></a>00079 
<a name="l00080"></a>00080     <span class="keywordflow">return</span> <a class="code" href="classprophet_1_1BundleTLV.html#a7921e77cc4c5585d79932a24b8a7927">BundleEntrySize</a>;
<a name="l00081"></a>00081 }
<a name="l00082"></a>00082 
<a name="l00083"></a>00083 };
</pre></div></div>
<hr size="1"><address style="text-align: right;"><small>Generated on Mon Jul 21 14:09:38 2008 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.6 </small></address>
</body>
</html>