Add udp output functionality
Stefan Bund [Wed, 26 May 2010 12:55:33 +0000 (14:55 +0200)]
.gitignore [new file with mode: 0644]
SConstruct
udpcat.cc

diff --git a/.gitignore b/.gitignore
new file mode 100644 (file)
index 0000000..359d685
--- /dev/null
@@ -0,0 +1,6 @@
+/.sconf_temp/
+/.sconsign.dblite
+/senf
+/config.log
+/udpcat
+*.o
index e5bd45e..c547429 100644 (file)
@@ -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' ])
index 0b9d85c..84279fe 100644 (file)
--- 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)
 #define prefix_
 ///////////////////////////////cc.p////////////////////////////////////////
 
-int main(int argc, char ** argv)
+void udpIn(senf::INet4SocketAddress addr)
 {
-    senf::UDPv4ClientSocketHandle handle (
-        senf::INet4SocketAddress(boost::lexical_cast<unsigned>(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<unsigned>(std::string(argv[1]))));
+        break;
+    case 3:
+        udpOut(senf::INet4SocketAddress(senf::INet4Address::from_string(argv[1]),
+                                        boost::lexical_cast<unsigned>(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"