31 #include <sys/types.h>
36 cout <<
"-- dtnrecv (IBR-DTN) --" << endl;
37 cout <<
"Syntax: dtnrecv [options]" << endl << endl;
38 cout <<
"* optional parameters *" << endl;
39 cout <<
" -h|--help Display this text" << endl;
40 cout <<
" --file <path> Write the incoming data to the a file instead of the" << endl;
41 cout <<
" standard output" << endl;
42 cout <<
" --name <name> Set the application name (e.g. filetransfer)" << endl;
43 cout <<
" --timeout <seconds>" << endl;
44 cout <<
" Receive timeout in seconds" << endl;
45 cout <<
" --count <n> Receive that many bundles" << endl;
46 cout <<
" --group <group> Join a group" << endl;
47 cout <<
" -U <socket> Connect to UNIX domain socket API" << endl;
60 std::cout <<
h <<
" bundles received." << std::endl;
73 int main(
int argc,
char *argv[])
79 unsigned char loglevel = 0;
84 sighandler.
handle(SIGTERM);
87 int ret = EXIT_SUCCESS;
89 string name =
"filetransfer";
95 for (
int i = 0; i < argc; ++i)
100 if (arg ==
"-h" || arg ==
"--help")
106 if (arg ==
"--logging")
111 if (arg ==
"--debug")
116 if (arg ==
"--name" && argc > i)
121 if (arg ==
"--file" && argc > i)
123 filename = argv[i + 1];
127 if (arg ==
"--timeout" && argc > i)
129 timeout = atoi(argv[i + 1]);
132 if (arg ==
"--group" && argc > i)
134 group = std::string(argv[i + 1]);
137 if (arg ==
"--count" && argc > i)
139 count = atoi(argv[i + 1]);
142 if (arg ==
"-U" && argc > i)
146 std::cout <<
"argument missing!" << std::endl;
194 std::cout <<
"Wait for incoming bundle... " << std::endl;
195 file.open(filename.c_str(), ios::in|ios::out|ios::binary|ios::trunc);
196 file.exceptions(std::ios::badbit | std::ios::eofbit);
199 for(
h = 0;
h < count; ++
h)
210 std::cout << ref.
iostream()->rdbuf() << std::flush;
216 std::cout <<
"Bundle received (" << (
h + 1) <<
")." << endl;
219 }
catch (
const ios_base::failure&) {
228 std::cout <<
"done." << std::endl;
237 std::cerr <<
"Timeout." << std::endl;
240 std::cerr <<
"Aborted." << std::endl;
243 }
catch (
const std::exception &ex) {
244 std::cerr <<
"Error: " << ex.what() << std::endl;