24 #include <ibrcommon/net/socket.h>
25 #include <ibrcommon/net/socketstream.h>
26 #include <ibrcommon/thread/Mutex.h>
27 #include <ibrcommon/thread/MutexLock.h>
28 #include <ibrcommon/thread/SignalHandler.h>
29 #include <ibrcommon/Logger.h>
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;
51 ibrcommon::socketstream *
_conn = NULL;
60 std::cout <<
h <<
" bundles received." << std::endl;
73 int main(
int argc,
char *argv[])
76 const unsigned char logopts = ibrcommon::Logger::LOG_DATETIME | ibrcommon::Logger::LOG_LEVEL;
79 unsigned char loglevel = 0;
82 ibrcommon::SignalHandler sighandler(
term);
83 sighandler.handle(SIGINT);
84 sighandler.handle(SIGTERM);
85 sighandler.initialize();
87 int ret = EXIT_SUCCESS;
89 string name =
"filetransfer";
93 ibrcommon::File unixdomain;
95 for (
int i = 0; i < argc; ++i)
100 if (arg ==
"-h" || arg ==
"--help")
106 if (arg ==
"--logging")
108 loglevel |= ibrcommon::Logger::LOGGER_ALL ^ ibrcommon::Logger::LOGGER_DEBUG;
111 if (arg ==
"--debug")
113 loglevel |= ibrcommon::Logger::LOGGER_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;
150 unixdomain = ibrcommon::File(argv[i]);
157 ibrcommon::Logger::addStream(std::cerr, loglevel, logopts);
162 ibrcommon::clientsocket *sock = NULL;
165 if (unixdomain.exists())
168 sock =
new ibrcommon::filesocket(unixdomain);
173 ibrcommon::vaddress addr(
"localhost", 4550);
174 sock =
new ibrcommon::tcpsocket(addr);
177 ibrcommon::socketstream conn(sock);
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;
218 file << ref.iostream()->rdbuf();
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;
ibrcommon::socketstream * _conn
dtn::api::Client * _client
dtn::data::Bundle getBundle(const dtn::data::Timeout timeout=0)
int main(int argc, char *argv[])
iterator find(block_t blocktype)