Sophie

Sophie

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

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: dtncp.c 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>dtncp.c</h1><a href="dtncp_8c.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 2004-2006 Intel Corporation</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">#ifdef HAVE_CONFIG_H</span>
<a name="l00018"></a>00018 <span class="preprocessor"></span><span class="preprocessor">#  include &lt;<a class="code" href="dtn-config_8h.html">dtn-config.h</a>&gt;</span>
<a name="l00019"></a>00019 <span class="preprocessor">#endif</span>
<a name="l00020"></a>00020 <span class="preprocessor"></span>
<a name="l00021"></a>00021 <span class="preprocessor">#include &lt;stdio.h&gt;</span>
<a name="l00022"></a>00022 <span class="preprocessor">#include &lt;stdlib.h&gt;</span>
<a name="l00023"></a>00023 <span class="preprocessor">#include &lt;string.h&gt;</span>
<a name="l00024"></a>00024 <span class="preprocessor">#include &lt;strings.h&gt;</span>
<a name="l00025"></a>00025 <span class="preprocessor">#include &lt;unistd.h&gt;</span>
<a name="l00026"></a>00026 <span class="preprocessor">#include &lt;errno.h&gt;</span>
<a name="l00027"></a>00027 <span class="preprocessor">#include &lt;sys/types.h&gt;</span>
<a name="l00028"></a>00028 <span class="preprocessor">#include &lt;sys/stat.h&gt;</span>
<a name="l00029"></a>00029 <span class="preprocessor">#include &lt;sys/time.h&gt;</span>
<a name="l00030"></a>00030 <span class="preprocessor">#include &lt;time.h&gt;</span>
<a name="l00031"></a>00031 
<a name="l00032"></a>00032 <span class="preprocessor">#include "<a class="code" href="dtn__api_8h.html">dtn_api.h</a>"</span>
<a name="l00033"></a>00033 
<a name="l00034"></a><a class="code" href="dtncp_8c.html#b9e1449fd00c98428516f0b41eddcb10">00034</a> <span class="keywordtype">char</span> *<a class="code" href="dtncat_8c.html#b9e1449fd00c98428516f0b41eddcb10">progname</a>;
<a name="l00035"></a><a class="code" href="dtncp_8c.html#0b2caeb4b6f130be43e5a2f0267dd453">00035</a> <span class="keywordtype">int</span> <a class="code" href="dtncat_8c.html#0b2caeb4b6f130be43e5a2f0267dd453">verbose</a>             = 1;
<a name="l00036"></a>00036 
<a name="l00037"></a><a class="code" href="dtncp_8c.html#9751128f4dcd9cccc1b82f5f82801871">00037</a> <span class="keywordtype">char</span> <a class="code" href="dtncp_8c.html#9751128f4dcd9cccc1b82f5f82801871">data_source</a>[1024]; <span class="comment">// filename or message, depending on type</span>
<a name="l00038"></a>00038 
<a name="l00039"></a>00039 <span class="comment">// specified options</span>
<a name="l00040"></a><a class="code" href="dtncp_8c.html#8f7af606d1623c716486d0dab4c70391">00040</a> <span class="keywordtype">char</span> * <a class="code" href="dtncat_8c.html#8f7af606d1623c716486d0dab4c70391">arg_dest</a>         = NULL;
<a name="l00041"></a><a class="code" href="dtncp_8c.html#33e4194393d4303c48a446b78b4250e9">00041</a> <span class="keywordtype">char</span> * <a class="code" href="dtncp_8c.html#33e4194393d4303c48a446b78b4250e9">arg_target</a>       = NULL;
<a name="l00042"></a>00042 
<a name="l00043"></a><a class="code" href="dtncp_8c.html#8b5dae09419110acc1d2e3d97b8bccd7">00043</a> <span class="keywordtype">int</span>    <a class="code" href="dtncp_8c.html#8b5dae09419110acc1d2e3d97b8bccd7">expiration_time</a>  = 60 * 60; <span class="comment">// default is 1 hour</span>
<a name="l00044"></a><a class="code" href="dtncp_8c.html#1bdbebbcf901e059d8765070846f9ee8">00044</a> <span class="keywordtype">int</span> <a class="code" href="dtncat_8c.html#1bdbebbcf901e059d8765070846f9ee8">delivery_receipts</a>   = 0;    <span class="comment">// request end to end delivery receipts</span>
<a name="l00045"></a>00045 
<a name="l00046"></a>00046 <span class="keywordtype">void</span> <a class="code" href="dtncat_8c.html#293abb58b132c26701dada5c4e57ca35">parse_options</a>(<span class="keywordtype">int</span>, <span class="keywordtype">char</span>**);
<a name="l00047"></a>00047 <a class="code" href="structdtn__endpoint__id__t.html" title="Specification of a dtn endpoint id, i.e.">dtn_endpoint_id_t</a> * <a class="code" href="dtncat_8c.html#8b10ca66cacac0bc52c3ce6737d8c85a">parse_eid</a>(<a class="code" href="dtn__api_8h.html#566289d829b69370d7635c21364bfe18" title="The basic handle for communication with the dtn router.">dtn_handle_t</a> <a class="code" href="dtncat_8c.html#01daea96255bb21a8979b3b45f5bbb70">handle</a>, <a class="code" href="structdtn__endpoint__id__t.html" title="Specification of a dtn endpoint id, i.e.">dtn_endpoint_id_t</a> * eid, 
<a name="l00048"></a>00048                           <span class="keywordtype">char</span> * str);
<a name="l00049"></a>00049 <span class="keywordtype">void</span> <a class="code" href="dtncat_8c.html#e5ad5cbeccaedc03a48d3c7eaa803e79">print_usage</a>();
<a name="l00050"></a>00050 <span class="keywordtype">void</span> <a class="code" href="dtncat_8c.html#a9d57d4d6b613ab254545fd140ebe5c8">print_eid</a>(<span class="keywordtype">char</span> * label, <a class="code" href="structdtn__endpoint__id__t.html" title="Specification of a dtn endpoint id, i.e.">dtn_endpoint_id_t</a> * eid);
<a name="l00051"></a>00051 
<a name="l00052"></a>00052 <span class="keywordtype">int</span>
<a name="l00053"></a><a class="code" href="dtncp_8c.html#3c04138a5bfe5d72780bb7e82a18e627">00053</a> <a class="code" href="dtncat_8c.html#3c04138a5bfe5d72780bb7e82a18e627">main</a>(<span class="keywordtype">int</span> argc, <span class="keywordtype">char</span>** argv)
<a name="l00054"></a>00054 {
<a name="l00055"></a>00055     <span class="keywordtype">int</span> ret;
<a name="l00056"></a>00056     <a class="code" href="dtn__api_8h.html#566289d829b69370d7635c21364bfe18" title="The basic handle for communication with the dtn router.">dtn_handle_t</a> <a class="code" href="dtncat_8c.html#01daea96255bb21a8979b3b45f5bbb70">handle</a>;
<a name="l00057"></a>00057     <a class="code" href="structdtn__reg__info__t.html" title="Registration state.">dtn_reg_info_t</a> reginfo;
<a name="l00058"></a>00058     <a class="code" href="dtn__types_8h.html#d9378ff6ab7ee699568e037a8105f9b6" title="A registration cookie.">dtn_reg_id_t</a> <a class="code" href="dtncat_8c.html#8eb0c3e35c1feb7baf9802f03bf42e41">regid</a> = <a class="code" href="dtn__types_8h.html#f96cd9cebfff24e37ccececf05ebb4e6" title="Value for an unspecified registration cookie (i.e.">DTN_REGID_NONE</a>;
<a name="l00059"></a>00059     <a class="code" href="structdtn__bundle__spec__t.html" title="Bundle metadata.">dtn_bundle_spec_t</a> <a class="code" href="dtncat_8c.html#70f601fc23b0cc97480972bf1ecf7f6c">bundle_spec</a>;
<a name="l00060"></a>00060     <a class="code" href="structdtn__bundle__spec__t.html" title="Bundle metadata.">dtn_bundle_spec_t</a> <a class="code" href="dtncat_8c.html#cad3457d57f7286e1e4e7caa1a619e25">reply_spec</a>;
<a name="l00061"></a>00061     <a class="code" href="structdtn__bundle__payload__t.html">dtn_bundle_payload_t</a> send_payload;
<a name="l00062"></a>00062     <a class="code" href="structdtn__bundle__payload__t.html">dtn_bundle_payload_t</a> <a class="code" href="dtncat_8c.html#f6ba744d4931e7c678cf04716560bfca">reply_payload</a>;
<a name="l00063"></a>00063     <a class="code" href="structdtn__bundle__id__t.html" title="Type definition for a unique bundle identifier.">dtn_bundle_id_t</a> <a class="code" href="dtncat_8c.html#0d43174f8d3844aa5df38af2712ccb00">bundle_id</a>;
<a name="l00064"></a>00064     <span class="keywordtype">char</span> demux[4096];
<a name="l00065"></a>00065     <span class="keyword">struct </span>timeval start, end;
<a name="l00066"></a>00066 
<a name="l00067"></a>00067 <span class="comment">/*     FILE * file; */</span>
<a name="l00068"></a>00068 <span class="comment">/*     //struct stat finfo; */</span>
<a name="l00069"></a>00069 <span class="comment">/*     char buffer[4096]; // max filesize to send is 4096 (temp) */</span>
<a name="l00070"></a>00070 <span class="comment">/*     int bufsize = 0; */</span>
<a name="l00071"></a>00071 
<a name="l00072"></a>00072     <span class="comment">// force stdout to always be line buffered, even if output is</span>
<a name="l00073"></a>00073     <span class="comment">// redirected to a pipe or file</span>
<a name="l00074"></a>00074     setvbuf(stdout, (<span class="keywordtype">char</span> *)NULL, _IOLBF, 0);
<a name="l00075"></a>00075     
<a name="l00076"></a>00076     <a class="code" href="dtncat_8c.html#293abb58b132c26701dada5c4e57ca35">parse_options</a>(argc, argv);
<a name="l00077"></a>00077 
<a name="l00078"></a>00078     <span class="comment">// open the ipc handle</span>
<a name="l00079"></a>00079     <span class="keywordflow">if</span> (<a class="code" href="dtncat_8c.html#0b2caeb4b6f130be43e5a2f0267dd453">verbose</a>) fprintf(stdout, <span class="stringliteral">"Opening connection to local DTN daemon\n"</span>);
<a name="l00080"></a>00080 
<a name="l00081"></a>00081     <span class="keywordtype">int</span> err = <a class="code" href="dtn__api_8c.html#3afc66b2e2c75fae07a45467df9f74e9" title="Open a new connection to the router.">dtn_open</a>(&amp;handle);
<a name="l00082"></a>00082     <span class="keywordflow">if</span> (err != <a class="code" href="dtn__errno_8h.html#3723251cb5d056b6ace3e22561da1e11" title="DTN API error codes.">DTN_SUCCESS</a>) {
<a name="l00083"></a>00083         fprintf(stderr, <span class="stringliteral">"fatal error opening dtn handle: %s\n"</span>,
<a name="l00084"></a>00084                 <a class="code" href="dtn__errno_8c.html#1b23d549407e59e3ce2a1c32e3885b1d" title="Get a string value associated with the dtn error code.">dtn_strerror</a>(err));
<a name="l00085"></a>00085         exit(1);
<a name="l00086"></a>00086     }
<a name="l00087"></a>00087 
<a name="l00088"></a>00088 
<a name="l00089"></a>00089     <span class="comment">// ----------------------------------------------------</span>
<a name="l00090"></a>00090     <span class="comment">// initialize bundle spec with src/dest/replyto</span>
<a name="l00091"></a>00091     <span class="comment">// ----------------------------------------------------</span>
<a name="l00092"></a>00092 
<a name="l00093"></a>00093     <span class="comment">// initialize bundle spec</span>
<a name="l00094"></a>00094     memset(&amp;bundle_spec, 0, <span class="keyword">sizeof</span>(bundle_spec));
<a name="l00095"></a>00095 
<a name="l00096"></a>00096     <span class="comment">// destination host is specified at run time, demux is hardcoded</span>
<a name="l00097"></a>00097     sprintf(demux, <span class="stringliteral">"%s/dtncp/recv?file=%s"</span>, <a class="code" href="dtncat_8c.html#8f7af606d1623c716486d0dab4c70391">arg_dest</a>, <a class="code" href="dtncp_8c.html#33e4194393d4303c48a446b78b4250e9">arg_target</a>);
<a name="l00098"></a>00098     <a class="code" href="dtncat_8c.html#8b10ca66cacac0bc52c3ce6737d8c85a">parse_eid</a>(handle, &amp;bundle_spec.<a class="code" href="structdtn__bundle__spec__t.html#8c2816b3ce9b92489b3b34c325a4cb4c">dest</a>, demux);
<a name="l00099"></a>00099 
<a name="l00100"></a>00100     <span class="comment">// source is local eid with file path as demux string</span>
<a name="l00101"></a>00101     sprintf(demux, <span class="stringliteral">"/dtncp/send?source=%s"</span>, <a class="code" href="dtncp_8c.html#9751128f4dcd9cccc1b82f5f82801871">data_source</a>);
<a name="l00102"></a>00102     <a class="code" href="dtncat_8c.html#8b10ca66cacac0bc52c3ce6737d8c85a">parse_eid</a>(handle, &amp;bundle_spec.<a class="code" href="structdtn__bundle__spec__t.html#3e0a3530457d11bea38b06d00dea30fa">source</a>, demux);
<a name="l00103"></a>00103 
<a name="l00104"></a>00104     <span class="keywordflow">if</span> (<a class="code" href="dtncat_8c.html#0b2caeb4b6f130be43e5a2f0267dd453">verbose</a>)
<a name="l00105"></a>00105     {
<a name="l00106"></a>00106         <a class="code" href="dtncat_8c.html#a9d57d4d6b613ab254545fd140ebe5c8">print_eid</a>(<span class="stringliteral">"source_eid"</span>, &amp;bundle_spec.<a class="code" href="structdtn__bundle__spec__t.html#3e0a3530457d11bea38b06d00dea30fa">source</a>);
<a name="l00107"></a>00107         <a class="code" href="dtncat_8c.html#a9d57d4d6b613ab254545fd140ebe5c8">print_eid</a>(<span class="stringliteral">"dest_eid"</span>, &amp;bundle_spec.<a class="code" href="structdtn__bundle__spec__t.html#8c2816b3ce9b92489b3b34c325a4cb4c">dest</a>);
<a name="l00108"></a>00108     }
<a name="l00109"></a>00109 
<a name="l00110"></a>00110     <span class="comment">// set the expiration time (one hour)</span>
<a name="l00111"></a>00111     bundle_spec.<a class="code" href="structdtn__bundle__spec__t.html#57f2d6068db6a5b38a73416ea721e814">expiration</a> = <a class="code" href="dtncp_8c.html#8b5dae09419110acc1d2e3d97b8bccd7">expiration_time</a>;
<a name="l00112"></a>00112     
<a name="l00113"></a>00113     <span class="keywordflow">if</span> (<a class="code" href="dtncat_8c.html#1bdbebbcf901e059d8765070846f9ee8">delivery_receipts</a>)
<a name="l00114"></a>00114     {
<a name="l00115"></a>00115         <span class="comment">// set the delivery receipt option</span>
<a name="l00116"></a>00116         bundle_spec.<a class="code" href="structdtn__bundle__spec__t.html#476482803410f3a19b40cbff91e1e56c">dopts</a> |= <a class="code" href="dtn__types_8h.html#ed7af5cc4e44a2ced1acdee4e441f000961c42551cde98aaccb2272d32f0a06c">DOPTS_DELIVERY_RCPT</a>;
<a name="l00117"></a>00117     }
<a name="l00118"></a>00118 
<a name="l00119"></a>00119     <span class="comment">// fill in a payload</span>
<a name="l00120"></a>00120     memset(&amp;send_payload, 0, <span class="keyword">sizeof</span>(send_payload));
<a name="l00121"></a>00121 
<a name="l00122"></a>00122     <a class="code" href="dtn__api_8c.html#21b6d705673aae970524972aca3db99f" title="Sets the value of the given payload structure to either a memory buffer or a file...">dtn_set_payload</a>(&amp;send_payload, <a class="code" href="dtn__types_8h.html#3dcfddc1b850a71a18d8a0868f67e7621ff9272291ffe7d9f8083e7c5a548909">DTN_PAYLOAD_FILE</a>,
<a name="l00123"></a>00123         <a class="code" href="dtncp_8c.html#9751128f4dcd9cccc1b82f5f82801871">data_source</a>, strlen(<a class="code" href="dtncp_8c.html#9751128f4dcd9cccc1b82f5f82801871">data_source</a>));
<a name="l00124"></a>00124      
<a name="l00125"></a>00125     <span class="comment">// send file and wait for reply</span>
<a name="l00126"></a>00126 
<a name="l00127"></a>00127     <span class="comment">// create a new dtn registration to receive bundle status reports</span>
<a name="l00128"></a>00128     memset(&amp;reginfo, 0, <span class="keyword">sizeof</span>(reginfo));
<a name="l00129"></a>00129     <a class="code" href="dtn__api_8c.html#b2935a9a7f4ade630f7d2ad1fec5c615" title="Copy the contents of one eid into another.">dtn_copy_eid</a>(&amp;reginfo.<a class="code" href="structdtn__reg__info__t.html#07df1822e2808b2127710a8b54acd07f">endpoint</a>, &amp;bundle_spec.<a class="code" href="structdtn__bundle__spec__t.html#3e0a3530457d11bea38b06d00dea30fa">source</a>);
<a name="l00130"></a>00130     reginfo.<a class="code" href="structdtn__reg__info__t.html#7bf2e33b713b585bfe1792c40fa8cd6c">flags</a> = <a class="code" href="dtn__types_8h.html#a6d0071f396dd4ef85f6ad6332e37f00d21fdf39ccc69d6790aec0c70ce5f972">DTN_REG_DEFER</a>;
<a name="l00131"></a>00131     reginfo.<a class="code" href="structdtn__reg__info__t.html#6909a69cc63e748899cf4f9fe8c8901a">regid</a> = regid;
<a name="l00132"></a>00132     reginfo.<a class="code" href="structdtn__reg__info__t.html#dd4b3b0c9f27a0375369f35e33be686d">expiration</a> = 0;
<a name="l00133"></a>00133     <span class="keywordflow">if</span> ((ret = <a class="code" href="dtn__api_8c.html#7384bf592d4aff0892ff948aafa98b0c" title="Create a dtn registration.">dtn_register</a>(handle, &amp;reginfo, &amp;regid)) != 0) {
<a name="l00134"></a>00134         fprintf(stderr, <span class="stringliteral">"error creating registration (id=%d): %d (%s)\n"</span>,
<a name="l00135"></a>00135                 regid, ret, <a class="code" href="dtn__errno_8c.html#1b23d549407e59e3ce2a1c32e3885b1d" title="Get a string value associated with the dtn error code.">dtn_strerror</a>(<a class="code" href="dtn__api_8c.html#6183d81d5f742d13e1fdee26423d94b4" title="Get the error associated with the given handle.">dtn_errno</a>(handle)));
<a name="l00136"></a>00136         exit(1);
<a name="l00137"></a>00137     }
<a name="l00138"></a>00138     
<a name="l00139"></a>00139     <span class="keywordflow">if</span> (<a class="code" href="dtncat_8c.html#0b2caeb4b6f130be43e5a2f0267dd453">verbose</a>) printf(<span class="stringliteral">"dtn_register succeeded, regid 0x%x\n"</span>, regid);
<a name="l00140"></a>00140 
<a name="l00141"></a>00141     <a class="code" href="namespacedtnsim.html#372b0bd474085f20b38efbbade7ce72a" title="Override gettimeofday to return the simulator time.">gettimeofday</a>(&amp;start, NULL); <span class="comment">// timer</span>
<a name="l00142"></a>00142 
<a name="l00143"></a>00143     memset(&amp;bundle_id, 0, <span class="keyword">sizeof</span>(bundle_id));
<a name="l00144"></a>00144                 
<a name="l00145"></a>00145     <span class="keywordflow">if</span> ((ret = <a class="code" href="dtn__api_8c.html#9bcce797cfff268e49c0f5b2e5f21788" title="Send a bundle either from memory or from a file.">dtn_send</a>(handle, regid, &amp;bundle_spec, &amp;send_payload,
<a name="l00146"></a>00146                         &amp;bundle_id)) != 0) {
<a name="l00147"></a>00147         fprintf(stderr, <span class="stringliteral">"error sending file bundle: %d (%s)\n"</span>,
<a name="l00148"></a>00148                 ret, <a class="code" href="dtn__errno_8c.html#1b23d549407e59e3ce2a1c32e3885b1d" title="Get a string value associated with the dtn error code.">dtn_strerror</a>(<a class="code" href="dtn__api_8c.html#6183d81d5f742d13e1fdee26423d94b4" title="Get the error associated with the given handle.">dtn_errno</a>(handle)));
<a name="l00149"></a>00149         exit(1);
<a name="l00150"></a>00150     }
<a name="l00151"></a>00151 
<a name="l00152"></a>00152     <span class="keywordflow">if</span> (<a class="code" href="dtncat_8c.html#1bdbebbcf901e059d8765070846f9ee8">delivery_receipts</a>)
<a name="l00153"></a>00153       {
<a name="l00154"></a>00154         memset(&amp;reply_spec, 0, <span class="keyword">sizeof</span>(reply_spec));
<a name="l00155"></a>00155         memset(&amp;reply_payload, 0, <span class="keyword">sizeof</span>(reply_payload));
<a name="l00156"></a>00156         
<a name="l00157"></a>00157         <span class="comment">// now we block waiting for the echo reply</span>
<a name="l00158"></a>00158         <span class="keywordflow">if</span> ((ret = <a class="code" href="dtn__api_8c.html#7005346bb34aabb5b6332690871fe3f4" title="Blocking receive for a bundle, filling in the spec and payload structures with the...">dtn_recv</a>(handle, &amp;reply_spec,
<a name="l00159"></a>00159                             <a class="code" href="dtn__types_8h.html#3dcfddc1b850a71a18d8a0868f67e7628f773bbfb80857bd5a11f09665fa9b03">DTN_PAYLOAD_MEM</a>, &amp;reply_payload, -1)) &lt; 0)
<a name="l00160"></a>00160           {
<a name="l00161"></a>00161             fprintf(stderr, <span class="stringliteral">"error getting reply: %d (%s)\n"</span>,
<a name="l00162"></a>00162                     ret, <a class="code" href="dtn__errno_8c.html#1b23d549407e59e3ce2a1c32e3885b1d" title="Get a string value associated with the dtn error code.">dtn_strerror</a>(<a class="code" href="dtn__api_8c.html#6183d81d5f742d13e1fdee26423d94b4" title="Get the error associated with the given handle.">dtn_errno</a>(handle)));
<a name="l00163"></a>00163             exit(1);
<a name="l00164"></a>00164           }
<a name="l00165"></a>00165         <a class="code" href="namespacedtnsim.html#372b0bd474085f20b38efbbade7ce72a" title="Override gettimeofday to return the simulator time.">gettimeofday</a>(&amp;end, NULL);
<a name="l00166"></a>00166 
<a name="l00167"></a>00167 
<a name="l00168"></a>00168         printf(<span class="stringliteral">"file sent successfully to [%s]: time=%.1f ms\n"</span>,
<a name="l00169"></a>00169                reply_spec.<a class="code" href="structdtn__bundle__spec__t.html#3e0a3530457d11bea38b06d00dea30fa">source</a>.<a class="code" href="structdtn__endpoint__id__t.html#d2e7d5788ae778c77b4041f1f8b1dc80">uri</a>,
<a name="l00170"></a>00170                ((<span class="keywordtype">double</span>)(end.tv_sec - start.tv_sec) * 1000.0 + 
<a name="l00171"></a>00171                 (<span class="keywordtype">double</span>)(end.tv_usec - start.tv_usec)/1000.0));
<a name="l00172"></a>00172         
<a name="l00173"></a>00173         <a class="code" href="dtn__api_8c.html#50a363bf1bf2803892afc1438ab62cff" title="Frees dynamic storage allocated by the xdr for a bundle payload in dtn_recv.">dtn_free_payload</a>(&amp;reply_payload);
<a name="l00174"></a>00174       } 
<a name="l00175"></a>00175     <span class="keywordflow">else</span> 
<a name="l00176"></a>00176       {
<a name="l00177"></a>00177         printf(<span class="stringliteral">"file sent to [%s]\n"</span>,
<a name="l00178"></a>00178                bundle_spec.<a class="code" href="structdtn__bundle__spec__t.html#8c2816b3ce9b92489b3b34c325a4cb4c">dest</a>.<a class="code" href="structdtn__endpoint__id__t.html#d2e7d5788ae778c77b4041f1f8b1dc80">uri</a>);
<a name="l00179"></a>00179       }
<a name="l00180"></a>00180 
<a name="l00181"></a>00181     <a class="code" href="dtn__api_8c.html#887c16260463d6057bf5b03a1ff0e224" title="Close an open dtn handle.">dtn_close</a>(handle);
<a name="l00182"></a>00182     
<a name="l00183"></a>00183     <span class="keywordflow">return</span> 0;
<a name="l00184"></a>00184 }
<a name="l00185"></a>00185 
<a name="l00186"></a>00186 <span class="keywordtype">void</span> <a class="code" href="dtncat_8c.html#e5ad5cbeccaedc03a48d3c7eaa803e79">print_usage</a>()
<a name="l00187"></a>00187 {
<a name="l00188"></a>00188     fprintf(stderr,
<a name="l00189"></a>00189             <span class="stringliteral">"usage: %s [-D] [--expiration sec] &lt;filename&gt; &lt;destination_eid&gt; &lt;remote-name&gt;\n"</span>, 
<a name="l00190"></a>00190             <a class="code" href="dtncat_8c.html#b9e1449fd00c98428516f0b41eddcb10">progname</a>);
<a name="l00191"></a>00191     fprintf(stderr,
<a name="l00192"></a>00192             <span class="stringliteral">"    Remote filename is optional; defaults to the "</span>
<a name="l00193"></a>00193             <span class="stringliteral">"local filename.\n\n"</span>
<a name="l00194"></a>00194             <span class="stringliteral">"-D disables acknowledgements\n"</span>
<a name="l00195"></a>00195             <span class="stringliteral">"Bundle expiration time is in seconds.\n"</span>);
<a name="l00196"></a>00196     
<a name="l00197"></a>00197     exit(1);
<a name="l00198"></a>00198 }
<a name="l00199"></a>00199 
<a name="l00200"></a>00200 <span class="keywordtype">void</span> <a class="code" href="dtncat_8c.html#293abb58b132c26701dada5c4e57ca35">parse_options</a>(<span class="keywordtype">int</span> argc, <span class="keywordtype">char</span>**argv)
<a name="l00201"></a>00201 {
<a name="l00202"></a>00202     <a class="code" href="dtncat_8c.html#b9e1449fd00c98428516f0b41eddcb10">progname</a> = argv[0];
<a name="l00203"></a>00203 
<a name="l00204"></a>00204     <span class="comment">// expiration time in seconds</span>
<a name="l00205"></a>00205     <span class="keywordflow">if</span> (argc &lt; 2)
<a name="l00206"></a>00206         <span class="keywordflow">goto</span> bail;
<a name="l00207"></a>00207 
<a name="l00208"></a>00208     <span class="keywordflow">if</span> (strcmp(argv[1], <span class="stringliteral">"--expiration"</span>) == 0)
<a name="l00209"></a>00209     {
<a name="l00210"></a>00210         argv++;
<a name="l00211"></a>00211         argc--;
<a name="l00212"></a>00212         
<a name="l00213"></a>00213         <span class="keywordflow">if</span> (argc &lt; 2)
<a name="l00214"></a>00214             <span class="keywordflow">goto</span> bail;
<a name="l00215"></a>00215         
<a name="l00216"></a>00216         <a class="code" href="dtncp_8c.html#8b5dae09419110acc1d2e3d97b8bccd7">expiration_time</a> = atoi(argv[1]);
<a name="l00217"></a>00217         <span class="keywordflow">if</span> (<a class="code" href="dtncp_8c.html#8b5dae09419110acc1d2e3d97b8bccd7">expiration_time</a> == 0)
<a name="l00218"></a>00218         {
<a name="l00219"></a>00219             fprintf(stderr, 
<a name="l00220"></a>00220                     <span class="stringliteral">"Expiration time must be &gt; 0\n"</span>);
<a name="l00221"></a>00221             exit(1);
<a name="l00222"></a>00222         }
<a name="l00223"></a>00223 
<a name="l00224"></a>00224         argv++;
<a name="l00225"></a>00225         argc--;
<a name="l00226"></a>00226     }
<a name="l00227"></a>00227 
<a name="l00228"></a>00228     <span class="comment">// no reply</span>
<a name="l00229"></a>00229     <span class="keywordflow">if</span> (argc &lt; 2)
<a name="l00230"></a>00230         <span class="keywordflow">goto</span> bail;
<a name="l00231"></a>00231 
<a name="l00232"></a>00232     <span class="keywordflow">if</span> (strcmp(argv[1], <span class="stringliteral">"-D"</span>) == 0)
<a name="l00233"></a>00233       {
<a name="l00234"></a>00234         <a class="code" href="dtncat_8c.html#1bdbebbcf901e059d8765070846f9ee8">delivery_receipts</a> = 1;
<a name="l00235"></a>00235         
<a name="l00236"></a>00236         argv++;
<a name="l00237"></a>00237         argc--;
<a name="l00238"></a>00238       }
<a name="l00239"></a>00239 
<a name="l00240"></a>00240     <span class="comment">// parse the normal arguments</span>
<a name="l00241"></a>00241     <span class="keywordflow">if</span> (argc &lt; 3)
<a name="l00242"></a>00242         <span class="keywordflow">goto</span> bail;
<a name="l00243"></a>00243 
<a name="l00244"></a>00244     <span class="keywordflow">if</span> (argv[1][0] == <span class="charliteral">'/'</span>) sprintf(<a class="code" href="dtncp_8c.html#9751128f4dcd9cccc1b82f5f82801871">data_source</a>, <span class="stringliteral">"%s"</span>, argv[1]);
<a name="l00245"></a>00245     <span class="keywordflow">else</span> sprintf(<a class="code" href="dtncp_8c.html#9751128f4dcd9cccc1b82f5f82801871">data_source</a>, <span class="stringliteral">"%s/%s"</span>, getenv(<span class="stringliteral">"PWD"</span>), argv[1]);
<a name="l00246"></a>00246 
<a name="l00247"></a>00247     <a class="code" href="dtncat_8c.html#8f7af606d1623c716486d0dab4c70391">arg_dest</a> = argv[2];
<a name="l00248"></a>00248     <span class="keywordflow">if</span> (argc &gt; 3)
<a name="l00249"></a>00249     {
<a name="l00250"></a>00250         <a class="code" href="dtncp_8c.html#33e4194393d4303c48a446b78b4250e9">arg_target</a> = argv[3];
<a name="l00251"></a>00251     }
<a name="l00252"></a>00252     <span class="keywordflow">else</span> 
<a name="l00253"></a>00253     {
<a name="l00254"></a>00254         <a class="code" href="dtncp_8c.html#33e4194393d4303c48a446b78b4250e9">arg_target</a> = strrchr(<a class="code" href="dtncp_8c.html#9751128f4dcd9cccc1b82f5f82801871">data_source</a>, <span class="charliteral">'/'</span>);
<a name="l00255"></a>00255         <span class="keywordflow">if</span> (<a class="code" href="dtncp_8c.html#33e4194393d4303c48a446b78b4250e9">arg_target</a> == 0) <a class="code" href="dtncp_8c.html#33e4194393d4303c48a446b78b4250e9">arg_target</a> = <a class="code" href="dtncp_8c.html#9751128f4dcd9cccc1b82f5f82801871">data_source</a>;
<a name="l00256"></a>00256     }
<a name="l00257"></a>00257 
<a name="l00258"></a>00258     <span class="keywordflow">return</span>;
<a name="l00259"></a>00259 
<a name="l00260"></a>00260   bail:
<a name="l00261"></a>00261         <a class="code" href="dtncat_8c.html#e5ad5cbeccaedc03a48d3c7eaa803e79">print_usage</a>();
<a name="l00262"></a>00262         exit(1);
<a name="l00263"></a>00263 }
<a name="l00264"></a>00264 
<a name="l00265"></a>00265 <a class="code" href="structdtn__endpoint__id__t.html" title="Specification of a dtn endpoint id, i.e.">dtn_endpoint_id_t</a> * <a class="code" href="dtncat_8c.html#8b10ca66cacac0bc52c3ce6737d8c85a">parse_eid</a>(<a class="code" href="dtn__api_8h.html#566289d829b69370d7635c21364bfe18" title="The basic handle for communication with the dtn router.">dtn_handle_t</a> <a class="code" href="dtncat_8c.html#01daea96255bb21a8979b3b45f5bbb70">handle</a>, 
<a name="l00266"></a>00266                           <a class="code" href="structdtn__endpoint__id__t.html" title="Specification of a dtn endpoint id, i.e.">dtn_endpoint_id_t</a> * eid, <span class="keywordtype">char</span> * str)
<a name="l00267"></a>00267 {
<a name="l00268"></a>00268     
<a name="l00269"></a>00269     <span class="comment">// try the string as an actual dtn eid</span>
<a name="l00270"></a>00270     <span class="keywordflow">if</span> (!<a class="code" href="dtn__api_8c.html#055c8bb8eaa570aacbe6a164ff123c84" title="Parse a string into an endpoint id structure, validating that it is in fact a valid...">dtn_parse_eid_string</a>(eid, str)) 
<a name="l00271"></a>00271     {
<a name="l00272"></a>00272         <span class="keywordflow">return</span> eid;
<a name="l00273"></a>00273     }
<a name="l00274"></a>00274     <span class="comment">// build a local eid based on the configuration of our dtn</span>
<a name="l00275"></a>00275     <span class="comment">// router plus the str as demux string</span>
<a name="l00276"></a>00276     <span class="keywordflow">else</span> <span class="keywordflow">if</span> (!<a class="code" href="dtn__api_8c.html#0947b9119c69984edf25df43ead8858b" title="Build an appropriate local endpoint id by appending the specified service tag to...">dtn_build_local_eid</a>(handle, eid, str))
<a name="l00277"></a>00277     {
<a name="l00278"></a>00278         <span class="keywordflow">return</span> eid;
<a name="l00279"></a>00279     }
<a name="l00280"></a>00280     <span class="keywordflow">else</span>
<a name="l00281"></a>00281     {
<a name="l00282"></a>00282         fprintf(stderr, <span class="stringliteral">"invalid endpoint id string '%s'\n"</span>, str);
<a name="l00283"></a>00283         exit(1);
<a name="l00284"></a>00284     }
<a name="l00285"></a>00285 }
<a name="l00286"></a>00286 
<a name="l00287"></a><a class="code" href="dtncp_8c.html#ecc3519b0625ad9c7bae39fc21b08d2d">00287</a> <span class="keywordtype">void</span> <a class="code" href="dtncat_8c.html#a9d57d4d6b613ab254545fd140ebe5c8">print_eid</a>(<span class="keywordtype">char</span> *  label, <a class="code" href="structdtn__endpoint__id__t.html" title="Specification of a dtn endpoint id, i.e.">dtn_endpoint_id_t</a> * eid)
<a name="l00288"></a>00288 {
<a name="l00289"></a>00289     printf(<span class="stringliteral">"%s [%s]\n"</span>, label, eid-&gt;<a class="code" href="structdtn__endpoint__id__t.html#d2e7d5788ae778c77b4041f1f8b1dc80">uri</a>);
<a name="l00290"></a>00290 }
<a name="l00291"></a>00291     
<a name="l00292"></a>00292 
<a name="l00293"></a>00293 
<a name="l00294"></a>00294 
</pre></div></div>
<hr size="1"><address style="text-align: right;"><small>Generated on Fri Jan 30 09:26:55 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>