<!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: dtncat.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>dtncat.c</h1><a href="dtncat_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 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 <a name="l00018"></a>00018 <span class="comment">/*</span> <a name="l00019"></a>00019 <span class="comment"> * dtncat: move stdin to bundles and vice-versa</span> <a name="l00020"></a>00020 <span class="comment"> * resembles the nc (netcat) unix program</span> <a name="l00021"></a>00021 <span class="comment"> * - kfall Apr 2006</span> <a name="l00022"></a>00022 <span class="comment"> *</span> <a name="l00023"></a>00023 <span class="comment"> * Usage: dtncat [-options] -s EID -d EID</span> <a name="l00024"></a>00024 <span class="comment"> * dtncat -l -s EID -d EID</span> <a name="l00025"></a>00025 <span class="comment"> */</span> <a name="l00026"></a>00026 <a name="l00027"></a>00027 <span class="preprocessor">#ifdef HAVE_CONFIG_H</span> <a name="l00028"></a>00028 <span class="preprocessor"></span><span class="preprocessor"># include <<a class="code" href="dtn-config_8h.html">dtn-config.h</a>></span> <a name="l00029"></a>00029 <span class="preprocessor">#endif</span> <a name="l00030"></a>00030 <span class="preprocessor"></span> <a name="l00031"></a>00031 <span class="preprocessor">#include <stdio.h></span> <a name="l00032"></a>00032 <span class="preprocessor">#include <unistd.h></span> <a name="l00033"></a>00033 <span class="preprocessor">#include <errno.h></span> <a name="l00034"></a>00034 <span class="preprocessor">#include <strings.h></span> <a name="l00035"></a>00035 <span class="preprocessor">#include <string.h></span> <a name="l00036"></a>00036 <span class="preprocessor">#include <stdlib.h></span> <a name="l00037"></a>00037 <span class="preprocessor">#include <sys/time.h></span> <a name="l00038"></a>00038 <span class="preprocessor">#include <time.h></span> <a name="l00039"></a>00039 <a name="l00040"></a>00040 <span class="preprocessor">#include "<a class="code" href="dtn__api_8h.html">dtn_api.h</a>"</span> <a name="l00041"></a>00041 <a name="l00042"></a><a class="code" href="dtncat_8c.html#b9e1449fd00c98428516f0b41eddcb10">00042</a> <span class="keywordtype">char</span> *<a class="code" href="dtncat_8c.html#b9e1449fd00c98428516f0b41eddcb10">progname</a>; <a name="l00043"></a>00043 <a name="l00044"></a>00044 <span class="comment">// global options</span> <a name="l00045"></a><a class="code" href="dtncat_8c.html#f6737c1dab828c01ca964e8b3c8183b5">00045</a> <span class="keywordtype">int</span> <a class="code" href="dtncat_8c.html#f6737c1dab828c01ca964e8b3c8183b5">copies</a> = 1; <span class="comment">// the number of copies to send</span> <a name="l00046"></a><a class="code" href="dtncat_8c.html#0b2caeb4b6f130be43e5a2f0267dd453">00046</a> <span class="keywordtype">int</span> <a class="code" href="dtncat_8c.html#0b2caeb4b6f130be43e5a2f0267dd453">verbose</a> = 0; <a name="l00047"></a>00047 <a name="l00048"></a>00048 <span class="comment">// bundle options</span> <a name="l00049"></a><a class="code" href="dtncat_8c.html#d6057e40387509de502bdc91007d3238">00049</a> <span class="keywordtype">int</span> <a class="code" href="dtncat_8c.html#d6057e40387509de502bdc91007d3238">expiration</a> = 3600; <span class="comment">// expiration timer (default one hour)</span> <a name="l00050"></a><a class="code" href="dtncat_8c.html#1bdbebbcf901e059d8765070846f9ee8">00050</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="l00051"></a><a class="code" href="dtncat_8c.html#6dd7ec74d1d4d8312e0f4cad76a3ebae">00051</a> <span class="keywordtype">int</span> <a class="code" href="dtncat_8c.html#6dd7ec74d1d4d8312e0f4cad76a3ebae">forwarding_receipts</a> = 0; <span class="comment">// request per hop departure</span> <a name="l00052"></a><a class="code" href="dtncat_8c.html#160881851a33309c0106503ac4d14d96">00052</a> <span class="keywordtype">int</span> <a class="code" href="dtncat_8c.html#160881851a33309c0106503ac4d14d96">custody</a> = 0; <span class="comment">// request custody transfer</span> <a name="l00053"></a><a class="code" href="dtncat_8c.html#e75d07ae6162cb4c080ca4b0189f5302">00053</a> <span class="keywordtype">int</span> <a class="code" href="dtncat_8c.html#e75d07ae6162cb4c080ca4b0189f5302">custody_receipts</a> = 0; <span class="comment">// request per custodian receipts</span> <a name="l00054"></a><a class="code" href="dtncat_8c.html#82c638daee7e7ec8f669285e64ebb511">00054</a> <span class="keywordtype">int</span> <a class="code" href="dtncat_8c.html#82c638daee7e7ec8f669285e64ebb511">receive_receipts</a> = 0; <span class="comment">// request per hop arrival receipt</span> <a name="l00055"></a><a class="code" href="dtncat_8c.html#fe53bb8563092a6a7cc95bbdfd4e2721">00055</a> <span class="keywordtype">int</span> <a class="code" href="dtncat_8c.html#fe53bb8563092a6a7cc95bbdfd4e2721">wait_for_report</a> = 0; <span class="comment">// wait for bundle status reports</span> <a name="l00056"></a><a class="code" href="dtncat_8c.html#057bbda8ea4dd2a0c5fc62ea88f55e6b">00056</a> <span class="keywordtype">int</span> <a class="code" href="dtncat_8c.html#057bbda8ea4dd2a0c5fc62ea88f55e6b">bundle_count</a> = -1; <span class="comment">// # bundles to receive (-l option)</span> <a name="l00057"></a><a class="code" href="dtncat_8c.html#7508c434c1f2152c7fd03381726d0a2a">00057</a> <span class="keywordtype">int</span> <a class="code" href="dtncat_8c.html#7508c434c1f2152c7fd03381726d0a2a">session_flags</a> = 0; <span class="comment">// use pub/sub session flags</span> <a name="l00058"></a><a class="code" href="dtncat_8c.html#9ca580976e59c0af2763e9e2e78bea66">00058</a> <span class="keywordtype">char</span>* <a class="code" href="dtncat_8c.html#9ca580976e59c0af2763e9e2e78bea66">sequence_id</a> = 0; <span class="comment">// use the given sequence id</span> <a name="l00059"></a><a class="code" href="dtncat_8c.html#53950f44ae10fbde2d8ae21493f50ffd">00059</a> <span class="keywordtype">char</span>* <a class="code" href="dtncat_8c.html#53950f44ae10fbde2d8ae21493f50ffd">obsoletes_id</a> = 0; <span class="comment">// use the given obsoletes id</span> <a name="l00060"></a>00060 <a name="l00061"></a><a class="code" href="dtncat_8c.html#f0dcc53259374250d9ed605c739de604">00061</a> <span class="preprocessor">#define DEFAULT_BUNDLE_COUNT 1</span> <a name="l00062"></a><a class="code" href="dtncat_8c.html#67f0eb2a4d9c5ec929b277f7066b4fc0">00062</a> <span class="preprocessor"></span><span class="preprocessor">#define FAILURE_SCRIPT ""</span> <a name="l00063"></a>00063 <span class="preprocessor"></span> <a name="l00064"></a>00064 <span class="preprocessor">#ifdef MIN</span> <a name="l00065"></a>00065 <span class="preprocessor"></span><span class="preprocessor">#undef MIN</span> <a name="l00066"></a>00066 <span class="preprocessor"></span><span class="preprocessor">#endif</span> <a name="l00067"></a><a class="code" href="dtncat_8c.html#3acffbd305ee72dcd4593c0d8af64a4f">00067</a> <span class="preprocessor"></span><span class="preprocessor">#define MIN(a, b) ((a) < (b) ? (a) : (b))</span> <a name="l00068"></a>00068 <span class="preprocessor"></span> <a name="l00069"></a>00069 <span class="comment">// specified options for bundle eids</span> <a name="l00070"></a><a class="code" href="dtncat_8c.html#cc3f40bcc31639227d6f74b3e0e6915c">00070</a> <span class="keywordtype">char</span> * <a class="code" href="dtncat_8c.html#cc3f40bcc31639227d6f74b3e0e6915c">arg_replyto</a> = NULL; <a name="l00071"></a><a class="code" href="dtncat_8c.html#b65c55eb53174efdd1d8a13c15a14fe7">00071</a> <span class="keywordtype">char</span> * <a class="code" href="dtncat_8c.html#b65c55eb53174efdd1d8a13c15a14fe7">arg_source</a> = NULL; <a name="l00072"></a><a class="code" href="dtncat_8c.html#8f7af606d1623c716486d0dab4c70391">00072</a> <span class="keywordtype">char</span> * <a class="code" href="dtncat_8c.html#8f7af606d1623c716486d0dab4c70391">arg_dest</a> = NULL; <a name="l00073"></a><a class="code" href="dtncat_8c.html#3e61efb260f461216d7465bdbaa3e778">00073</a> <span class="keywordtype">char</span> * <a class="code" href="dtncat_8c.html#3e61efb260f461216d7465bdbaa3e778">arg_receive</a> = NULL; <a name="l00074"></a>00074 <a name="l00075"></a><a class="code" href="dtncat_8c.html#8eb0c3e35c1feb7baf9802f03bf42e41">00075</a> <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="l00076"></a>00076 <a name="l00077"></a>00077 <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="l00078"></a>00078 <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="l00079"></a>00079 <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="l00080"></a>00080 <span class="keywordtype">char</span> * str); <a name="l00081"></a>00081 <span class="keywordtype">void</span> <a class="code" href="dtncat_8c.html#e5ad5cbeccaedc03a48d3c7eaa803e79">print_usage</a>(); <a name="l00082"></a>00082 <span class="keywordtype">void</span> <a class="code" href="dtncat_8c.html#a9d57d4d6b613ab254545fd140ebe5c8">print_eid</a>(FILE*, <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="l00083"></a>00083 <span class="keywordtype">int</span> <a class="code" href="dtncat_8c.html#e66a979abf383ee357553609993b3d1f">fill_payload</a>(<a class="code" href="structdtn__bundle__payload__t.html">dtn_bundle_payload_t</a>* payload); <a name="l00084"></a>00084 <a name="l00085"></a><a class="code" href="dtncat_8c.html#71f51a2e8cbe9a53031fa72596edc09f">00085</a> FILE* <a class="code" href="dtncat_8c.html#71f51a2e8cbe9a53031fa72596edc09f">info</a>; <span class="comment">/* when -v option is used, write to here */</span> <a name="l00086"></a><a class="code" href="dtncat_8c.html#2af892c305953806a6b6fb3f55963bbc">00086</a> <span class="preprocessor">#define REG_EXPIRE (60 * 60)</span> <a name="l00087"></a><a class="code" href="dtncat_8c.html#5287cc892023d51088dd91a9b78de7c5">00087</a> <span class="preprocessor"></span><span class="keywordtype">char</span> <a class="code" href="dtncat_8c.html#5287cc892023d51088dd91a9b78de7c5">payload_buf</a>[<a class="code" href="dtn__types_8h.html#35e670e5d1e8d12cc3c644b748fbef31">DTN_MAX_BUNDLE_MEM</a>]; <a name="l00088"></a>00088 <a name="l00089"></a><a class="code" href="dtncat_8c.html#35bb644b5e618ea5ad790f7b181e47d6">00089</a> <span class="keywordtype">int</span> <a class="code" href="dtncat_8c.html#35bb644b5e618ea5ad790f7b181e47d6">from_bundles_flag</a>; <a name="l00090"></a>00090 <a name="l00091"></a>00091 <span class="keywordtype">void</span> <a class="code" href="dtncat_8c.html#14a8e20bb3844060ac4e927e6ba72eb7">to_bundles</a>(); <span class="comment">// stdin -> bundles</span> <a name="l00092"></a>00092 <span class="keywordtype">void</span> <a class="code" href="dtncat_8c.html#9893f12c84249fce163f9b67f96aa3f7">from_bundles</a>(); <span class="comment">// bundles -> stdout</span> <a name="l00093"></a>00093 <span class="keywordtype">void</span> <a class="code" href="dtncat_8c.html#5f3182fedba4dab2c150f77dbd997df1">make_registration</a>(<a class="code" href="structdtn__reg__info__t.html" title="Registration state.">dtn_reg_info_t</a>*); <a name="l00094"></a>00094 <a name="l00095"></a><a class="code" href="dtncat_8c.html#01daea96255bb21a8979b3b45f5bbb70">00095</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="l00096"></a><a class="code" href="dtncat_8c.html#70f601fc23b0cc97480972bf1ecf7f6c">00096</a> <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="l00097"></a><a class="code" href="dtncat_8c.html#cad3457d57f7286e1e4e7caa1a619e25">00097</a> <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="l00098"></a><a class="code" href="dtncat_8c.html#ff6885d77acf2e2c60a4c8da20da5b2c">00098</a> <a class="code" href="structdtn__bundle__payload__t.html">dtn_bundle_payload_t</a> <a class="code" href="dtncat_8c.html#ff6885d77acf2e2c60a4c8da20da5b2c">primary_payload</a>; <a name="l00099"></a><a class="code" href="dtncat_8c.html#f6ba744d4931e7c678cf04716560bfca">00099</a> <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="l00100"></a><a class="code" href="dtncat_8c.html#0d43174f8d3844aa5df38af2712ccb00">00100</a> <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="l00101"></a><a class="code" href="dtncat_8c.html#7ab59805f7a1819164bc301293db600d">00101</a> <span class="keyword">struct </span>timeval start, <a class="code" href="dtncat_8c.html#7ab59805f7a1819164bc301293db600d">end</a>; <a name="l00102"></a>00102 <a name="l00103"></a>00103 <a name="l00104"></a>00104 <span class="keywordtype">int</span> <a name="l00105"></a><a class="code" href="dtncat_8c.html#3c04138a5bfe5d72780bb7e82a18e627">00105</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="l00106"></a>00106 { <a name="l00107"></a>00107 <a name="l00108"></a>00108 <a class="code" href="dtncat_8c.html#71f51a2e8cbe9a53031fa72596edc09f">info</a> = stderr; <a name="l00109"></a>00109 <a name="l00110"></a>00110 <span class="comment">// force stdout to always be line buffered, even if output is</span> <a name="l00111"></a>00111 <span class="comment">// redirected to a pipe or file -- why? kf</span> <a name="l00112"></a>00112 <span class="comment">// setvbuf(stdout, (char *)NULL, _IOLBF, 0);</span> <a name="l00113"></a>00113 <a name="l00114"></a>00114 <a class="code" href="dtncat_8c.html#293abb58b132c26701dada5c4e57ca35">parse_options</a>(argc, argv); <a name="l00115"></a>00115 <a name="l00116"></a>00116 <span class="comment">// open the ipc handle</span> <a name="l00117"></a>00117 <span class="keywordflow">if</span> (<a class="code" href="dtncat_8c.html#0b2caeb4b6f130be43e5a2f0267dd453">verbose</a>) <a name="l00118"></a>00118 fprintf(<a class="code" href="dtncat_8c.html#71f51a2e8cbe9a53031fa72596edc09f">info</a>, <span class="stringliteral">"Opening connection to local DTN daemon\n"</span>); <a name="l00119"></a>00119 <a name="l00120"></a>00120 <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>(&<a class="code" href="dtncat_8c.html#01daea96255bb21a8979b3b45f5bbb70">handle</a>); <a name="l00121"></a>00121 <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="l00122"></a>00122 fprintf(stderr, <span class="stringliteral">"%s: fatal error opening dtn handle: %s\n"</span>, <a name="l00123"></a>00123 <a class="code" href="dtncat_8c.html#b9e1449fd00c98428516f0b41eddcb10">progname</a>, <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="l00124"></a>00124 exit(EXIT_FAILURE); <a name="l00125"></a>00125 } <a name="l00126"></a>00126 <a name="l00127"></a>00127 <span class="keywordflow">if</span> (<a class="code" href="namespacedtnsim.html#372b0bd474085f20b38efbbade7ce72a" title="Override gettimeofday to return the simulator time.">gettimeofday</a>(&start, NULL) < 0) { <a name="l00128"></a>00128 fprintf(stderr, <span class="stringliteral">"%s: gettimeofday(start) returned error %s\n"</span>, <a name="l00129"></a>00129 <a class="code" href="dtncat_8c.html#b9e1449fd00c98428516f0b41eddcb10">progname</a>, strerror(<a class="code" href="IPDiscovery_8cc.html#d65a8842cc674e3ddf69355898c0ecbf">errno</a>)); <a name="l00130"></a>00130 exit(EXIT_FAILURE); <a name="l00131"></a>00131 } <a name="l00132"></a>00132 <a name="l00133"></a>00133 <span class="keywordflow">if</span> (<a class="code" href="dtncat_8c.html#35bb644b5e618ea5ad790f7b181e47d6">from_bundles_flag</a>) <a name="l00134"></a>00134 <a class="code" href="dtncat_8c.html#9893f12c84249fce163f9b67f96aa3f7">from_bundles</a>(); <a name="l00135"></a>00135 <span class="keywordflow">else</span> <a name="l00136"></a>00136 <a class="code" href="dtncat_8c.html#14a8e20bb3844060ac4e927e6ba72eb7">to_bundles</a>(); <a name="l00137"></a>00137 <a name="l00138"></a>00138 <a class="code" href="dtn__api_8c.html#887c16260463d6057bf5b03a1ff0e224" title="Close an open dtn handle.">dtn_close</a>(<a class="code" href="dtncat_8c.html#01daea96255bb21a8979b3b45f5bbb70">handle</a>); <a name="l00139"></a>00139 <span class="keywordflow">return</span> (EXIT_SUCCESS); <a name="l00140"></a>00140 } <a name="l00141"></a>00141 <a name="l00142"></a>00142 <a name="l00143"></a>00143 <span class="comment">/*</span> <a name="l00144"></a>00144 <span class="comment"> * [bundles] -> stdout</span> <a name="l00145"></a>00145 <span class="comment"> */</span> <a name="l00146"></a>00146 <a name="l00147"></a>00147 <span class="keywordtype">void</span> <a name="l00148"></a><a class="code" href="dtncat_8c.html#9893f12c84249fce163f9b67f96aa3f7">00148</a> <a class="code" href="dtncat_8c.html#9893f12c84249fce163f9b67f96aa3f7">from_bundles</a>() <a name="l00149"></a>00149 { <a name="l00150"></a>00150 <span class="keywordtype">int</span> total_bytes = 0, i, ret; <a name="l00151"></a>00151 <span class="keywordtype">char</span> *buffer; <a name="l00152"></a>00152 <span class="keywordtype">char</span> s_buffer[BUFSIZ]; <a name="l00153"></a>00153 <a name="l00154"></a>00154 <a class="code" href="structdtn__reg__info__t.html" title="Registration state.">dtn_reg_info_t</a> reg; <a name="l00155"></a>00155 <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="l00156"></a>00156 <a class="code" href="structdtn__bundle__spec__t.html" title="Bundle metadata.">dtn_bundle_spec_t</a> receive_spec; <a name="l00157"></a>00157 <a name="l00158"></a>00158 <a class="code" href="dtncat_8c.html#8b10ca66cacac0bc52c3ce6737d8c85a">parse_eid</a>(<a class="code" href="dtncat_8c.html#01daea96255bb21a8979b3b45f5bbb70">handle</a>, &local_eid, <a class="code" href="dtncat_8c.html#3e61efb260f461216d7465bdbaa3e778">arg_receive</a>); <a name="l00159"></a>00159 <a name="l00160"></a>00160 memset(&reg, 0, <span class="keyword">sizeof</span>(reg)); <a name="l00161"></a>00161 <a class="code" href="dtn__api_8c.html#b2935a9a7f4ade630f7d2ad1fec5c615" title="Copy the contents of one eid into another.">dtn_copy_eid</a>(&reg.<a class="code" href="structdtn__reg__info__t.html#07df1822e2808b2127710a8b54acd07f">endpoint</a>, &local_eid); <a name="l00162"></a>00162 <a name="l00163"></a>00163 <span class="comment">// when using the session flags, the registration expires</span> <a name="l00164"></a>00164 <span class="comment">// immediately, otherwise we give it a default expiration time</span> <a name="l00165"></a>00165 <span class="keywordflow">if</span> (<a class="code" href="dtncat_8c.html#7508c434c1f2152c7fd03381726d0a2a">session_flags</a>) { <a name="l00166"></a>00166 reg.<a class="code" href="structdtn__reg__info__t.html#7bf2e33b713b585bfe1792c40fa8cd6c">flags</a> = <a class="code" href="dtn__types_8h.html#a6d0071f396dd4ef85f6ad6332e37f0067a5f773775540e3dbe22a87105d571e">DTN_REG_DROP</a> | <a class="code" href="dtn__types_8h.html#a6d0071f396dd4ef85f6ad6332e37f003c2e2090965814efabe47f3f2a358e33">DTN_SESSION_SUBSCRIBE</a>; <a name="l00167"></a>00167 reg.<a class="code" href="structdtn__reg__info__t.html#dd4b3b0c9f27a0375369f35e33be686d">expiration</a> = 0; <a name="l00168"></a>00168 } <span class="keywordflow">else</span> { <a name="l00169"></a>00169 reg.<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="l00170"></a>00170 reg.<a class="code" href="structdtn__reg__info__t.html#dd4b3b0c9f27a0375369f35e33be686d">expiration</a> = <a class="code" href="dtncat_8c.html#2af892c305953806a6b6fb3f55963bbc">REG_EXPIRE</a>; <a name="l00171"></a>00171 } <a name="l00172"></a>00172 <a name="l00173"></a>00173 <a class="code" href="dtncat_8c.html#5f3182fedba4dab2c150f77dbd997df1">make_registration</a>(&reg); <a name="l00174"></a>00174 <a name="l00175"></a>00175 <span class="keywordflow">if</span> (<a class="code" href="dtncat_8c.html#0b2caeb4b6f130be43e5a2f0267dd453">verbose</a>) <a name="l00176"></a>00176 fprintf(<a class="code" href="dtncat_8c.html#71f51a2e8cbe9a53031fa72596edc09f">info</a>, <span class="stringliteral">"waiting to receive %d bundles using reg >%s<\n"</span>, <a name="l00177"></a>00177 <a class="code" href="dtncat_8c.html#057bbda8ea4dd2a0c5fc62ea88f55e6b">bundle_count</a>, reg.<a class="code" href="structdtn__reg__info__t.html#07df1822e2808b2127710a8b54acd07f">endpoint</a>.<a class="code" href="structdtn__endpoint__id__t.html#d2e7d5788ae778c77b4041f1f8b1dc80">uri</a>); <a name="l00178"></a>00178 <a name="l00179"></a>00179 <span class="comment">// loop waiting for bundles</span> <a name="l00180"></a>00180 <span class="keywordflow">for</span> (i = 0; i < <a class="code" href="dtncat_8c.html#057bbda8ea4dd2a0c5fc62ea88f55e6b">bundle_count</a>; ++i) { <a name="l00181"></a>00181 <span class="keywordtype">size_t</span> bytes = 0; <a name="l00182"></a>00182 u_int k; <a name="l00183"></a>00183 <a name="l00184"></a>00184 <span class="comment">// read from network</span> <a name="l00185"></a>00185 <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>(<a class="code" href="dtncat_8c.html#01daea96255bb21a8979b3b45f5bbb70">handle</a>, &receive_spec, <a name="l00186"></a>00186 <a class="code" href="dtn__types_8h.html#3dcfddc1b850a71a18d8a0868f67e7628f773bbfb80857bd5a11f09665fa9b03">DTN_PAYLOAD_MEM</a>, &primary_payload, -1)) < 0) { <a name="l00187"></a>00187 fprintf(stderr, <span class="stringliteral">"%s: error getting recv reply: %d (%s)\n"</span>, <a name="l00188"></a>00188 <a class="code" href="dtncat_8c.html#b9e1449fd00c98428516f0b41eddcb10">progname</a>, 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>(<a class="code" href="dtncat_8c.html#01daea96255bb21a8979b3b45f5bbb70">handle</a>))); <a name="l00189"></a>00189 exit(EXIT_FAILURE); <a name="l00190"></a>00190 } <a name="l00191"></a>00191 <a name="l00192"></a>00192 bytes = primary_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="l00193"></a>00193 buffer = (<span class="keywordtype">char</span> *) primary_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="l00194"></a>00194 total_bytes += bytes; <a name="l00195"></a>00195 <a name="l00196"></a>00196 <span class="comment">// write to stdout</span> <a name="l00197"></a>00197 if (fwrite(buffer, 1, bytes, stdout) != bytes) { <a name="l00198"></a>00198 fprintf(stderr, <span class="stringliteral">"%s: error writing to stdout\n"</span>, <a name="l00199"></a>00199 <a class="code" href="dtncat_8c.html#b9e1449fd00c98428516f0b41eddcb10">progname</a>); <a name="l00200"></a>00200 exit(EXIT_FAILURE); <a name="l00201"></a>00201 } <a name="l00202"></a>00202 <a name="l00203"></a>00203 <span class="keywordflow">if</span> (!<a class="code" href="dtncat_8c.html#0b2caeb4b6f130be43e5a2f0267dd453">verbose</a>) { <a name="l00204"></a>00204 <span class="keywordflow">continue</span>; <a name="l00205"></a>00205 } <a name="l00206"></a>00206 <a name="l00207"></a>00207 fprintf(<a class="code" href="dtncat_8c.html#71f51a2e8cbe9a53031fa72596edc09f">info</a>, <span class="stringliteral">"%d bytes from [%s]: transit time=%d ms\n"</span>, <a name="l00208"></a>00208 primary_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="l00209"></a>00209 receive_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>, 0); <a name="l00210"></a>00210 <a name="l00211"></a>00211 <span class="keywordflow">for</span> (k=0; k < primary_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="l00212"></a>00212 <span class="keywordflow">if</span> (buffer[k] >= <span class="charliteral">' '</span> && buffer[k] <= <span class="charliteral">'~'</span>) <a name="l00213"></a>00213 s_buffer[k%BUFSIZ] = buffer[k]; <a name="l00214"></a>00214 <span class="keywordflow">else</span> <a name="l00215"></a>00215 s_buffer[k%BUFSIZ] = <span class="charliteral">'.'</span>; <a name="l00216"></a>00216 <a name="l00217"></a>00217 <span class="keywordflow">if</span> (k%BUFSIZ == 0) <span class="comment">// new line every 16 bytes</span> <a name="l00218"></a>00218 { <a name="l00219"></a>00219 fprintf(<a class="code" href="dtncat_8c.html#71f51a2e8cbe9a53031fa72596edc09f">info</a>,<span class="stringliteral">"%07x "</span>, k); <a name="l00220"></a>00220 } <a name="l00221"></a>00221 <span class="keywordflow">else</span> <span class="keywordflow">if</span> (k%2 == 0) <a name="l00222"></a>00222 { <a name="l00223"></a>00223 fprintf(<a class="code" href="dtncat_8c.html#71f51a2e8cbe9a53031fa72596edc09f">info</a>,<span class="stringliteral">" "</span>); <span class="comment">// space every 2 bytes</span> <a name="l00224"></a>00224 } <a name="l00225"></a>00225 <a name="l00226"></a>00226 fprintf(<a class="code" href="dtncat_8c.html#71f51a2e8cbe9a53031fa72596edc09f">info</a>,<span class="stringliteral">"%02x"</span>, buffer[k] & 0xff); <a name="l00227"></a>00227 <a name="l00228"></a>00228 <span class="comment">// print character summary (a la emacs hexl-mode)</span> <a name="l00229"></a>00229 <span class="keywordflow">if</span> (k%BUFSIZ == BUFSIZ-1) <a name="l00230"></a>00230 { <a name="l00231"></a>00231 fprintf(<a class="code" href="dtncat_8c.html#71f51a2e8cbe9a53031fa72596edc09f">info</a>,<span class="stringliteral">" | %.*s\n"</span>, BUFSIZ, s_buffer); <a name="l00232"></a>00232 } <a name="l00233"></a>00233 } <a name="l00234"></a>00234 <a name="l00235"></a>00235 <span class="comment">// print spaces to fill out the rest of the line</span> <a name="l00236"></a>00236 <span class="keywordflow">if</span> (k%BUFSIZ != BUFSIZ-1) { <a name="l00237"></a>00237 <span class="keywordflow">while</span> (k%BUFSIZ != BUFSIZ-1) { <a name="l00238"></a>00238 <span class="keywordflow">if</span> (k%2 == 0) { <a name="l00239"></a>00239 fprintf(<a class="code" href="dtncat_8c.html#71f51a2e8cbe9a53031fa72596edc09f">info</a>,<span class="stringliteral">" "</span>); <a name="l00240"></a>00240 } <a name="l00241"></a>00241 fprintf(<a class="code" href="dtncat_8c.html#71f51a2e8cbe9a53031fa72596edc09f">info</a>,<span class="stringliteral">" "</span>); <a name="l00242"></a>00242 k++; <a name="l00243"></a>00243 } <a name="l00244"></a>00244 fprintf(<a class="code" href="dtncat_8c.html#71f51a2e8cbe9a53031fa72596edc09f">info</a>,<span class="stringliteral">" | %.*s\n"</span>, <a name="l00245"></a>00245 (<span class="keywordtype">int</span>)primary_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>%BUFSIZ, <a name="l00246"></a>00246 s_buffer); <a name="l00247"></a>00247 } <a name="l00248"></a>00248 fprintf(<a class="code" href="dtncat_8c.html#71f51a2e8cbe9a53031fa72596edc09f">info</a>,<span class="stringliteral">"\n"</span>); <a name="l00249"></a>00249 } <a name="l00250"></a>00250 } <a name="l00251"></a>00251 <a name="l00252"></a>00252 <span class="comment">/*</span> <a name="l00253"></a>00253 <span class="comment"> * stdout -> [bundles]</span> <a name="l00254"></a>00254 <span class="comment"> */</span> <a name="l00255"></a>00255 <a name="l00256"></a>00256 <span class="keywordtype">void</span> <a name="l00257"></a><a class="code" href="dtncat_8c.html#14a8e20bb3844060ac4e927e6ba72eb7">00257</a> <a class="code" href="dtncat_8c.html#14a8e20bb3844060ac4e927e6ba72eb7">to_bundles</a>() <a name="l00258"></a>00258 { <a name="l00259"></a>00259 <a name="l00260"></a>00260 <span class="keywordtype">int</span> bytes, ret; <a name="l00261"></a>00261 <a class="code" href="structdtn__reg__info__t.html" title="Registration state.">dtn_reg_info_t</a> reg_report; <span class="comment">/* for reports, if reqd */</span> <a name="l00262"></a>00262 <a class="code" href="structdtn__reg__info__t.html" title="Registration state.">dtn_reg_info_t</a> reg_session; <span class="comment">/* for session reg, if reqd */</span> <a name="l00263"></a>00263 <a name="l00264"></a>00264 <span class="comment">// initialize bundle spec</span> <a name="l00265"></a>00265 memset(&bundle_spec, 0, <span class="keyword">sizeof</span>(bundle_spec)); <a name="l00266"></a>00266 <a class="code" href="dtncat_8c.html#8b10ca66cacac0bc52c3ce6737d8c85a">parse_eid</a>(<a class="code" href="dtncat_8c.html#01daea96255bb21a8979b3b45f5bbb70">handle</a>, &bundle_spec.<a class="code" href="structdtn__bundle__spec__t.html#8c2816b3ce9b92489b3b34c325a4cb4c">dest</a>, <a class="code" href="dtncat_8c.html#8f7af606d1623c716486d0dab4c70391">arg_dest</a>); <a name="l00267"></a>00267 <a class="code" href="dtncat_8c.html#8b10ca66cacac0bc52c3ce6737d8c85a">parse_eid</a>(<a class="code" href="dtncat_8c.html#01daea96255bb21a8979b3b45f5bbb70">handle</a>, &bundle_spec.<a class="code" href="structdtn__bundle__spec__t.html#3e0a3530457d11bea38b06d00dea30fa">source</a>, <a class="code" href="dtncat_8c.html#b65c55eb53174efdd1d8a13c15a14fe7">arg_source</a>); <a name="l00268"></a>00268 <a name="l00269"></a>00269 <span class="keywordflow">if</span> (<a class="code" href="dtncat_8c.html#cc3f40bcc31639227d6f74b3e0e6915c">arg_replyto</a> == NULL) { <a name="l00270"></a>00270 <a class="code" href="dtn__api_8c.html#b2935a9a7f4ade630f7d2ad1fec5c615" title="Copy the contents of one eid into another.">dtn_copy_eid</a>(&bundle_spec.<a class="code" href="structdtn__bundle__spec__t.html#f76b43d28b76b155d48df0abe82c6913">replyto</a>, &bundle_spec.<a class="code" href="structdtn__bundle__spec__t.html#3e0a3530457d11bea38b06d00dea30fa">source</a>); <a name="l00271"></a>00271 } <span class="keywordflow">else</span> { <a name="l00272"></a>00272 <a class="code" href="dtncat_8c.html#8b10ca66cacac0bc52c3ce6737d8c85a">parse_eid</a>(<a class="code" href="dtncat_8c.html#01daea96255bb21a8979b3b45f5bbb70">handle</a>, &bundle_spec.<a class="code" href="structdtn__bundle__spec__t.html#f76b43d28b76b155d48df0abe82c6913">replyto</a>, <a class="code" href="dtncat_8c.html#cc3f40bcc31639227d6f74b3e0e6915c">arg_replyto</a>); <a name="l00273"></a>00273 } <a name="l00274"></a>00274 <a name="l00275"></a>00275 <span class="keywordflow">if</span> (<a class="code" href="dtncat_8c.html#0b2caeb4b6f130be43e5a2f0267dd453">verbose</a>) { <a name="l00276"></a>00276 <a class="code" href="dtncat_8c.html#a9d57d4d6b613ab254545fd140ebe5c8">print_eid</a>(<a class="code" href="dtncat_8c.html#71f51a2e8cbe9a53031fa72596edc09f">info</a>, <span class="stringliteral">"source_eid"</span>, &bundle_spec.<a class="code" href="structdtn__bundle__spec__t.html#3e0a3530457d11bea38b06d00dea30fa">source</a>); <a name="l00277"></a>00277 <a class="code" href="dtncat_8c.html#a9d57d4d6b613ab254545fd140ebe5c8">print_eid</a>(<a class="code" href="dtncat_8c.html#71f51a2e8cbe9a53031fa72596edc09f">info</a>, <span class="stringliteral">"replyto_eid"</span>, &bundle_spec.<a class="code" href="structdtn__bundle__spec__t.html#f76b43d28b76b155d48df0abe82c6913">replyto</a>); <a name="l00278"></a>00278 <a class="code" href="dtncat_8c.html#a9d57d4d6b613ab254545fd140ebe5c8">print_eid</a>(<a class="code" href="dtncat_8c.html#71f51a2e8cbe9a53031fa72596edc09f">info</a>, <span class="stringliteral">"dest_eid"</span>, &bundle_spec.<a class="code" href="structdtn__bundle__spec__t.html#8c2816b3ce9b92489b3b34c325a4cb4c">dest</a>); <a name="l00279"></a>00279 } <a name="l00280"></a>00280 <a name="l00281"></a>00281 <span class="keywordflow">if</span> (<a class="code" href="dtncat_8c.html#fe53bb8563092a6a7cc95bbdfd4e2721">wait_for_report</a>) { <a name="l00282"></a>00282 <span class="comment">// if we're given a regid, bind to it, otherwise make a</span> <a name="l00283"></a>00283 <span class="comment">// registration for incoming reports</span> <a name="l00284"></a>00284 <span class="keywordflow">if</span> (<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="l00285"></a>00285 <span class="keywordflow">if</span> (<a class="code" href="dtn__api_8c.html#ab949d76f4c34a202aea5bac853b310b" title="Associate a registration with the current ipc channel.">dtn_bind</a>(<a class="code" href="dtncat_8c.html#01daea96255bb21a8979b3b45f5bbb70">handle</a>, <a class="code" href="dtncat_8c.html#8eb0c3e35c1feb7baf9802f03bf42e41">regid</a>) != <a class="code" href="dtn__errno_8h.html#3723251cb5d056b6ace3e22561da1e11" title="DTN API error codes.">DTN_SUCCESS</a>) { <a name="l00286"></a>00286 fprintf(stderr, <span class="stringliteral">"%s: error in bind (id=0x%x): %d (%s)\n"</span>, <a name="l00287"></a>00287 <a class="code" href="dtncat_8c.html#b9e1449fd00c98428516f0b41eddcb10">progname</a>, <a class="code" href="dtncat_8c.html#8eb0c3e35c1feb7baf9802f03bf42e41">regid</a>, 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>(<a class="code" href="dtncat_8c.html#01daea96255bb21a8979b3b45f5bbb70">handle</a>))); <a name="l00288"></a>00288 exit(EXIT_FAILURE); <a name="l00289"></a>00289 } <a name="l00290"></a>00290 } <span class="keywordflow">else</span> { <a name="l00291"></a>00291 memset(&reg_report, 0, <span class="keyword">sizeof</span>(reg_report)); <a name="l00292"></a>00292 <a class="code" href="dtn__api_8c.html#b2935a9a7f4ade630f7d2ad1fec5c615" title="Copy the contents of one eid into another.">dtn_copy_eid</a>(&reg_report.<a class="code" href="structdtn__reg__info__t.html#07df1822e2808b2127710a8b54acd07f">endpoint</a>, &bundle_spec.<a class="code" href="structdtn__bundle__spec__t.html#f76b43d28b76b155d48df0abe82c6913">replyto</a>); <a name="l00293"></a>00293 reg_report.<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="l00294"></a>00294 reg_report.<a class="code" href="structdtn__reg__info__t.html#dd4b3b0c9f27a0375369f35e33be686d">expiration</a> = <a class="code" href="dtncat_8c.html#2af892c305953806a6b6fb3f55963bbc">REG_EXPIRE</a>; <a name="l00295"></a>00295 <a class="code" href="dtncat_8c.html#5f3182fedba4dab2c150f77dbd997df1">make_registration</a>(&reg_report); <a name="l00296"></a>00296 } <a name="l00297"></a>00297 } <a name="l00298"></a>00298 <a name="l00299"></a>00299 <span class="keywordflow">if</span> (<a class="code" href="dtncat_8c.html#7508c434c1f2152c7fd03381726d0a2a">session_flags</a>) { <a name="l00300"></a>00300 <span class="comment">// make a publisher registration </span> <a name="l00301"></a>00301 memset(&reg_session, 0, <span class="keyword">sizeof</span>(reg_session)); <a name="l00302"></a>00302 <a class="code" href="dtn__api_8c.html#b2935a9a7f4ade630f7d2ad1fec5c615" title="Copy the contents of one eid into another.">dtn_copy_eid</a>(&reg_session.<a class="code" href="structdtn__reg__info__t.html#07df1822e2808b2127710a8b54acd07f">endpoint</a>, &bundle_spec.<a class="code" href="structdtn__bundle__spec__t.html#8c2816b3ce9b92489b3b34c325a4cb4c">dest</a>); <a name="l00303"></a>00303 reg_session.<a class="code" href="structdtn__reg__info__t.html#7bf2e33b713b585bfe1792c40fa8cd6c">flags</a> = <a class="code" href="dtn__types_8h.html#a6d0071f396dd4ef85f6ad6332e37f000b1aebf4fb3e0186630c9cd5a702538a">DTN_SESSION_PUBLISH</a>; <a name="l00304"></a>00304 reg_session.<a class="code" href="structdtn__reg__info__t.html#dd4b3b0c9f27a0375369f35e33be686d">expiration</a> = 0; <a name="l00305"></a>00305 <a class="code" href="dtncat_8c.html#5f3182fedba4dab2c150f77dbd997df1">make_registration</a>(&reg_session); <a name="l00306"></a>00306 } <a name="l00307"></a>00307 <a name="l00308"></a>00308 <span class="comment">// set the dtn options</span> <a name="l00309"></a>00309 bundle_spec.<a class="code" href="structdtn__bundle__spec__t.html#57f2d6068db6a5b38a73416ea721e814">expiration</a> = <a class="code" href="dtncat_8c.html#d6057e40387509de502bdc91007d3238">expiration</a>; <a name="l00310"></a>00310 <a name="l00311"></a>00311 <span class="keywordflow">if</span> (<a class="code" href="dtncat_8c.html#1bdbebbcf901e059d8765070846f9ee8">delivery_receipts</a>) { <a name="l00312"></a>00312 <span class="comment">// set the delivery receipt option</span> <a name="l00313"></a>00313 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="l00314"></a>00314 } <a name="l00315"></a>00315 <a name="l00316"></a>00316 <span class="keywordflow">if</span> (<a class="code" href="dtncat_8c.html#6dd7ec74d1d4d8312e0f4cad76a3ebae">forwarding_receipts</a>) { <a name="l00317"></a>00317 <span class="comment">// set the forward receipt option</span> <a name="l00318"></a>00318 bundle_spec.<a class="code" href="structdtn__bundle__spec__t.html#476482803410f3a19b40cbff91e1e56c">dopts</a> |= <a class="code" href="dtn__types_8h.html#ed7af5cc4e44a2ced1acdee4e441f000f1140b2789c648d104e6ec8a78bc3cea">DOPTS_FORWARD_RCPT</a>; <a name="l00319"></a>00319 } <a name="l00320"></a>00320 <a name="l00321"></a>00321 <span class="keywordflow">if</span> (<a class="code" href="dtncat_8c.html#160881851a33309c0106503ac4d14d96">custody</a>) { <a name="l00322"></a>00322 <span class="comment">// request custody transfer</span> <a name="l00323"></a>00323 bundle_spec.<a class="code" href="structdtn__bundle__spec__t.html#476482803410f3a19b40cbff91e1e56c">dopts</a> |= <a class="code" href="dtn__types_8h.html#ed7af5cc4e44a2ced1acdee4e441f000cf365df7de1d4ff463456b4adbafaf0c">DOPTS_CUSTODY</a>; <a name="l00324"></a>00324 } <a name="l00325"></a>00325 <a name="l00326"></a>00326 <span class="keywordflow">if</span> (<a class="code" href="dtncat_8c.html#e75d07ae6162cb4c080ca4b0189f5302">custody_receipts</a>) { <a name="l00327"></a>00327 <span class="comment">// request custody transfer</span> <a name="l00328"></a>00328 bundle_spec.<a class="code" href="structdtn__bundle__spec__t.html#476482803410f3a19b40cbff91e1e56c">dopts</a> |= <a class="code" href="dtn__types_8h.html#ed7af5cc4e44a2ced1acdee4e441f000df337d9033e6091548861d7197ea1ae1">DOPTS_CUSTODY_RCPT</a>; <a name="l00329"></a>00329 } <a name="l00330"></a>00330 <a name="l00331"></a>00331 <span class="keywordflow">if</span> (<a class="code" href="dtncat_8c.html#82c638daee7e7ec8f669285e64ebb511">receive_receipts</a>) { <a name="l00332"></a>00332 <span class="comment">// request receive receipt</span> <a name="l00333"></a>00333 bundle_spec.<a class="code" href="structdtn__bundle__spec__t.html#476482803410f3a19b40cbff91e1e56c">dopts</a> |= <a class="code" href="dtn__types_8h.html#ed7af5cc4e44a2ced1acdee4e441f0001240065bb26608579eedd4b022f3397f">DOPTS_RECEIVE_RCPT</a>; <a name="l00334"></a>00334 } <a name="l00335"></a>00335 <a name="l00336"></a>00336 <span class="keywordflow">if</span> (<a class="code" href="dtncat_8c.html#9ca580976e59c0af2763e9e2e78bea66">sequence_id</a>) { <a name="l00337"></a>00337 bundle_spec.<a class="code" href="structdtn__bundle__spec__t.html#60a24eed29224ad842136b87241108b7">sequence_id</a>.<a class="code" href="structdtn__sequence__id__t.html#bdbb1a6df2afea41dccb74f4ea8bbadc">data</a>.<a class="code" href="structdtn__sequence__id__t.html#aaf2850ca5853b9b1bca2791d16e969a">data_val</a> = <a class="code" href="dtncat_8c.html#9ca580976e59c0af2763e9e2e78bea66">sequence_id</a>; <a name="l00338"></a>00338 bundle_spec.<a class="code" href="structdtn__bundle__spec__t.html#60a24eed29224ad842136b87241108b7">sequence_id</a>.<a class="code" href="structdtn__sequence__id__t.html#bdbb1a6df2afea41dccb74f4ea8bbadc">data</a>.<a class="code" href="structdtn__sequence__id__t.html#7ea9c5585efae94220749c79f41080d7">data_len</a> = strlen(<a class="code" href="dtncat_8c.html#9ca580976e59c0af2763e9e2e78bea66">sequence_id</a>); <a name="l00339"></a>00339 } <a name="l00340"></a>00340 <a name="l00341"></a>00341 <span class="keywordflow">if</span> (<a class="code" href="dtncat_8c.html#53950f44ae10fbde2d8ae21493f50ffd">obsoletes_id</a>) { <a name="l00342"></a>00342 bundle_spec.<a class="code" href="structdtn__bundle__spec__t.html#a3239046abcbbb355b8b3d136769078a">obsoletes_id</a>.<a class="code" href="structdtn__sequence__id__t.html#bdbb1a6df2afea41dccb74f4ea8bbadc">data</a>.<a class="code" href="structdtn__sequence__id__t.html#aaf2850ca5853b9b1bca2791d16e969a">data_val</a> = <a class="code" href="dtncat_8c.html#53950f44ae10fbde2d8ae21493f50ffd">obsoletes_id</a>; <a name="l00343"></a>00343 bundle_spec.<a class="code" href="structdtn__bundle__spec__t.html#a3239046abcbbb355b8b3d136769078a">obsoletes_id</a>.<a class="code" href="structdtn__sequence__id__t.html#bdbb1a6df2afea41dccb74f4ea8bbadc">data</a>.<a class="code" href="structdtn__sequence__id__t.html#7ea9c5585efae94220749c79f41080d7">data_len</a> = strlen(<a class="code" href="dtncat_8c.html#53950f44ae10fbde2d8ae21493f50ffd">obsoletes_id</a>); <a name="l00344"></a>00344 } <a name="l00345"></a>00345 <a name="l00346"></a>00346 <span class="keywordflow">if</span> ((bytes = <a class="code" href="dtncat_8c.html#e66a979abf383ee357553609993b3d1f">fill_payload</a>(&primary_payload)) < 0) { <a name="l00347"></a>00347 fprintf(stderr, <span class="stringliteral">"%s: error reading bundle data\n"</span>, <a name="l00348"></a>00348 <a class="code" href="dtncat_8c.html#b9e1449fd00c98428516f0b41eddcb10">progname</a>); <a name="l00349"></a>00349 exit(EXIT_FAILURE); <a name="l00350"></a>00350 } <a name="l00351"></a>00351 <a name="l00352"></a>00352 memset(&bundle_id, 0, <span class="keyword">sizeof</span>(bundle_id)); <a name="l00353"></a>00353 <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>(<a class="code" href="dtncat_8c.html#01daea96255bb21a8979b3b45f5bbb70">handle</a>, <a class="code" href="dtncat_8c.html#8eb0c3e35c1feb7baf9802f03bf42e41">regid</a>, &bundle_spec, &primary_payload, <a name="l00354"></a>00354 &bundle_id)) != 0) { <a name="l00355"></a>00355 fprintf(stderr, <span class="stringliteral">"%s: error sending bundle: %d (%s)\n"</span>, <a name="l00356"></a>00356 <a class="code" href="dtncat_8c.html#b9e1449fd00c98428516f0b41eddcb10">progname</a>, 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>(<a class="code" href="dtncat_8c.html#01daea96255bb21a8979b3b45f5bbb70">handle</a>))); <a name="l00357"></a>00357 exit(EXIT_FAILURE); <a name="l00358"></a>00358 } <a name="l00359"></a>00359 <a name="l00360"></a>00360 <span class="keywordflow">if</span> (<a class="code" href="dtncat_8c.html#0b2caeb4b6f130be43e5a2f0267dd453">verbose</a>) <a name="l00361"></a>00361 fprintf(<a class="code" href="dtncat_8c.html#71f51a2e8cbe9a53031fa72596edc09f">info</a>, <span class="stringliteral">"Read %d bytes from stdin and wrote to bundles\n"</span>, <a name="l00362"></a>00362 bytes); <a name="l00363"></a>00363 <a name="l00364"></a>00364 <span class="keywordflow">if</span> (<a class="code" href="dtncat_8c.html#fe53bb8563092a6a7cc95bbdfd4e2721">wait_for_report</a>) { <a name="l00365"></a>00365 memset(&reply_spec, 0, <span class="keyword">sizeof</span>(reply_spec)); <a name="l00366"></a>00366 memset(&reply_payload, 0, <span class="keyword">sizeof</span>(reply_payload)); <a name="l00367"></a>00367 <a name="l00368"></a>00368 <span class="comment">// now we block waiting for any replies</span> <a name="l00369"></a>00369 <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>(<a class="code" href="dtncat_8c.html#01daea96255bb21a8979b3b45f5bbb70">handle</a>, &reply_spec, <a name="l00370"></a>00370 <a class="code" href="dtn__types_8h.html#3dcfddc1b850a71a18d8a0868f67e7628f773bbfb80857bd5a11f09665fa9b03">DTN_PAYLOAD_MEM</a>, &reply_payload, -1)) < 0) { <a name="l00371"></a>00371 fprintf(stderr, <span class="stringliteral">"%s: error getting reply: %d (%s)\n"</span>, <a name="l00372"></a>00372 <a class="code" href="dtncat_8c.html#b9e1449fd00c98428516f0b41eddcb10">progname</a>, 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>(<a class="code" href="dtncat_8c.html#01daea96255bb21a8979b3b45f5bbb70">handle</a>))); <a name="l00373"></a>00373 exit(EXIT_FAILURE); <a name="l00374"></a>00374 } <a name="l00375"></a>00375 <span class="keywordflow">if</span> (<a class="code" href="namespacedtnsim.html#372b0bd474085f20b38efbbade7ce72a" title="Override gettimeofday to return the simulator time.">gettimeofday</a>(&<a class="code" href="dtncat_8c.html#7ab59805f7a1819164bc301293db600d">end</a>, NULL) < 0) { <a name="l00376"></a>00376 fprintf(stderr, <span class="stringliteral">"%s: gettimeofday(end) returned error %s\n"</span>, <a name="l00377"></a>00377 <a class="code" href="dtncat_8c.html#b9e1449fd00c98428516f0b41eddcb10">progname</a>, strerror(<a class="code" href="IPDiscovery_8cc.html#d65a8842cc674e3ddf69355898c0ecbf">errno</a>)); <a name="l00378"></a>00378 exit(EXIT_FAILURE); <a name="l00379"></a>00379 } <a name="l00380"></a>00380 <a name="l00381"></a>00381 <span class="keywordflow">if</span> (<a class="code" href="dtncat_8c.html#0b2caeb4b6f130be43e5a2f0267dd453">verbose</a>) <a name="l00382"></a>00382 fprintf(<a class="code" href="dtncat_8c.html#71f51a2e8cbe9a53031fa72596edc09f">info</a>, <span class="stringliteral">"got %d byte report from [%s]: time=%.1f ms\n"</span>, <a name="l00383"></a>00383 reply_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="l00384"></a>00384 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="l00385"></a>00385 ((<span class="keywordtype">double</span>)(<a class="code" href="dtncat_8c.html#7ab59805f7a1819164bc301293db600d">end</a>.tv_sec - start.tv_sec) * 1000.0 + <a name="l00386"></a>00386 (<span class="keywordtype">double</span>)(<a class="code" href="dtncat_8c.html#7ab59805f7a1819164bc301293db600d">end</a>.tv_usec - start.tv_usec)/1000.0)); <a name="l00387"></a>00387 } <a name="l00388"></a>00388 } <a name="l00389"></a>00389 <a name="l00390"></a>00390 <a name="l00391"></a><a class="code" href="dtncat_8c.html#e5ad5cbeccaedc03a48d3c7eaa803e79">00391</a> <span class="keywordtype">void</span> <a class="code" href="dtncat_8c.html#e5ad5cbeccaedc03a48d3c7eaa803e79">print_usage</a>() <a name="l00392"></a>00392 { <a name="l00393"></a>00393 fprintf(stderr, <span class="stringliteral">"To source bundles from stdin:\n"</span>); <a name="l00394"></a>00394 fprintf(stderr, <span class="stringliteral">" usage: %s [opts] -s <source_eid> -d <dest_eid>\n"</span>, <a name="l00395"></a>00395 <a class="code" href="dtncat_8c.html#b9e1449fd00c98428516f0b41eddcb10">progname</a>); <a name="l00396"></a>00396 fprintf(stderr, <span class="stringliteral">"To receive bundles to stdout:\n"</span>); <a name="l00397"></a>00397 fprintf(stderr, <span class="stringliteral">" usage: %s [opts] -l <receive_eid>\n"</span>, <a class="code" href="dtncat_8c.html#b9e1449fd00c98428516f0b41eddcb10">progname</a>); <a name="l00398"></a>00398 <a name="l00399"></a>00399 fprintf(stderr, <span class="stringliteral">"common options:\n"</span>); <a name="l00400"></a>00400 fprintf(stderr, <span class="stringliteral">" -v verbose\n"</span>); <a name="l00401"></a>00401 fprintf(stderr, <span class="stringliteral">" -h/H help\n"</span>); <a name="l00402"></a>00402 fprintf(stderr, <span class="stringliteral">" -i <regid> registration id for listening\n"</span>); <a name="l00403"></a>00403 fprintf(stderr, <span class="stringliteral">"receive only options (-l option required):\n"</span>); <a name="l00404"></a>00404 fprintf(stderr, <span class="stringliteral">" -l <eid> receive bundles destined for eid (instead of sending)\n"</span>); <a name="l00405"></a>00405 fprintf(stderr, <span class="stringliteral">" -n <count> exit after count bundles received (-l option required)\n"</span>); <a name="l00406"></a>00406 fprintf(stderr, <span class="stringliteral">"send only options (-l option prohibited):\n"</span>); <a name="l00407"></a>00407 fprintf(stderr, <span class="stringliteral">" -s <eid|demux_string> source eid)\n"</span>); <a name="l00408"></a>00408 fprintf(stderr, <span class="stringliteral">" -d <eid|demux_string> destination eid)\n"</span>); <a name="l00409"></a>00409 fprintf(stderr, <span class="stringliteral">" -r <eid|demux_string> reply to eid)\n"</span>); <a name="l00410"></a>00410 fprintf(stderr, <span class="stringliteral">" -e <time> expiration time in seconds (default: one hour)\n"</span>); <a name="l00411"></a>00411 fprintf(stderr, <span class="stringliteral">" -c request custody transfer\n"</span>); <a name="l00412"></a>00412 fprintf(stderr, <span class="stringliteral">" -C request custody transfer receipts\n"</span>); <a name="l00413"></a>00413 fprintf(stderr, <span class="stringliteral">" -D request for end-to-end delivery receipt\n"</span>); <a name="l00414"></a>00414 fprintf(stderr, <span class="stringliteral">" -R request for bundle reception receipts\n"</span>); <a name="l00415"></a>00415 fprintf(stderr, <span class="stringliteral">" -F request for bundle forwarding receipts\n"</span>); <a name="l00416"></a>00416 fprintf(stderr, <span class="stringliteral">" -w wait for bundle status reports\n"</span>); <a name="l00417"></a>00417 fprintf(stderr, <span class="stringliteral">" -S <sequence_id> sequence id vector\n"</span>); <a name="l00418"></a>00418 fprintf(stderr, <span class="stringliteral">" -O <obsoletes_id> obsoletes id vector\n"</span>); <a name="l00419"></a>00419 <a name="l00420"></a>00420 <span class="keywordflow">return</span>; <a name="l00421"></a>00421 } <a name="l00422"></a>00422 <a name="l00423"></a>00423 <span class="keywordtype">void</span> <a name="l00424"></a><a class="code" href="dtncat_8c.html#293abb58b132c26701dada5c4e57ca35">00424</a> <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="l00425"></a>00425 { <a name="l00426"></a>00426 <span class="keywordtype">int</span> c, done = 0; <a name="l00427"></a>00427 <span class="keywordtype">int</span> lopts = 0, notlopts = 0; <a name="l00428"></a>00428 <a name="l00429"></a>00429 <a class="code" href="dtncat_8c.html#b9e1449fd00c98428516f0b41eddcb10">progname</a> = argv[0]; <a name="l00430"></a>00430 <a name="l00431"></a>00431 <span class="keywordflow">while</span> (!done) { <a name="l00432"></a>00432 c = getopt(argc, argv, <span class="stringliteral">"l:vhHr:s:d:e:wDFRcCi:n:S:O:"</span>); <a name="l00433"></a>00433 <span class="keywordflow">switch</span> (c) { <a name="l00434"></a>00434 <span class="keywordflow">case</span> <span class="charliteral">'l'</span>: <a name="l00435"></a>00435 <a class="code" href="dtncat_8c.html#35bb644b5e618ea5ad790f7b181e47d6">from_bundles_flag</a> = 1; <a name="l00436"></a>00436 <a class="code" href="dtncat_8c.html#3e61efb260f461216d7465bdbaa3e778">arg_receive</a> = optarg; <a name="l00437"></a>00437 <span class="keywordflow">break</span>; <a name="l00438"></a>00438 <span class="keywordflow">case</span> <span class="charliteral">'v'</span>: <a name="l00439"></a>00439 <a class="code" href="dtncat_8c.html#0b2caeb4b6f130be43e5a2f0267dd453">verbose</a> = 1; <a name="l00440"></a>00440 <span class="keywordflow">break</span>; <a name="l00441"></a>00441 <span class="keywordflow">case</span> <span class="charliteral">'h'</span>: <a name="l00442"></a>00442 <span class="keywordflow">case</span> <span class="charliteral">'H'</span>: <a name="l00443"></a>00443 <a class="code" href="dtncat_8c.html#e5ad5cbeccaedc03a48d3c7eaa803e79">print_usage</a>(); <a name="l00444"></a>00444 exit(EXIT_SUCCESS); <a name="l00445"></a>00445 <span class="keywordflow">return</span>; <a name="l00446"></a>00446 <span class="keywordflow">case</span> <span class="charliteral">'r'</span>: <a name="l00447"></a>00447 <a class="code" href="dtncat_8c.html#cc3f40bcc31639227d6f74b3e0e6915c">arg_replyto</a> = optarg; <a name="l00448"></a>00448 lopts++; <a name="l00449"></a>00449 <span class="keywordflow">break</span>; <a name="l00450"></a>00450 <span class="keywordflow">case</span> <span class="charliteral">'s'</span>: <a name="l00451"></a>00451 <a class="code" href="dtncat_8c.html#b65c55eb53174efdd1d8a13c15a14fe7">arg_source</a> = optarg; <a name="l00452"></a>00452 notlopts++; <a name="l00453"></a>00453 <span class="keywordflow">break</span>; <a name="l00454"></a>00454 <span class="keywordflow">case</span> <span class="charliteral">'d'</span>: <a name="l00455"></a>00455 <a class="code" href="dtncat_8c.html#8f7af606d1623c716486d0dab4c70391">arg_dest</a> = optarg; <a name="l00456"></a>00456 notlopts++; <a name="l00457"></a>00457 <span class="keywordflow">break</span>; <a name="l00458"></a>00458 <span class="keywordflow">case</span> <span class="charliteral">'e'</span>: <a name="l00459"></a>00459 <a class="code" href="dtncat_8c.html#d6057e40387509de502bdc91007d3238">expiration</a> = atoi(optarg); <a name="l00460"></a>00460 notlopts++; <a name="l00461"></a>00461 <span class="keywordflow">break</span>; <a name="l00462"></a>00462 <span class="keywordflow">case</span> <span class="charliteral">'w'</span>: <a name="l00463"></a>00463 <a class="code" href="dtncat_8c.html#fe53bb8563092a6a7cc95bbdfd4e2721">wait_for_report</a> = 1; <a name="l00464"></a>00464 notlopts++; <a name="l00465"></a>00465 <span class="keywordflow">break</span>; <a name="l00466"></a>00466 <span class="keywordflow">case</span> <span class="charliteral">'D'</span>: <a name="l00467"></a>00467 <a class="code" href="dtncat_8c.html#1bdbebbcf901e059d8765070846f9ee8">delivery_receipts</a> = 1; <a name="l00468"></a>00468 notlopts++; <a name="l00469"></a>00469 <span class="keywordflow">break</span>; <a name="l00470"></a>00470 <span class="keywordflow">case</span> <span class="charliteral">'F'</span>: <a name="l00471"></a>00471 <a class="code" href="dtncat_8c.html#6dd7ec74d1d4d8312e0f4cad76a3ebae">forwarding_receipts</a> = 1; <a name="l00472"></a>00472 notlopts++; <a name="l00473"></a>00473 <span class="keywordflow">break</span>; <a name="l00474"></a>00474 <span class="keywordflow">case</span> <span class="charliteral">'R'</span>: <a name="l00475"></a>00475 <a class="code" href="dtncat_8c.html#82c638daee7e7ec8f669285e64ebb511">receive_receipts</a> = 1; <a name="l00476"></a>00476 notlopts++; <a name="l00477"></a>00477 <span class="keywordflow">break</span>; <a name="l00478"></a>00478 <span class="keywordflow">case</span> <span class="charliteral">'c'</span>: <a name="l00479"></a>00479 <a class="code" href="dtncat_8c.html#160881851a33309c0106503ac4d14d96">custody</a> = 1; <a name="l00480"></a>00480 notlopts++; <a name="l00481"></a>00481 <span class="keywordflow">break</span>; <a name="l00482"></a>00482 <span class="keywordflow">case</span> <span class="charliteral">'C'</span>: <a name="l00483"></a>00483 <a class="code" href="dtncat_8c.html#e75d07ae6162cb4c080ca4b0189f5302">custody_receipts</a> = 1; <a name="l00484"></a>00484 notlopts++; <a name="l00485"></a>00485 <span class="keywordflow">break</span>; <a name="l00486"></a>00486 <span class="keywordflow">case</span> <span class="charliteral">'i'</span>: <a name="l00487"></a>00487 <a class="code" href="dtncat_8c.html#8eb0c3e35c1feb7baf9802f03bf42e41">regid</a> = atoi(optarg); <a name="l00488"></a>00488 notlopts++; <a name="l00489"></a>00489 <span class="keywordflow">break</span>; <a name="l00490"></a>00490 <span class="keywordflow">case</span> <span class="charliteral">'n'</span>: <a name="l00491"></a>00491 <a class="code" href="dtncat_8c.html#057bbda8ea4dd2a0c5fc62ea88f55e6b">bundle_count</a> = atoi(optarg); <a name="l00492"></a>00492 lopts++; <a name="l00493"></a>00493 <span class="keywordflow">break</span>; <a name="l00494"></a>00494 <span class="keywordflow">case</span> <span class="charliteral">'S'</span>: <a name="l00495"></a>00495 <a class="code" href="dtncat_8c.html#9ca580976e59c0af2763e9e2e78bea66">sequence_id</a> = optarg; <a name="l00496"></a>00496 <span class="keywordflow">break</span>; <a name="l00497"></a>00497 <span class="keywordflow">case</span> <span class="charliteral">'O'</span>: <a name="l00498"></a>00498 <a class="code" href="dtncat_8c.html#53950f44ae10fbde2d8ae21493f50ffd">obsoletes_id</a> = optarg; <a name="l00499"></a>00499 <span class="keywordflow">break</span>; <a name="l00500"></a>00500 <span class="keywordflow">case</span> -1: <a name="l00501"></a>00501 done = 1; <a name="l00502"></a>00502 <span class="keywordflow">break</span>; <a name="l00503"></a>00503 <span class="keywordflow">default</span>: <a name="l00504"></a>00504 <span class="comment">// getopt already prints an error message for unknown</span> <a name="l00505"></a>00505 <span class="comment">// option characters</span> <a name="l00506"></a>00506 <a class="code" href="dtncat_8c.html#e5ad5cbeccaedc03a48d3c7eaa803e79">print_usage</a>(); <a name="l00507"></a>00507 exit(EXIT_FAILURE); <a name="l00508"></a>00508 } <a name="l00509"></a>00509 } <a name="l00510"></a>00510 <a name="l00511"></a>00511 <span class="keywordflow">if</span> (<a class="code" href="dtncat_8c.html#35bb644b5e618ea5ad790f7b181e47d6">from_bundles_flag</a> && (notlopts > 0)) { <a name="l00512"></a>00512 fprintf(stderr, <span class="stringliteral">"%s: error: transmission options specified when using -l flag\n"</span>, <a name="l00513"></a>00513 <a class="code" href="dtncat_8c.html#b9e1449fd00c98428516f0b41eddcb10">progname</a>); <a name="l00514"></a>00514 <a class="code" href="dtncat_8c.html#e5ad5cbeccaedc03a48d3c7eaa803e79">print_usage</a>(); <a name="l00515"></a>00515 exit(EXIT_FAILURE); <a name="l00516"></a>00516 } <a name="l00517"></a>00517 <a name="l00518"></a>00518 <span class="keywordflow">if</span> (!<a class="code" href="dtncat_8c.html#35bb644b5e618ea5ad790f7b181e47d6">from_bundles_flag</a> && (lopts > 0)) { <a name="l00519"></a>00519 fprintf(stderr, <span class="stringliteral">"%s: error: receive option specified but -l option not selected\n"</span>, <a name="l00520"></a>00520 <a class="code" href="dtncat_8c.html#b9e1449fd00c98428516f0b41eddcb10">progname</a>); <a name="l00521"></a>00521 <a class="code" href="dtncat_8c.html#e5ad5cbeccaedc03a48d3c7eaa803e79">print_usage</a>(); <a name="l00522"></a>00522 exit(EXIT_FAILURE); <a name="l00523"></a>00523 } <a name="l00524"></a>00524 <a name="l00525"></a>00525 <a name="l00526"></a>00526 <span class="preprocessor">#define CHECK_SET(_arg, _what) \</span> <a name="l00527"></a>00527 <span class="preprocessor"> if (_arg == 0) { \</span> <a name="l00528"></a>00528 <span class="preprocessor"> fprintf(stderr, "%s: %s must be specified\n", progname, _what); \</span> <a name="l00529"></a>00529 <span class="preprocessor"> print_usage(); \</span> <a name="l00530"></a>00530 <span class="preprocessor"> exit(EXIT_FAILURE); \</span> <a name="l00531"></a>00531 <span class="preprocessor"> }</span> <a name="l00532"></a>00532 <span class="preprocessor"></span> <a name="l00533"></a>00533 <span class="keywordflow">if</span> (!<a class="code" href="dtncat_8c.html#35bb644b5e618ea5ad790f7b181e47d6">from_bundles_flag</a>) { <a name="l00534"></a>00534 <span class="comment">/* transmitting to bundles - no -l option */</span> <a name="l00535"></a>00535 <a class="code" href="dtncat_8c.html#48408bd325becd2af358eea79e42f335">CHECK_SET</a>(<a class="code" href="dtncat_8c.html#b65c55eb53174efdd1d8a13c15a14fe7">arg_source</a>, <span class="stringliteral">"source eid"</span>); <a name="l00536"></a>00536 <a class="code" href="dtncat_8c.html#48408bd325becd2af358eea79e42f335">CHECK_SET</a>(<a class="code" href="dtncat_8c.html#8f7af606d1623c716486d0dab4c70391">arg_dest</a>, <span class="stringliteral">"destination eid"</span>); <a name="l00537"></a>00537 } <span class="keywordflow">else</span> { <a name="l00538"></a>00538 <span class="comment">/* receiving from bundles - -l option specified */</span> <a name="l00539"></a>00539 <a class="code" href="dtncat_8c.html#48408bd325becd2af358eea79e42f335">CHECK_SET</a>(<a class="code" href="dtncat_8c.html#3e61efb260f461216d7465bdbaa3e778">arg_receive</a>, <span class="stringliteral">"receive eid"</span>); <a name="l00540"></a>00540 <span class="keywordflow">if</span> (<a class="code" href="dtncat_8c.html#057bbda8ea4dd2a0c5fc62ea88f55e6b">bundle_count</a> == -1) { <a name="l00541"></a>00541 <a class="code" href="dtncat_8c.html#057bbda8ea4dd2a0c5fc62ea88f55e6b">bundle_count</a> = <a class="code" href="dtncat_8c.html#f0dcc53259374250d9ed605c739de604">DEFAULT_BUNDLE_COUNT</a>; <a name="l00542"></a>00542 } <a name="l00543"></a>00543 } <a name="l00544"></a>00544 } <a name="l00545"></a>00545 <a name="l00546"></a>00546 <a class="code" href="structdtn__endpoint__id__t.html" title="Specification of a dtn endpoint id, i.e.">dtn_endpoint_id_t</a> * <a name="l00547"></a><a class="code" href="dtncat_8c.html#8b10ca66cacac0bc52c3ce6737d8c85a">00547</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="l00548"></a>00548 { <a name="l00549"></a>00549 <span class="comment">// try the string as an actual dtn eid</span> <a name="l00550"></a>00550 <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="l00551"></a>00551 <span class="keywordflow">if</span> (<a class="code" href="dtncat_8c.html#0b2caeb4b6f130be43e5a2f0267dd453">verbose</a>) <a name="l00552"></a>00552 fprintf(<a class="code" href="dtncat_8c.html#71f51a2e8cbe9a53031fa72596edc09f">info</a>, <span class="stringliteral">"%s (literal)\n"</span>, str); <a name="l00553"></a>00553 <span class="keywordflow">return</span> eid; <a name="l00554"></a>00554 } <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="l00555"></a>00555 <span class="comment">// build a local eid based on the configuration of our dtn</span> <a name="l00556"></a>00556 <span class="comment">// router plus the str as demux string</span> <a name="l00557"></a>00557 <span class="keywordflow">if</span> (<a class="code" href="dtncat_8c.html#0b2caeb4b6f130be43e5a2f0267dd453">verbose</a>) fprintf(<a class="code" href="dtncat_8c.html#71f51a2e8cbe9a53031fa72596edc09f">info</a>, <span class="stringliteral">"%s (local)\n"</span>, str); <a name="l00558"></a>00558 <span class="keywordflow">return</span> eid; <a name="l00559"></a>00559 } <span class="keywordflow">else</span> { <a name="l00560"></a>00560 fprintf(stderr, <span class="stringliteral">"invalid eid string '%s'\n"</span>, str); <a name="l00561"></a>00561 exit(EXIT_FAILURE); <a name="l00562"></a>00562 } <a name="l00563"></a>00563 } <a name="l00564"></a>00564 <a name="l00565"></a>00565 <span class="keywordtype">void</span> <a name="l00566"></a><a class="code" href="dtncat_8c.html#a9d57d4d6b613ab254545fd140ebe5c8">00566</a> <a class="code" href="dtncat_8c.html#a9d57d4d6b613ab254545fd140ebe5c8">print_eid</a>(FILE *dest, <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="l00567"></a>00567 { <a name="l00568"></a>00568 fprintf(dest, <span class="stringliteral">"%s [%s]\n"</span>, label, eid-><a class="code" href="structdtn__endpoint__id__t.html#d2e7d5788ae778c77b4041f1f8b1dc80">uri</a>); <a name="l00569"></a>00569 } <a name="l00570"></a>00570 <a name="l00571"></a>00571 <span class="comment">/*</span> <a name="l00572"></a>00572 <span class="comment"> * read from stdin to get the payload</span> <a name="l00573"></a>00573 <span class="comment"> */</span> <a name="l00574"></a>00574 <a name="l00575"></a>00575 <span class="keywordtype">int</span> <a name="l00576"></a><a class="code" href="dtncat_8c.html#e66a979abf383ee357553609993b3d1f">00576</a> <a class="code" href="dtncat_8c.html#e66a979abf383ee357553609993b3d1f">fill_payload</a>(<a class="code" href="structdtn__bundle__payload__t.html">dtn_bundle_payload_t</a>* payload) <a name="l00577"></a>00577 { <a name="l00578"></a>00578 <a name="l00579"></a>00579 <span class="keywordtype">unsigned</span> <span class="keywordtype">char</span> <a class="code" href="num2sdnv_8c.html#a81cdcc7ff6987bc85c073253e32715f">buf</a>[BUFSIZ]; <a name="l00580"></a>00580 <span class="keywordtype">unsigned</span> <span class="keywordtype">char</span> *p = (<span class="keywordtype">unsigned</span> <span class="keywordtype">char</span>*) <a class="code" href="dtncat_8c.html#5287cc892023d51088dd91a9b78de7c5">payload_buf</a>; <a name="l00581"></a>00581 <span class="keywordtype">unsigned</span> <span class="keywordtype">char</span> *endp = p + <span class="keyword">sizeof</span>(<a class="code" href="dtncat_8c.html#5287cc892023d51088dd91a9b78de7c5">payload_buf</a>); <a name="l00582"></a>00582 <span class="keywordtype">size_t</span> n, total = 0; <a name="l00583"></a>00583 <span class="keywordtype">size_t</span> maxread = <span class="keyword">sizeof</span>(buf); <a name="l00584"></a>00584 <a name="l00585"></a>00585 <span class="keywordflow">while</span> (1) { <a name="l00586"></a>00586 maxread = <a class="code" href="APIServer_8cc.html#74e75242132eaabbc1c512488a135926">MIN</a>((<span class="keywordtype">int</span>)<span class="keyword">sizeof</span>(buf), (endp-p)); <a name="l00587"></a>00587 <span class="keywordflow">if</span> ((n = fread(buf, 1, maxread, stdin)) == 0) <a name="l00588"></a>00588 <span class="keywordflow">break</span>; <a name="l00589"></a>00589 memcpy(p, buf, n); <a name="l00590"></a>00590 p += n; <a name="l00591"></a>00591 total += n; <a name="l00592"></a>00592 } <a name="l00593"></a>00593 <span class="keywordflow">if</span> (ferror(stdin)) <a name="l00594"></a>00594 <span class="keywordflow">return</span> (-1); <a name="l00595"></a>00595 <a name="l00596"></a>00596 <span class="keywordflow">if</span> (<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>(payload, <a class="code" href="dtn__types_8h.html#3dcfddc1b850a71a18d8a0868f67e7628f773bbfb80857bd5a11f09665fa9b03">DTN_PAYLOAD_MEM</a>, <a class="code" href="dtncat_8c.html#5287cc892023d51088dd91a9b78de7c5">payload_buf</a>, total) == <a class="code" href="dtn__errno_8h.html#dfbc45377fa7c17b849e79a015975a79">DTN_ESIZE</a>) <a name="l00597"></a>00597 <span class="keywordflow">return</span> (-1); <a name="l00598"></a>00598 <span class="keywordflow">return</span>(total); <a name="l00599"></a>00599 } <a name="l00600"></a>00600 <a name="l00601"></a>00601 <span class="keywordtype">void</span> <a name="l00602"></a><a class="code" href="dtncat_8c.html#5f3182fedba4dab2c150f77dbd997df1">00602</a> <a class="code" href="dtncat_8c.html#5f3182fedba4dab2c150f77dbd997df1">make_registration</a>(<a class="code" href="structdtn__reg__info__t.html" title="Registration state.">dtn_reg_info_t</a>* reginfo) <a name="l00603"></a>00603 { <a name="l00604"></a>00604 <span class="keywordtype">int</span> ret; <a name="l00605"></a>00605 <a name="l00606"></a>00606 <span class="comment">// try to find an existing registration to use (unless we're</span> <a name="l00607"></a>00607 <span class="comment">// using session flags, in which case we always create a new</span> <a name="l00608"></a>00608 <span class="comment">// registration)</span> <a name="l00609"></a>00609 <span class="keywordflow">if</span> (<a class="code" href="dtncat_8c.html#7508c434c1f2152c7fd03381726d0a2a">session_flags</a> == 0) { <a name="l00610"></a>00610 ret = <a class="code" href="dtn__api_8c.html#add060907ae0beceeebb75ac61a8f552" title="Check for an existing registration on the given endpoint id, returning DTN_SUCCSS...">dtn_find_registration</a>(<a class="code" href="dtncat_8c.html#01daea96255bb21a8979b3b45f5bbb70">handle</a>, &reginfo-><a class="code" href="structdtn__reg__info__t.html#07df1822e2808b2127710a8b54acd07f">endpoint</a>, &<a class="code" href="dtncat_8c.html#8eb0c3e35c1feb7baf9802f03bf42e41">regid</a>); <a name="l00611"></a>00611 <a name="l00612"></a>00612 <span class="keywordflow">if</span> (ret == 0) { <a name="l00613"></a>00613 <a name="l00614"></a>00614 <span class="comment">// found the registration, bind it to the handle</span> <a name="l00615"></a>00615 <span class="keywordflow">if</span> (<a class="code" href="dtn__api_8c.html#ab949d76f4c34a202aea5bac853b310b" title="Associate a registration with the current ipc channel.">dtn_bind</a>(<a class="code" href="dtncat_8c.html#01daea96255bb21a8979b3b45f5bbb70">handle</a>, <a class="code" href="dtncat_8c.html#8eb0c3e35c1feb7baf9802f03bf42e41">regid</a>) != <a class="code" href="dtn__errno_8h.html#3723251cb5d056b6ace3e22561da1e11" title="DTN API error codes.">DTN_SUCCESS</a>) { <a name="l00616"></a>00616 fprintf(stderr, <span class="stringliteral">"%s: error in bind (id=0x%x): %d (%s)\n"</span>, <a name="l00617"></a>00617 <a class="code" href="dtncat_8c.html#b9e1449fd00c98428516f0b41eddcb10">progname</a>, <a class="code" href="dtncat_8c.html#8eb0c3e35c1feb7baf9802f03bf42e41">regid</a>, 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>(<a class="code" href="dtncat_8c.html#01daea96255bb21a8979b3b45f5bbb70">handle</a>))); <a name="l00618"></a>00618 exit(EXIT_FAILURE); <a name="l00619"></a>00619 } <a name="l00620"></a>00620 <a name="l00621"></a>00621 <span class="keywordflow">return</span>; <a name="l00622"></a>00622 <a name="l00623"></a>00623 } <span class="keywordflow">else</span> <span class="keywordflow">if</span> (<a class="code" href="dtn__api_8c.html#6183d81d5f742d13e1fdee26423d94b4" title="Get the error associated with the given handle.">dtn_errno</a>(<a class="code" href="dtncat_8c.html#01daea96255bb21a8979b3b45f5bbb70">handle</a>) == <a class="code" href="dtn__errno_8h.html#58a067b3ff3eba74fc55d6d7e7866d5a">DTN_ENOTFOUND</a>) { <a name="l00624"></a>00624 <span class="comment">// fall through</span> <a name="l00625"></a>00625 <a name="l00626"></a>00626 } <span class="keywordflow">else</span> { <a name="l00627"></a>00627 fprintf(stderr, <span class="stringliteral">"%s: error in dtn_find_registration: %d (%s)\n"</span>, <a name="l00628"></a>00628 <a class="code" href="dtncat_8c.html#b9e1449fd00c98428516f0b41eddcb10">progname</a>, 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>(<a class="code" href="dtncat_8c.html#01daea96255bb21a8979b3b45f5bbb70">handle</a>))); <a name="l00629"></a>00629 exit(EXIT_FAILURE); <a name="l00630"></a>00630 } <a name="l00631"></a>00631 } <a name="l00632"></a>00632 <a name="l00633"></a>00633 <span class="comment">// create a new dtn registration to receive bundles</span> <a name="l00634"></a>00634 <span class="keywordflow">if</span> ((ret = <a class="code" href="dtn__api_8c.html#7384bf592d4aff0892ff948aafa98b0c" title="Create a dtn registration.">dtn_register</a>(<a class="code" href="dtncat_8c.html#01daea96255bb21a8979b3b45f5bbb70">handle</a>, reginfo, &<a class="code" href="dtncat_8c.html#8eb0c3e35c1feb7baf9802f03bf42e41">regid</a>)) != 0) { <a name="l00635"></a>00635 fprintf(stderr, <span class="stringliteral">"%s: error creating registration (id=0x%x): %d (%s)\n"</span>, <a name="l00636"></a>00636 <a class="code" href="dtncat_8c.html#b9e1449fd00c98428516f0b41eddcb10">progname</a>, <a class="code" href="dtncat_8c.html#8eb0c3e35c1feb7baf9802f03bf42e41">regid</a>, 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>(<a class="code" href="dtncat_8c.html#01daea96255bb21a8979b3b45f5bbb70">handle</a>))); <a name="l00637"></a>00637 exit(EXIT_FAILURE); <a name="l00638"></a>00638 } <a name="l00639"></a>00639 <a name="l00640"></a>00640 <span class="keywordflow">if</span> (<a class="code" href="dtncat_8c.html#0b2caeb4b6f130be43e5a2f0267dd453">verbose</a>) <a name="l00641"></a>00641 fprintf(<a class="code" href="dtncat_8c.html#71f51a2e8cbe9a53031fa72596edc09f">info</a>, <span class="stringliteral">"dtn_register succeeded, regid 0x%x\n"</span>, <a class="code" href="dtncat_8c.html#8eb0c3e35c1feb7baf9802f03bf42e41">regid</a>); <a name="l00642"></a>00642 } </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>