From: Stefan Bund Date: Wed, 26 May 2010 12:55:33 +0000 (+0200) Subject: Add udp output functionality X-Git-Url: http://g0dil.de/git?a=commitdiff_plain;h=2ac6d37e0265027490bfd25136b3d3d518c8295e;p=udpcat.git Add udp output functionality --- diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..359d685 --- /dev/null +++ b/.gitignore @@ -0,0 +1,6 @@ +/.sconf_temp/ +/.sconsign.dblite +/senf +/config.log +/udpcat +*.o diff --git a/SConstruct b/SConstruct index e5bd45e..c547429 100644 --- a/SConstruct +++ b/SConstruct @@ -1,34 +1,20 @@ -import sys -sys.path.extend(('senf/senfscons','/usr/lib/senf/senfscons')) -try: - import os.path, glob, senfutil -except ImportError: - print "\nModule import failed. 'senf' symlink missing?\n" - raise +# -*- python -*- +import sys, os, os.path +try: sys.path.append(((_ for _ in (os.path.join(os.path.sep.join(('..' for _ in range(_))),d, + 'site_scons') for d in ('','senf','Senf') for _ in range(len(os.getcwd().split('/')))) + if os.path.exists(_))).next()) +except: pass +import senfutil env = Environment() -senfutil.SetupForSENF( env ) - -env.Append( - - LIBS = [ ], - CXXFLAGS = [ '-Wall', '-Woverloaded-virtual' ], - LINKFLAGS = [ ], - - CXXFLAGS_debug = [ ], - LINKFLAGS_debug = [ ], - LOGLEVELS_debug = [ 'senf::log::Debug||VERBOSE' ], - - CXXFLAGS_final = [ '-O3' ], - LINKFLAGS_final = [ ], - LOGLEVELS_final = [ ], - - SENF_BUILDOPTS = [ ], - -) +senfutil.SetupForSENF(env) +senfutil.DefaultOptions(env) env.Default( env.Program( target = 'udpcat', - source = glob.glob('*.cc') ) + source = env.Glob('*.cc') ) ) + +env.Alias('all', '.') +env.Clean(['.', 'all'], [ '.sconf_temp', 'config.log', '.sconsign.dblite' ]) diff --git a/udpcat.cc b/udpcat.cc index 0b9d85c..84279fe 100644 --- a/udpcat.cc +++ b/udpcat.cc @@ -1,4 +1,4 @@ -// $Id$ +// $Id: udpcat.cc 56 2009-05-13 13:33:24Z g0dil $ // // Copyright (C) 2009 // Fraunhofer Institute for Open Communication Systems (FOKUS) @@ -33,15 +33,40 @@ #define prefix_ ///////////////////////////////cc.p//////////////////////////////////////// -int main(int argc, char ** argv) +void udpIn(senf::INet4SocketAddress addr) { - senf::UDPv4ClientSocketHandle handle ( - senf::INet4SocketAddress(boost::lexical_cast(std::string(argv[1])))); - + senf::UDPv4ClientSocketHandle handle (addr); for (;;) std::cout << handle.read() << std::flush; } +void udpOut(senf::INet4SocketAddress addr) +{ + senf::UDPv4ClientSocketHandle handle; + std::string line; + while (getline(std::cin, line)) { + line += "\n"; + handle.writeto(addr, line); + } +} + +int main(int argc, char ** argv) +{ + switch (argc) { + case 2: + udpIn(senf::INet4SocketAddress(boost::lexical_cast(std::string(argv[1])))); + break; + case 3: + udpOut(senf::INet4SocketAddress(senf::INet4Address::from_string(argv[1]), + boost::lexical_cast(std::string(argv[2])))); + break; + default: + std::cerr << "Usage:\n" " udpcat ip port\n" " udpcat port\n" << std::flush; + break; + } + return 1; +} + ///////////////////////////////cc.e//////////////////////////////////////// #undef prefix_ //#include "udpcat.mpp"