31 #include <sys/types.h>
36 cout <<
"-- dtnrecv (IBR-DTN) --" << endl;
37 cout <<
"Syntax: dtnrecv [options]" << endl;
38 cout <<
"* optional parameters *" << endl;
39 cout <<
" -h|--help display this text" << endl;
40 cout <<
" --file <filename> write the incoming data to the a file instead of the standard output" << endl;
41 cout <<
" --name <name> set the application name (e.g. filetransfer)" << endl;
42 cout <<
" --timeout <seconds> receive timeout in seconds" << endl;
43 cout <<
" --count <number> receive that many bundles" << endl;
44 cout <<
" --group <group> join a group" << endl;
45 cout <<
" -U <socket> use UNIX domain sockets" << endl;
58 std::cout <<
h <<
" bundles received." << std::endl;
71 int main(
int argc,
char *argv[])
77 unsigned char loglevel = 0;
81 signal(SIGTERM,
term);
83 int ret = EXIT_SUCCESS;
85 string name =
"filetransfer";
91 for (
int i = 0; i < argc; ++i)
96 if (arg ==
"-h" || arg ==
"--help")
102 if (arg ==
"--logging")
107 if (arg ==
"--debug")
112 if (arg ==
"--name" && argc > i)
117 if (arg ==
"--file" && argc > i)
119 filename = argv[i + 1];
123 if (arg ==
"--timeout" && argc > i)
125 timeout = atoi(argv[i + 1]);
128 if (arg ==
"--group" && argc > i)
130 group = std::string(argv[i + 1]);
133 if (arg ==
"--count" && argc > i)
135 count = atoi(argv[i + 1]);
138 if (arg ==
"-U" && argc > i)
142 std::cout <<
"argument missing!" << std::endl;
190 std::cout <<
"Wait for incoming bundle... " << std::endl;
191 file.open(filename.c_str(), ios::in|ios::out|ios::binary|ios::trunc);
192 file.exceptions(std::ios::badbit | std::ios::eofbit);
195 for(
h = 0;
h < count; ++
h)
206 std::cout << ref.
iostream()->rdbuf() << std::flush;
212 std::cout <<
"Bundle received (" << (
h + 1) <<
")." << endl;
215 }
catch (
const ios_base::failure&) {
224 std::cout <<
"done." << std::endl;
233 std::cerr <<
"Timeout." << std::endl;
236 std::cerr <<
"Aborted." << std::endl;
239 }
catch (
const std::exception &ex) {
240 std::cerr <<
"Error: " << ex.what() << std::endl;