<!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: dtnperf-server.c 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 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>dtnperf-server.c</h1><a href="dtnperf-server_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 2005-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="comment">/* ----------------------</span> <a name="l00018"></a>00018 <span class="comment"> * dtnperf-server.c</span> <a name="l00019"></a>00019 <span class="comment"> * ---------------------- */</span> <a name="l00020"></a>00020 <a name="l00021"></a>00021 <span class="comment">/* -----------------------------------------------------------</span> <a name="l00022"></a>00022 <span class="comment"> * PLEASE NOTE: this software was developed</span> <a name="l00023"></a>00023 <span class="comment"> * by Piero Cornice <piero.cornice@gmail.com></span> <a name="l00024"></a>00024 <span class="comment"> * at DEIS - University of Bologna, Italy.</span> <a name="l00025"></a>00025 <span class="comment"> * If you want to modify it, please contact me</span> <a name="l00026"></a>00026 <span class="comment"> * at piero.cornice(at)gmail.com. Thanks =)</span> <a name="l00027"></a>00027 <span class="comment"> * -----------------------------------------------------------</span> <a name="l00028"></a>00028 <span class="comment"> */</span> <a name="l00029"></a>00029 <a name="l00030"></a>00030 <span class="comment">/* version 1.6.0 - 23/06/06</span> <a name="l00031"></a>00031 <span class="comment"> *</span> <a name="l00032"></a>00032 <span class="comment"> * - compatible with DTN 2.2.0 reference implementation</span> <a name="l00033"></a>00033 <span class="comment"> */</span> <a name="l00034"></a>00034 <a name="l00035"></a>00035 <span class="preprocessor">#ifdef HAVE_CONFIG_H</span> <a name="l00036"></a>00036 <span class="preprocessor"></span><span class="preprocessor"># include <<a class="code" href="dtn-config_8h.html">dtn-config.h</a>></span> <a name="l00037"></a>00037 <span class="preprocessor">#endif</span> <a name="l00038"></a>00038 <span class="preprocessor"></span> <a name="l00039"></a>00039 <span class="preprocessor">#include <stdio.h></span> <a name="l00040"></a>00040 <span class="preprocessor">#include <unistd.h></span> <a name="l00041"></a>00041 <span class="preprocessor">#include <errno.h></span> <a name="l00042"></a>00042 <span class="preprocessor">#include <strings.h></span> <a name="l00043"></a>00043 <span class="preprocessor">#include <string.h></span> <a name="l00044"></a>00044 <span class="preprocessor">#include <stdlib.h></span> <a name="l00045"></a>00045 <span class="preprocessor">#include <time.h></span> <a name="l00046"></a>00046 <span class="preprocessor">#include "<a class="code" href="dtn__api_8h.html">dtn_api.h</a>"</span> <a name="l00047"></a>00047 <span class="preprocessor">#include <sys/stat.h></span> <a name="l00048"></a>00048 <a name="l00049"></a><a class="code" href="dtnperf-server_8c.html#eca034f67218340ecb2261a22c2f3dcd">00049</a> <span class="preprocessor">#define BUFSIZE 16</span> <a name="l00050"></a><a class="code" href="dtnperf-server_8c.html#e15a995a7a30a0d14d0db7362b90ce27">00050</a> <span class="preprocessor"></span><span class="preprocessor">#define BUNDLE_DIR_DEFAULT INSTALL_LOCALSTATEDIR "/dtn/dtnperf"</span> <a name="l00051"></a><a class="code" href="dtnperf-server_8c.html#32cc9d976eaa3b33e3cdbc87e47c72a1">00051</a> <span class="preprocessor"></span><span class="preprocessor">#define OUTFILE "dtnbuffer.rcv"</span> <a name="l00052"></a>00052 <span class="preprocessor"></span> <a name="l00053"></a>00053 <span class="comment">/* ------------------------------</span> <a name="l00054"></a>00054 <span class="comment"> * Global variables and options</span> <a name="l00055"></a>00055 <span class="comment"> * ------------------------------ */</span> <a name="l00056"></a>00056 <a name="l00057"></a>00057 <span class="comment">// values between [square braces] are default</span> <a name="l00058"></a><a class="code" href="dtnperf-server_8c.html#d785d8a8f8ff378aa21eb1fa7a6085df">00058</a> <span class="keyword">const</span> <span class="keywordtype">char</span> *<a class="code" href="dtncat_8c.html#b9e1449fd00c98428516f0b41eddcb10">progname</a> ; <a name="l00059"></a><a class="code" href="dtnperf-server_8c.html#f72f0fe7b03d82b7ee28f9f9bd395d12">00059</a> <span class="keywordtype">int</span> <a class="code" href="dtnperf-client_8c.html#f72f0fe7b03d82b7ee28f9f9bd395d12">use_file</a> = 1; <span class="comment">// if set to 0, memorize received bundles into memory (max 50000 bytes)</span> <a name="l00060"></a>00060 <span class="comment">// if set to 1, memorize received bundles into a file (-f) [0]</span> <a name="l00061"></a><a class="code" href="dtnperf-server_8c.html#0b2caeb4b6f130be43e5a2f0267dd453">00061</a> <span class="keywordtype">int</span> <a class="code" href="dtncat_8c.html#0b2caeb4b6f130be43e5a2f0267dd453">verbose</a> = 0; <span class="comment">// if set to 1, show verbose messages [0]</span> <a name="l00062"></a><a class="code" href="dtnperf-server_8c.html#cd3810a883cd2d3430c4ec9922df3c9c">00062</a> <span class="keywordtype">int</span> <a class="code" href="dtnperf-server_8c.html#cd3810a883cd2d3430c4ec9922df3c9c">aggregate</a> = 0; <span class="comment">// if > 0, print after aggregate arrivals</span> <a name="l00063"></a><a class="code" href="dtnperf-server_8c.html#c3e1795766a80ec63b157951b4b9a7d4">00063</a> <span class="keywordtype">int</span> <a class="code" href="dtnmoteproxy_8c.html#ae6a9b084de32dbd181692c52c5e97de">debug</a> = 0; <span class="comment">// if set to 1, show debug messages [1]</span> <a name="l00064"></a><a class="code" href="dtnperf-server_8c.html#6d2d1c31529bee906473fcabaffff34f">00064</a> <span class="keywordtype">char</span> * <a class="code" href="dtnperf-server_8c.html#6d2d1c31529bee906473fcabaffff34f">endpoint</a> = <span class="stringliteral">"/dtnperf:/dest"</span>; <span class="comment">// endpoint (-e) ["/dtnperf:/dest"]</span> <a name="l00065"></a><a class="code" href="dtnperf-server_8c.html#1bc5fad21b936109b622e4992ad1e0c2">00065</a> <span class="keywordtype">char</span> * <a class="code" href="dtnperf-server_8c.html#1bc5fad21b936109b622e4992ad1e0c2">bundle_dir</a> = <a class="code" href="dtncpd_8c.html#e15a995a7a30a0d14d0db7362b90ce27">BUNDLE_DIR_DEFAULT</a>; <span class="comment">// destination directory (-d)</span> <a name="l00066"></a>00066 <a name="l00067"></a>00067 <span class="comment">/* ------------------------</span> <a name="l00068"></a>00068 <span class="comment"> * Function Prototypes</span> <a name="l00069"></a>00069 <span class="comment"> * ------------------------ */</span> <a name="l00070"></a>00070 <span class="keywordtype">void</span> <a class="code" href="dtncat_8c.html#e5ad5cbeccaedc03a48d3c7eaa803e79">print_usage</a>(<span class="keywordtype">char</span>*); <a name="l00071"></a>00071 <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="l00072"></a>00072 <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="structdtn__endpoint__id__t.html" title="Specification of a dtn endpoint id, i.e.">dtn_endpoint_id_t</a>*, <span class="keywordtype">char</span>*); <a name="l00073"></a>00073 <a name="l00074"></a>00074 <a name="l00075"></a>00075 <span class="comment">/* -------------------------------------------------</span> <a name="l00076"></a>00076 <span class="comment"> * main</span> <a name="l00077"></a>00077 <span class="comment"> * ------------------------------------------------- */</span> <a name="l00078"></a><a class="code" href="dtnperf-server_8c.html#3c04138a5bfe5d72780bb7e82a18e627">00078</a> <span class="keywordtype">int</span> <a class="code" href="dtncat_8c.html#3c04138a5bfe5d72780bb7e82a18e627">main</a>(<span class="keywordtype">int</span> argc, <span class="keywordtype">char</span>** argv) <a name="l00079"></a>00079 { <a name="l00080"></a>00080 <a name="l00081"></a>00081 <span class="comment">/* -----------------------</span> <a name="l00082"></a>00082 <span class="comment"> * variables declaration</span> <a name="l00083"></a>00083 <span class="comment"> * ----------------------- */</span> <a name="l00084"></a>00084 <span class="keywordtype">int</span> k; <a name="l00085"></a>00085 <span class="keywordtype">int</span> ret; <a name="l00086"></a>00086 <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="l00087"></a>00087 <a class="code" href="structdtn__endpoint__id__t.html" title="Specification of a dtn endpoint id, i.e.">dtn_endpoint_id_t</a> local_eid; <a name="l00088"></a>00088 <a class="code" href="structdtn__reg__info__t.html" title="Registration state.">dtn_reg_info_t</a> reginfo; <a name="l00089"></a>00089 <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 name="l00090"></a>00090 <a class="code" href="structdtn__bundle__spec__t.html" title="Bundle metadata.">dtn_bundle_spec_t</a> spec; <a name="l00091"></a>00091 <a class="code" href="structdtn__bundle__payload__t.html">dtn_bundle_payload_t</a> payload; <a name="l00092"></a>00092 <span class="keywordtype">char</span> *buffer; <span class="comment">// buffer used for shell commands</span> <a name="l00093"></a>00093 <span class="keywordtype">char</span> s_buffer[<a class="code" href="dtncpd_8c.html#eca034f67218340ecb2261a22c2f3dcd">BUFSIZE</a>]; <a name="l00094"></a>00094 time_t current; <a name="l00095"></a>00095 <a class="code" href="dtn__types_8h.html#3dcfddc1b850a71a18d8a0868f67e762" title="The payload of a bundle can be sent or received either in a file, in which case the...">dtn_bundle_payload_location_t</a> pl_type = <a class="code" href="dtn__types_8h.html#3dcfddc1b850a71a18d8a0868f67e7621ff9272291ffe7d9f8083e7c5a548909">DTN_PAYLOAD_FILE</a>; <span class="comment">// payload saved into memory or into file</span> <a name="l00096"></a>00096 <span class="comment">// char * source_region, dest_region;</span> <a name="l00097"></a>00097 <span class="keywordtype">int</span> source_eid_len, dest_eid_len; <a name="l00098"></a>00098 <span class="keywordtype">char</span> *source_eid, *dest_eid; <a name="l00099"></a>00099 <span class="keywordtype">char</span> * filepath; <a name="l00100"></a>00100 <span class="keywordtype">char</span> * <a class="code" href="dtnrecv_8c.html#b49244970ed5ca30989c2dab2129de34">filename</a> = <a class="code" href="dtnperf-server_8c.html#32cc9d976eaa3b33e3cdbc87e47c72a1">OUTFILE</a>; <span class="comment">// source filename [OUTFILE]</span> <a name="l00101"></a>00101 <span class="keywordtype">int</span> bufsize; <a name="l00102"></a>00102 <span class="keywordtype">int</span> <a class="code" href="dtnping_8c.html#d43c3812e6d13e0518d9f8b8f463ffcf">count</a> = 0; <a name="l00103"></a>00103 <span class="keywordtype">int</span> total = 0; <a name="l00104"></a>00104 <a name="l00105"></a>00105 <span class="comment">/* -------</span> <a name="l00106"></a>00106 <span class="comment"> * begin</span> <a name="l00107"></a>00107 <span class="comment"> * ------- */</span> <a name="l00108"></a>00108 <a name="l00109"></a>00109 <span class="comment">// print information header</span> <a name="l00110"></a>00110 printf(<span class="stringliteral">"\nDTNperf - SERVER - v 1.6.0"</span>); <a name="l00111"></a>00111 printf(<span class="stringliteral">"\nwritten by Piero Cornice <piero.cornice@gmail.com>"</span>); <a name="l00112"></a>00112 printf(<span class="stringliteral">"\nDEIS - University of Bologna, Italy"</span>); <a name="l00113"></a>00113 printf(<span class="stringliteral">"\n"</span>); <a name="l00114"></a>00114 <a name="l00115"></a>00115 <span class="comment">// parse command-line options</span> <a name="l00116"></a>00116 <a class="code" href="dtncat_8c.html#293abb58b132c26701dada5c4e57ca35">parse_options</a>(argc, argv); <a name="l00117"></a>00117 <span class="keywordflow">if</span> (<a class="code" href="dtnmoteproxy_8c.html#ae6a9b084de32dbd181692c52c5e97de">debug</a>) printf(<span class="stringliteral">"[debug] parsed command-line options\n"</span>); <a name="l00118"></a>00118 <a name="l00119"></a>00119 <span class="comment">// show requested options (verbose)</span> <a name="l00120"></a>00120 <span class="keywordflow">if</span> (<a class="code" href="dtncat_8c.html#0b2caeb4b6f130be43e5a2f0267dd453">verbose</a>) { <a name="l00121"></a>00121 printf(<span class="stringliteral">"\nOptions:\n"</span>); <a name="l00122"></a>00122 printf(<span class="stringliteral">"\tendpoint : %s\n"</span>, <a class="code" href="dtnperf-server_8c.html#6d2d1c31529bee906473fcabaffff34f">endpoint</a>); <a name="l00123"></a>00123 printf(<span class="stringliteral">"\tsave bundles to: %s\n"</span>, <a class="code" href="dtnperf-client_8c.html#f72f0fe7b03d82b7ee28f9f9bd395d12">use_file</a> ? <span class="stringliteral">"file"</span> : <span class="stringliteral">"memory"</span>); <a name="l00124"></a>00124 printf(<span class="stringliteral">"\tdestination dir: %s\n"</span>, <a class="code" href="dtnperf-server_8c.html#1bc5fad21b936109b622e4992ad1e0c2">bundle_dir</a>); <a name="l00125"></a>00125 printf(<span class="stringliteral">"\n"</span>); <a name="l00126"></a>00126 } <a name="l00127"></a>00127 <a name="l00128"></a>00128 <span class="comment">// initialize buffer with shell command ("mkdir -p " + bundle_dir)</span> <a name="l00129"></a>00129 <span class="keywordflow">if</span> (<a class="code" href="dtnmoteproxy_8c.html#ae6a9b084de32dbd181692c52c5e97de">debug</a>) printf(<span class="stringliteral">"[debug] initializing buffer with shell command..."</span>); <a name="l00130"></a>00130 buffer = malloc(<span class="keyword">sizeof</span>(<span class="keywordtype">char</span>) * (strlen(<a class="code" href="dtnperf-server_8c.html#1bc5fad21b936109b622e4992ad1e0c2">bundle_dir</a>) + 10)); <a name="l00131"></a>00131 sprintf(buffer, <span class="stringliteral">"mkdir -p %s"</span>, <a class="code" href="dtnperf-server_8c.html#1bc5fad21b936109b622e4992ad1e0c2">bundle_dir</a>); <a name="l00132"></a>00132 <span class="keywordflow">if</span> (<a class="code" href="dtnmoteproxy_8c.html#ae6a9b084de32dbd181692c52c5e97de">debug</a>) printf(<span class="stringliteral">" done. Shell command = %s\n"</span>, buffer); <a name="l00133"></a>00133 <a name="l00134"></a>00134 <span class="comment">// execute shell command</span> <a name="l00135"></a>00135 <span class="keywordflow">if</span> (<a class="code" href="dtnmoteproxy_8c.html#ae6a9b084de32dbd181692c52c5e97de">debug</a>) printf(<span class="stringliteral">"[debug] executing shell command \"%s\"..."</span>, buffer); <a name="l00136"></a>00136 <span class="keywordflow">if</span> (system(buffer) == -1) <a name="l00137"></a>00137 { <a name="l00138"></a>00138 fprintf(stderr, <span class="stringliteral">"Error opening bundle directory: %s\n"</span>, <a class="code" href="dtnperf-server_8c.html#1bc5fad21b936109b622e4992ad1e0c2">bundle_dir</a>); <a name="l00139"></a>00139 exit(1); <a name="l00140"></a>00140 } <a name="l00141"></a>00141 free(buffer); <a name="l00142"></a>00142 <span class="keywordflow">if</span> (<a class="code" href="dtnmoteproxy_8c.html#ae6a9b084de32dbd181692c52c5e97de">debug</a>) printf(<span class="stringliteral">" done\n"</span>); <a name="l00143"></a>00143 <a name="l00144"></a>00144 <span class="comment">// open the ipc handle</span> <a name="l00145"></a>00145 <span class="keywordflow">if</span> (<a class="code" href="dtnmoteproxy_8c.html#ae6a9b084de32dbd181692c52c5e97de">debug</a>) printf(<span class="stringliteral">"[debug] opening connection to dtn router..."</span>); <a name="l00146"></a>00146 <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>(&handle); <a name="l00147"></a>00147 <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="l00148"></a>00148 fprintf(stderr, <span class="stringliteral">"fatal error opening dtn handle: %s\n"</span>, <a name="l00149"></a>00149 <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="l00150"></a>00150 exit(1); <a name="l00151"></a>00151 } <a name="l00152"></a>00152 <span class="keywordflow">if</span> (<a class="code" href="dtnmoteproxy_8c.html#ae6a9b084de32dbd181692c52c5e97de">debug</a>) printf(<span class="stringliteral">" done\n"</span>); <a name="l00153"></a>00153 <a name="l00154"></a>00154 <span class="comment">// build a local tuple based on the configuration of local dtn router</span> <a name="l00155"></a>00155 <span class="keywordflow">if</span> (<a class="code" href="dtnmoteproxy_8c.html#ae6a9b084de32dbd181692c52c5e97de">debug</a>) printf(<span class="stringliteral">"[debug] building local eid..."</span>); <a name="l00156"></a>00156 <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, &local_eid, <a class="code" href="dtnperf-server_8c.html#6d2d1c31529bee906473fcabaffff34f">endpoint</a>); <a name="l00157"></a>00157 <span class="keywordflow">if</span> (<a class="code" href="dtnmoteproxy_8c.html#ae6a9b084de32dbd181692c52c5e97de">debug</a>) printf(<span class="stringliteral">" done\n"</span>); <a name="l00158"></a>00158 <span class="keywordflow">if</span> (<a class="code" href="dtncat_8c.html#0b2caeb4b6f130be43e5a2f0267dd453">verbose</a>) printf(<span class="stringliteral">"local_eid = %s\n"</span>, local_eid.<a class="code" href="structdtn__endpoint__id__t.html#d2e7d5788ae778c77b4041f1f8b1dc80">uri</a>); <a name="l00159"></a>00159 <a name="l00160"></a>00160 <span class="comment">// create a new registration based on this eid</span> <a name="l00161"></a>00161 <span class="keywordflow">if</span> (<a class="code" href="dtnmoteproxy_8c.html#ae6a9b084de32dbd181692c52c5e97de">debug</a>) printf(<span class="stringliteral">"[debug] registering to local daemon..."</span>); <a name="l00162"></a>00162 memset(&reginfo, 0, <span class="keyword">sizeof</span>(reginfo)); <a name="l00163"></a>00163 <a class="code" href="dtn__api_8c.html#b2935a9a7f4ade630f7d2ad1fec5c615" title="Copy the contents of one eid into another.">dtn_copy_eid</a>(&reginfo.<a class="code" href="structdtn__reg__info__t.html#07df1822e2808b2127710a8b54acd07f">endpoint</a>, &local_eid); <a name="l00164"></a>00164 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="l00165"></a>00165 reginfo.<a class="code" href="structdtn__reg__info__t.html#6909a69cc63e748899cf4f9fe8c8901a">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="l00166"></a>00166 reginfo.<a class="code" href="structdtn__reg__info__t.html#dd4b3b0c9f27a0375369f35e33be686d">expiration</a> = 0; <a name="l00167"></a>00167 <span class="keywordflow">if</span> ((ret = <a class="code" href="dtn__api_8c.html#7384bf592d4aff0892ff948aafa98b0c" title="Create a dtn registration.">dtn_register</a>(handle, &reginfo, &regid)) != 0) { <a name="l00168"></a>00168 fprintf(stderr, <span class="stringliteral">"error creating registration: %d (%s)\n"</span>, <a name="l00169"></a>00169 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="l00170"></a>00170 exit(1); <a name="l00171"></a>00171 } <a name="l00172"></a>00172 <span class="keywordflow">if</span> (<a class="code" href="dtnmoteproxy_8c.html#ae6a9b084de32dbd181692c52c5e97de">debug</a>) printf(<span class="stringliteral">" done\n"</span>); <a name="l00173"></a>00173 <span class="keywordflow">if</span> (<a class="code" href="dtncat_8c.html#0b2caeb4b6f130be43e5a2f0267dd453">verbose</a>) printf(<span class="stringliteral">"regid 0x%x\n"</span>, regid); <a name="l00174"></a>00174 <a name="l00175"></a>00175 <span class="comment">// set bundle destination type</span> <a name="l00176"></a>00176 <span class="keywordflow">if</span> (<a class="code" href="dtnmoteproxy_8c.html#ae6a9b084de32dbd181692c52c5e97de">debug</a>) printf(<span class="stringliteral">"[debug] choosing bundle destination type..."</span>); <a name="l00177"></a>00177 <span class="keywordflow">if</span> (<a class="code" href="dtnperf-client_8c.html#f72f0fe7b03d82b7ee28f9f9bd395d12">use_file</a>) <a name="l00178"></a>00178 pl_type = <a class="code" href="dtn__types_8h.html#3dcfddc1b850a71a18d8a0868f67e7621ff9272291ffe7d9f8083e7c5a548909">DTN_PAYLOAD_FILE</a>; <a name="l00179"></a>00179 <span class="keywordflow">else</span> <a name="l00180"></a>00180 pl_type = <a class="code" href="dtn__types_8h.html#3dcfddc1b850a71a18d8a0868f67e7628f773bbfb80857bd5a11f09665fa9b03">DTN_PAYLOAD_MEM</a>; <a name="l00181"></a>00181 <span class="keywordflow">if</span> (<a class="code" href="dtnmoteproxy_8c.html#ae6a9b084de32dbd181692c52c5e97de">debug</a>) printf(<span class="stringliteral">" done. Bundles will be saved into %s\n"</span>, <a class="code" href="dtnperf-client_8c.html#f72f0fe7b03d82b7ee28f9f9bd395d12">use_file</a> ? <span class="stringliteral">"file"</span> : <span class="stringliteral">"memory"</span>); <a name="l00182"></a>00182 <a name="l00183"></a>00183 <span class="keywordflow">if</span> (<a class="code" href="dtnmoteproxy_8c.html#ae6a9b084de32dbd181692c52c5e97de">debug</a>) printf(<span class="stringliteral">"[debug] entering infinite loop...\n"</span>); <a name="l00184"></a>00184 <a name="l00185"></a>00185 <span class="comment">// infinite loop, waiting for bundles</span> <a name="l00186"></a>00186 <span class="keywordflow">while</span> (1) { <a name="l00187"></a>00187 <a name="l00188"></a>00188 <span class="comment">// wait until receive a bundle</span> <a name="l00189"></a>00189 memset(&spec, 0, <span class="keyword">sizeof</span>(spec)); <a name="l00190"></a>00190 memset(&payload, 0, <span class="keyword">sizeof</span>(payload)); <a name="l00191"></a>00191 <a name="l00192"></a>00192 <span class="keywordflow">if</span> (<a class="code" href="dtnmoteproxy_8c.html#ae6a9b084de32dbd181692c52c5e97de">debug</a>) printf(<span class="stringliteral">"[debug] waiting for bundles..."</span>); <a name="l00193"></a>00193 <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, &spec, pl_type, &payload, -1)) < 0) <a name="l00194"></a>00194 { <a name="l00195"></a>00195 fprintf(stderr, <span class="stringliteral">"error getting recv reply: %d (%s)\n"</span>, <a name="l00196"></a>00196 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="l00197"></a>00197 exit(1); <a name="l00198"></a>00198 } <a name="l00199"></a>00199 <span class="keywordflow">if</span> (<a class="code" href="dtnmoteproxy_8c.html#ae6a9b084de32dbd181692c52c5e97de">debug</a>) printf(<span class="stringliteral">" bundle received\n"</span>); <a name="l00200"></a>00200 count++; <a name="l00201"></a>00201 <a name="l00202"></a>00202 <span class="keywordtype">size_t</span> <a class="code" href="num2sdnv_8c.html#fed088663f8704004425cdae2120b9b3">len</a>; <a name="l00203"></a>00203 <span class="keywordflow">if</span> (pl_type == <a class="code" href="dtn__types_8h.html#3dcfddc1b850a71a18d8a0868f67e7628f773bbfb80857bd5a11f09665fa9b03">DTN_PAYLOAD_MEM</a>) { <a name="l00204"></a>00204 len = payload.<a class="code" href="structdtn__bundle__payload__t.html#04e8c46c5b40f187e1fefed80853cc5c">buf</a>.<a class="code" href="structdtn__bundle__payload__t.html#c20a1cf6010dbd5855140373da5ce8c3">buf_len</a>; <a name="l00205"></a>00205 } <span class="keywordflow">else</span> { <a name="l00206"></a>00206 <span class="keyword">struct </span>stat st; <a name="l00207"></a>00207 memset(&st, 0, <span class="keyword">sizeof</span>(st)); <a name="l00208"></a>00208 stat(payload.<a class="code" href="structdtn__bundle__payload__t.html#f3a33fd2ae2b3b8eae2e675f1a038cec">filename</a>.<a class="code" href="structdtn__bundle__payload__t.html#0d824d13c3225cb59fa2e34623608b2a">filename_val</a>, &st); <a name="l00209"></a>00209 len = st.st_size; <a name="l00210"></a>00210 } <a name="l00211"></a>00211 <a name="l00212"></a>00212 total += len; <a name="l00213"></a>00213 <a name="l00214"></a>00214 <span class="comment">// mark current time</span> <a name="l00215"></a>00215 <span class="keywordflow">if</span> (<a class="code" href="dtnmoteproxy_8c.html#ae6a9b084de32dbd181692c52c5e97de">debug</a>) printf(<span class="stringliteral">"[debug] marking time..."</span>); <a name="l00216"></a>00216 current = time(NULL); <a name="l00217"></a>00217 <span class="keywordflow">if</span> (<a class="code" href="dtnmoteproxy_8c.html#ae6a9b084de32dbd181692c52c5e97de">debug</a>) printf(<span class="stringliteral">" done\n"</span>); <a name="l00218"></a>00218 <a name="l00219"></a>00219 <span class="keywordflow">if</span> (<a class="code" href="dtnperf-server_8c.html#cd3810a883cd2d3430c4ec9922df3c9c">aggregate</a> == 0) { <a name="l00220"></a>00220 printf(<span class="stringliteral">"%s : %zu bytes from %s\n"</span>, <a name="l00221"></a>00221 ctime(&current), <a name="l00222"></a>00222 len, <a name="l00223"></a>00223 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="l00224"></a>00224 } <span class="keywordflow">else</span> <span class="keywordflow">if</span> (count % <a class="code" href="dtnperf-server_8c.html#cd3810a883cd2d3430c4ec9922df3c9c">aggregate</a> == 0) { <a name="l00225"></a>00225 printf(<span class="stringliteral">"%s : %d bundles, total length %d bytes\n"</span>, <a name="l00226"></a>00226 ctime(&current), count, total); <a name="l00227"></a>00227 } <a name="l00228"></a>00228 <a name="l00229"></a>00229 <span class="comment">/* ---------------------------------------------------</span> <a name="l00230"></a>00230 <span class="comment"> * parse admin string to select file target location</span> <a name="l00231"></a>00231 <span class="comment"> * --------------------------------------------------- */</span> <a name="l00232"></a>00232 <a name="l00233"></a>00233 <span class="comment">// copy SOURCE eid</span> <a name="l00234"></a>00234 <span class="keywordflow">if</span> (<a class="code" href="dtnmoteproxy_8c.html#ae6a9b084de32dbd181692c52c5e97de">debug</a>) printf(<span class="stringliteral">"[debug]\tcopying source eid..."</span>); <a name="l00235"></a>00235 source_eid_len = <span class="keyword">sizeof</span>(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="l00236"></a>00236 source_eid = malloc(<span class="keyword">sizeof</span>(<span class="keywordtype">char</span>) * source_eid_len+1); <a name="l00237"></a>00237 memcpy(source_eid, 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>, source_eid_len); <a name="l00238"></a>00238 source_eid[source_eid_len] = <span class="charliteral">'\0'</span>; <a name="l00239"></a>00239 <span class="keywordflow">if</span> (<a class="code" href="dtnmoteproxy_8c.html#ae6a9b084de32dbd181692c52c5e97de">debug</a>) { <a name="l00240"></a>00240 printf(<span class="stringliteral">" done:\n"</span>); <a name="l00241"></a>00241 printf(<span class="stringliteral">"\tsource_eid = %s\n"</span>, source_eid); <a name="l00242"></a>00242 printf(<span class="stringliteral">"\n"</span>); <a name="l00243"></a>00243 } <a name="l00244"></a>00244 <a name="l00245"></a>00245 <span class="comment">// copy DEST eid</span> <a name="l00246"></a>00246 <span class="keywordflow">if</span> (<a class="code" href="dtnmoteproxy_8c.html#ae6a9b084de32dbd181692c52c5e97de">debug</a>) printf(<span class="stringliteral">"[debug]\tcopying dest eid..."</span>); <a name="l00247"></a>00247 dest_eid_len = <span class="keyword">sizeof</span>(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="l00248"></a>00248 dest_eid = malloc(<span class="keyword">sizeof</span>(<span class="keywordtype">char</span>) * dest_eid_len+1); <a name="l00249"></a>00249 memcpy(dest_eid, 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>, dest_eid_len); <a name="l00250"></a>00250 dest_eid[dest_eid_len] = <span class="charliteral">'\0'</span>; <a name="l00251"></a>00251 <span class="keywordflow">if</span> (<a class="code" href="dtnmoteproxy_8c.html#ae6a9b084de32dbd181692c52c5e97de">debug</a>) { <a name="l00252"></a>00252 printf(<span class="stringliteral">" done:\n"</span>); <a name="l00253"></a>00253 printf(<span class="stringliteral">"\tdest_eid = %s\n"</span>, dest_eid); <a name="l00254"></a>00254 printf(<span class="stringliteral">"\n"</span>); <a name="l00255"></a>00255 } <a name="l00256"></a>00256 <a name="l00257"></a>00257 <span class="comment">// recursively create full directory path</span> <a name="l00258"></a>00258 filepath = malloc(<span class="keyword">sizeof</span>(<span class="keywordtype">char</span>) * dest_eid_len + 10); <a name="l00259"></a>00259 sprintf(filepath, <span class="stringliteral">"mkdir -p %s"</span>, <a class="code" href="dtnperf-server_8c.html#1bc5fad21b936109b622e4992ad1e0c2">bundle_dir</a>); <a name="l00260"></a>00260 <span class="keywordflow">if</span> (<a class="code" href="dtnmoteproxy_8c.html#ae6a9b084de32dbd181692c52c5e97de">debug</a>) printf(<span class="stringliteral">"[debug] filepath = %s\n"</span>, filepath); <a name="l00261"></a>00261 system(filepath); <a name="l00262"></a>00262 <a name="l00263"></a>00263 <span class="comment">// create file name</span> <a name="l00264"></a>00264 sprintf(filepath, <span class="stringliteral">"%s/%s"</span>, <a class="code" href="dtnperf-server_8c.html#1bc5fad21b936109b622e4992ad1e0c2">bundle_dir</a>, filename); <a name="l00265"></a>00265 <span class="keywordflow">if</span> (<a class="code" href="dtnmoteproxy_8c.html#ae6a9b084de32dbd181692c52c5e97de">debug</a>) printf(<span class="stringliteral">"[debug] filepath = %s\n"</span>, filepath); <a name="l00266"></a>00266 <a name="l00267"></a>00267 <span class="comment">// bundle name is the name of the bundle payload file</span> <a name="l00268"></a>00268 buffer = payload.<a class="code" href="structdtn__bundle__payload__t.html#04e8c46c5b40f187e1fefed80853cc5c">buf</a>.<a class="code" href="structdtn__bundle__payload__t.html#45cd21fd96fced99995450f0fca848d5">buf_val</a>; <a name="l00269"></a>00269 bufsize = payload.<a class="code" href="structdtn__bundle__payload__t.html#04e8c46c5b40f187e1fefed80853cc5c">buf</a>.<a class="code" href="structdtn__bundle__payload__t.html#c20a1cf6010dbd5855140373da5ce8c3">buf_len</a>; <a name="l00270"></a>00270 <a name="l00271"></a>00271 <span class="keywordflow">if</span> (<a class="code" href="dtnmoteproxy_8c.html#ae6a9b084de32dbd181692c52c5e97de">debug</a>) { <a name="l00272"></a>00272 printf (<span class="stringliteral">"======================================\n"</span>); <a name="l00273"></a>00273 printf (<span class="stringliteral">" Bundle received at %s\n"</span>, ctime(&current)); <a name="l00274"></a>00274 printf (<span class="stringliteral">" source: %s\n"</span>, 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="l00275"></a>00275 <span class="keywordflow">if</span> (<a class="code" href="dtnperf-client_8c.html#f72f0fe7b03d82b7ee28f9f9bd395d12">use_file</a>) { <a name="l00276"></a>00276 printf (<span class="stringliteral">" saved into : %s\n"</span>, filepath); <a name="l00277"></a>00277 } <a name="l00278"></a>00278 <a name="l00279"></a>00279 printf (<span class="stringliteral">"--------------------------------------\n"</span>); <a name="l00280"></a>00280 } <a name="l00281"></a>00281 <a name="l00282"></a>00282 <span class="keywordflow">if</span> (pl_type == <a class="code" href="dtn__types_8h.html#3dcfddc1b850a71a18d8a0868f67e7621ff9272291ffe7d9f8083e7c5a548909">DTN_PAYLOAD_FILE</a>) { <span class="comment">// if bundle was saved into file</span> <a name="l00283"></a>00283 <a name="l00284"></a>00284 <span class="keywordflow">if</span> (<a class="code" href="dtnmoteproxy_8c.html#ae6a9b084de32dbd181692c52c5e97de">debug</a>) printf(<span class="stringliteral">"[debug] renaming file %s -> %s..."</span>, <a name="l00285"></a>00285 payload.<a class="code" href="structdtn__bundle__payload__t.html#f3a33fd2ae2b3b8eae2e675f1a038cec">filename</a>.<a class="code" href="structdtn__bundle__payload__t.html#0d824d13c3225cb59fa2e34623608b2a">filename_val</a>, filepath); <a name="l00286"></a>00286 <span class="keywordflow">if</span> (rename(payload.<a class="code" href="structdtn__bundle__payload__t.html#f3a33fd2ae2b3b8eae2e675f1a038cec">filename</a>.<a class="code" href="structdtn__bundle__payload__t.html#0d824d13c3225cb59fa2e34623608b2a">filename_val</a>, filepath) != 0) { <a name="l00287"></a>00287 printf(<span class="stringliteral">"[ERROR] Couldn't rename %s -> %s: %s\n"</span>, <a name="l00288"></a>00288 payload.<a class="code" href="structdtn__bundle__payload__t.html#f3a33fd2ae2b3b8eae2e675f1a038cec">filename</a>.<a class="code" href="structdtn__bundle__payload__t.html#0d824d13c3225cb59fa2e34623608b2a">filename_val</a>, filepath, strerror(<a class="code" href="IPDiscovery_8cc.html#d65a8842cc674e3ddf69355898c0ecbf">errno</a>)); <a name="l00289"></a>00289 } <a name="l00290"></a>00290 <a name="l00291"></a>00291 } <span class="keywordflow">else</span> { <span class="comment">// if bundle was saved into memory</span> <a name="l00292"></a>00292 <a name="l00293"></a>00293 <span class="keywordflow">if</span> (<a class="code" href="dtnmoteproxy_8c.html#ae6a9b084de32dbd181692c52c5e97de">debug</a>) { <a name="l00294"></a>00294 <span class="keywordflow">for</span> (k=0; k < (int)payload.<a class="code" href="structdtn__bundle__payload__t.html#04e8c46c5b40f187e1fefed80853cc5c">buf</a>.<a class="code" href="structdtn__bundle__payload__t.html#c20a1cf6010dbd5855140373da5ce8c3">buf_len</a>; k++) <a name="l00295"></a>00295 { <a name="l00296"></a>00296 <span class="keywordflow">if</span> (buffer[k] >= <span class="charliteral">' '</span> && buffer[k] <= <span class="charliteral">'~'</span>) <a name="l00297"></a>00297 s_buffer[k%<a class="code" href="dtncpd_8c.html#eca034f67218340ecb2261a22c2f3dcd">BUFSIZE</a>] = buffer[k]; <a name="l00298"></a>00298 <span class="keywordflow">else</span> <a name="l00299"></a>00299 s_buffer[k%<a class="code" href="dtncpd_8c.html#eca034f67218340ecb2261a22c2f3dcd">BUFSIZE</a>] = <span class="charliteral">'.'</span>; <a name="l00300"></a>00300 <a name="l00301"></a>00301 <span class="keywordflow">if</span> (k%<a class="code" href="dtncpd_8c.html#eca034f67218340ecb2261a22c2f3dcd">BUFSIZE</a> == 0) <span class="comment">// new line every 16 bytes</span> <a name="l00302"></a>00302 { <a name="l00303"></a>00303 printf(<span class="stringliteral">"%07x "</span>, k); <a name="l00304"></a>00304 } <a name="l00305"></a>00305 <span class="keywordflow">else</span> <span class="keywordflow">if</span> (k%2 == 0) <a name="l00306"></a>00306 { <a name="l00307"></a>00307 printf(<span class="stringliteral">" "</span>); <span class="comment">// space every 2 bytes</span> <a name="l00308"></a>00308 } <a name="l00309"></a>00309 <a name="l00310"></a>00310 printf(<span class="stringliteral">"%02x"</span>, buffer[k] & 0xff); <a name="l00311"></a>00311 <a name="l00312"></a>00312 <span class="comment">// print character summary (a la emacs hexl-mode)</span> <a name="l00313"></a>00313 <span class="keywordflow">if</span> (k%<a class="code" href="dtncpd_8c.html#eca034f67218340ecb2261a22c2f3dcd">BUFSIZE</a> == <a class="code" href="dtncpd_8c.html#eca034f67218340ecb2261a22c2f3dcd">BUFSIZE</a>-1) <a name="l00314"></a>00314 { <a name="l00315"></a>00315 printf(<span class="stringliteral">" | %.*s\n"</span>, <a class="code" href="dtncpd_8c.html#eca034f67218340ecb2261a22c2f3dcd">BUFSIZE</a>, s_buffer); <a name="l00316"></a>00316 } <a name="l00317"></a>00317 } <span class="comment">// for</span> <a name="l00318"></a>00318 <a name="l00319"></a>00319 <span class="comment">// print spaces to fill out the rest of the line</span> <a name="l00320"></a>00320 <span class="keywordflow">if</span> (k%<a class="code" href="dtncpd_8c.html#eca034f67218340ecb2261a22c2f3dcd">BUFSIZE</a> != <a class="code" href="dtncpd_8c.html#eca034f67218340ecb2261a22c2f3dcd">BUFSIZE</a>-1) { <a name="l00321"></a>00321 <span class="keywordflow">while</span> (k%<a class="code" href="dtncpd_8c.html#eca034f67218340ecb2261a22c2f3dcd">BUFSIZE</a> != <a class="code" href="dtncpd_8c.html#eca034f67218340ecb2261a22c2f3dcd">BUFSIZE</a>-1) { <a name="l00322"></a>00322 <span class="keywordflow">if</span> (k%2 == 0) { <a name="l00323"></a>00323 printf(<span class="stringliteral">" "</span>); <a name="l00324"></a>00324 } <a name="l00325"></a>00325 printf(<span class="stringliteral">" "</span>); <a name="l00326"></a>00326 k++; <a name="l00327"></a>00327 } <a name="l00328"></a>00328 printf(<span class="stringliteral">" | %.*s\n"</span>, <a name="l00329"></a>00329 (<span class="keywordtype">int</span>)payload.<a class="code" href="structdtn__bundle__payload__t.html#04e8c46c5b40f187e1fefed80853cc5c">buf</a>.<a class="code" href="structdtn__bundle__payload__t.html#c20a1cf6010dbd5855140373da5ce8c3">buf_len</a>%<a class="code" href="dtncpd_8c.html#eca034f67218340ecb2261a22c2f3dcd">BUFSIZE</a>, s_buffer); <a name="l00330"></a>00330 } <span class="comment">// if</span> <a name="l00331"></a>00331 <a name="l00332"></a>00332 printf (<span class="stringliteral">"======================================\n"</span>); <a name="l00333"></a>00333 <a name="l00334"></a>00334 } <span class="comment">// if (debug) </span> <a name="l00335"></a>00335 <a name="l00336"></a>00336 free(filepath); <a name="l00337"></a>00337 free(source_eid); <a name="l00338"></a>00338 free(dest_eid); <a name="l00339"></a>00339 <a name="l00340"></a>00340 } <a name="l00341"></a>00341 <a name="l00342"></a>00342 fflush(stdout); <a name="l00343"></a>00343 <a name="l00344"></a>00344 } <span class="comment">// while(1)</span> <a name="l00345"></a>00345 <a name="l00346"></a>00346 <span class="comment">// if this was ever changed to gracefully shutdown, it would be good to call:</span> <a name="l00347"></a>00347 <a class="code" href="dtn__api_8c.html#887c16260463d6057bf5b03a1ff0e224" title="Close an open dtn handle.">dtn_close</a>(handle); <a name="l00348"></a>00348 <a name="l00349"></a>00349 <span class="keywordflow">return</span> 0; <a name="l00350"></a>00350 <a name="l00351"></a>00351 } <span class="comment">//main</span> <a name="l00352"></a>00352 <a name="l00353"></a>00353 <span class="comment">/* -------------------------------</span> <a name="l00354"></a>00354 <span class="comment"> * Utility Functions</span> <a name="l00355"></a>00355 <span class="comment"> * ------------------------------- */</span> <a name="l00356"></a>00356 <a name="l00357"></a>00357 <span class="comment">/* -------------</span> <a name="l00358"></a>00358 <span class="comment"> * print_usage</span> <a name="l00359"></a>00359 <span class="comment"> * ------------- */</span> <a name="l00360"></a>00360 <span class="keywordtype">void</span> <a class="code" href="dtncat_8c.html#e5ad5cbeccaedc03a48d3c7eaa803e79">print_usage</a>(<span class="keywordtype">char</span>* <a class="code" href="dtncat_8c.html#b9e1449fd00c98428516f0b41eddcb10">progname</a>) <a name="l00361"></a>00361 { <a name="l00362"></a>00362 fprintf(stderr, <span class="stringliteral">"\n"</span>); <a name="l00363"></a>00363 fprintf(stderr, <span class="stringliteral">"SYNTAX: %s [options]\n"</span>, progname); <a name="l00364"></a>00364 fprintf(stderr, <span class="stringliteral">"\n"</span>); <a name="l00365"></a>00365 fprintf(stderr, <span class="stringliteral">"options:\n"</span>); <a name="l00366"></a>00366 fprintf(stderr, <span class="stringliteral">" -d <dir>: destination directory (if using -f) \n"</span>); <a name="l00367"></a>00367 fprintf(stderr, <span class="stringliteral">" [default destination dir: %s]\n"</span>, <a class="code" href="dtncpd_8c.html#e15a995a7a30a0d14d0db7362b90ce27">BUNDLE_DIR_DEFAULT</a>); <a name="l00368"></a>00368 fprintf(stderr, <span class="stringliteral">" -D: many debug messages are shown\n"</span>); <a name="l00369"></a>00369 fprintf(stderr, <span class="stringliteral">" -m: save received bundles into memory\n"</span>); <a name="l00370"></a>00370 fprintf(stderr, <span class="stringliteral">" -h: shows this help\n"</span>); <a name="l00371"></a>00371 fprintf(stderr, <span class="stringliteral">" -v: verbose\n"</span>); <a name="l00372"></a>00372 fprintf(stderr, <span class="stringliteral">" -a <n>: print message every n arrivals\n"</span>); <a name="l00373"></a>00373 fprintf(stderr, <span class="stringliteral">"\n"</span>); <a name="l00374"></a>00374 exit(1); <a name="l00375"></a>00375 } <a name="l00376"></a>00376 <a name="l00377"></a>00377 <span class="comment">/* ---------------</span> <a name="l00378"></a>00378 <span class="comment"> * parse_options</span> <a name="l00379"></a>00379 <span class="comment"> * --------------- */</span> <a name="l00380"></a>00380 <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="l00381"></a>00381 <span class="keywordtype">int</span> c, done = 0; <a name="l00382"></a>00382 <a name="l00383"></a>00383 <span class="keywordflow">while</span> (!done) { <a name="l00384"></a>00384 c = getopt(argc, argv, <span class="stringliteral">"hvDfmd:e:a:"</span>); <a name="l00385"></a>00385 <a name="l00386"></a>00386 <span class="keywordflow">switch</span>(c) { <a name="l00387"></a>00387 <span class="keywordflow">case</span> <span class="charliteral">'h'</span>: <span class="comment">// show help</span> <a name="l00388"></a>00388 <a class="code" href="dtncat_8c.html#e5ad5cbeccaedc03a48d3c7eaa803e79">print_usage</a>(argv[0]); <a name="l00389"></a>00389 exit(1); <a name="l00390"></a>00390 <span class="keywordflow">return</span>; <a name="l00391"></a>00391 <span class="keywordflow">case</span> <span class="charliteral">'v'</span>: <span class="comment">// verbose mode</span> <a name="l00392"></a>00392 <a class="code" href="dtncat_8c.html#0b2caeb4b6f130be43e5a2f0267dd453">verbose</a> = 1; <a name="l00393"></a>00393 <span class="keywordflow">break</span>; <a name="l00394"></a>00394 <span class="keywordflow">case</span> <span class="charliteral">'D'</span>: <span class="comment">// debug messages</span> <a name="l00395"></a>00395 <a class="code" href="dtnmoteproxy_8c.html#ae6a9b084de32dbd181692c52c5e97de">debug</a> = 1; <a name="l00396"></a>00396 <span class="keywordflow">break</span>; <a name="l00397"></a>00397 <span class="keywordflow">case</span> <span class="charliteral">'m'</span>: <span class="comment">// save received bundles into memory</span> <a name="l00398"></a>00398 <a class="code" href="dtnperf-client_8c.html#f72f0fe7b03d82b7ee28f9f9bd395d12">use_file</a> = 0; <a name="l00399"></a>00399 <span class="keywordflow">break</span>; <a name="l00400"></a>00400 <span class="keywordflow">case</span> <span class="charliteral">'d'</span>: <span class="comment">// destination directory</span> <a name="l00401"></a>00401 <a class="code" href="dtnperf-server_8c.html#1bc5fad21b936109b622e4992ad1e0c2">bundle_dir</a> = optarg; <a name="l00402"></a>00402 <span class="keywordflow">break</span>; <a name="l00403"></a>00403 <a name="l00404"></a>00404 <span class="keywordflow">case</span> <span class="charliteral">'e'</span>: <span class="comment">// destination endpoint</span> <a name="l00405"></a>00405 <a class="code" href="dtnperf-server_8c.html#6d2d1c31529bee906473fcabaffff34f">endpoint</a> = optarg; <a name="l00406"></a>00406 <span class="keywordflow">break</span>; <a name="l00407"></a>00407 <a name="l00408"></a>00408 <span class="keywordflow">case</span> <span class="charliteral">'a'</span>: <span class="comment">// aggregate</span> <a name="l00409"></a>00409 <a class="code" href="dtnperf-server_8c.html#cd3810a883cd2d3430c4ec9922df3c9c">aggregate</a> = atoi(optarg); <a name="l00410"></a>00410 <span class="keywordflow">break</span>; <a name="l00411"></a>00411 <a name="l00412"></a>00412 <span class="keywordflow">case</span> -1: <a name="l00413"></a>00413 done = 1; <a name="l00414"></a>00414 <span class="keywordflow">break</span>; <a name="l00415"></a>00415 <span class="keywordflow">default</span>: <a name="l00416"></a>00416 <a class="code" href="dtncat_8c.html#e5ad5cbeccaedc03a48d3c7eaa803e79">print_usage</a>(argv[0]); <a name="l00417"></a>00417 exit(1); <a name="l00418"></a>00418 } <a name="l00419"></a>00419 } <a name="l00420"></a>00420 <a name="l00421"></a>00421 <span class="preprocessor">#define CHECK_SET(_arg, _what) \</span> <a name="l00422"></a>00422 <span class="preprocessor"> if (_arg == 0) { \</span> <a name="l00423"></a>00423 <span class="preprocessor"> fprintf(stderr, "\nSYNTAX ERROR: %s must be specified\n", _what); \</span> <a name="l00424"></a>00424 <span class="preprocessor"> print_usage(argv[0]); \</span> <a name="l00425"></a>00425 <span class="preprocessor"> exit(1); \</span> <a name="l00426"></a>00426 <span class="preprocessor"> }</span> <a name="l00427"></a>00427 <span class="preprocessor"></span> <a name="l00428"></a>00428 } <a name="l00429"></a>00429 <a name="l00430"></a>00430 <span class="comment">/* ----------------------------</span> <a name="l00431"></a>00431 <span class="comment"> * parse_tuple</span> <a name="l00432"></a>00432 <span class="comment"> * ---------------------------- */</span> <a name="l00433"></a>00433 <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, <span class="keywordtype">char</span> * str) <a name="l00434"></a>00434 { <a name="l00435"></a>00435 <span class="comment">// try the string as an actual dtn tuple</span> <a name="l00436"></a>00436 <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="l00437"></a>00437 { <a name="l00438"></a>00438 <span class="keywordflow">return</span> eid; <a name="l00439"></a>00439 } <a name="l00440"></a>00440 <span class="comment">// build a local tuple based on the configuration of our dtn</span> <a name="l00441"></a>00441 <span class="comment">// router plus the str as demux string</span> <a name="l00442"></a>00442 <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="l00443"></a>00443 { <a name="l00444"></a>00444 <span class="keywordflow">if</span> (<a class="code" href="dtncat_8c.html#0b2caeb4b6f130be43e5a2f0267dd453">verbose</a>) fprintf(stdout, <span class="stringliteral">"%s (local)\n"</span>, str); <a name="l00445"></a>00445 <span class="keywordflow">return</span> eid; <a name="l00446"></a>00446 } <a name="l00447"></a>00447 <span class="keywordflow">else</span> <a name="l00448"></a>00448 { <a name="l00449"></a>00449 fprintf(stderr, <span class="stringliteral">"invalid eid string '%s'\n"</span>, str); <a name="l00450"></a>00450 exit(1); <a name="l00451"></a>00451 } <a name="l00452"></a>00452 } <span class="comment">// end parse_tuple</span> </pre></div></div> <hr size="1"><address style="text-align: right;"><small>Generated on Mon Jul 21 14:09:45 2008 for DTN Reference Implementation by <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>