summaryrefslogtreecommitdiff
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/net/wellenreiter/libwellenreiter/docs/quickintro35
-rw-r--r--noncore/net/wellenreiter/libwellenreiter/source/Makefile17
-rw-r--r--noncore/net/wellenreiter/libwellenreiter/source/log.cc51
-rw-r--r--noncore/net/wellenreiter/libwellenreiter/source/log.hh14
-rw-r--r--noncore/net/wellenreiter/libwellenreiter/source/sock.cc73
-rw-r--r--noncore/net/wellenreiter/libwellenreiter/source/sock.hh19
6 files changed, 209 insertions, 0 deletions
diff --git a/noncore/net/wellenreiter/libwellenreiter/docs/quickintro b/noncore/net/wellenreiter/libwellenreiter/docs/quickintro
new file mode 100644
index 0000000..e4978a1
--- a/dev/null
+++ b/noncore/net/wellenreiter/libwellenreiter/docs/quickintro
@@ -0,0 +1,35 @@
1
2Name: libwellenreiter
3Author: Martin J. Muench
4
5NOTE: This is just a very short summary of the functions included
6in libwellenreiter, written because a lack of time. The whole
7library will be rewritten with extended documentation and
8test programs.
9
10Included functions:
11
12Log to syslog/info:
13void wl_loginfo(const char *, ...);
14
15Log to syslog/err:
16void wl_logerr(const char *, ...);
17
18Use like printf() function with format strings and so on.
19
20
21Setup udp socket for incoming commands:
22int commsock(const char *, int);
23
24Fist argument is the host where it should listen and second
25is the port.
26
27Return values:
28
29Send command to udp socket:
30int sendcomm(const char *, int, const char *, ...);
31
32First two arguments are the host and port where the command should
33be send to, followed by buffer that should be send.
34
35Thats it for the moment.
diff --git a/noncore/net/wellenreiter/libwellenreiter/source/Makefile b/noncore/net/wellenreiter/libwellenreiter/source/Makefile
new file mode 100644
index 0000000..05a5bd3
--- a/dev/null
+++ b/noncore/net/wellenreiter/libwellenreiter/source/Makefile
@@ -0,0 +1,17 @@
1# $Id$
2
3INCLUDES =
4LIBRARIES =
5LIBOBJ = sock.o log.o
6CXX = g++ -Wall -pedantic -g $(INCLUDES) -DDEBUG
7
8 static:libwellenreiter.a
9libwellenreiter.a: $(LIBOBJ)
10 ar -cr libwellenreiter.a $(LIBOBJ)
11
12 shared:libwellenreiter.so
13libwellenreiter.so: $(LIBOBJ)
14 $(CXX) -shared -o libwellenreiter.so $(LIBOBJ)
15
16clean:
17 rm -f *.o *.a *.so *~
diff --git a/noncore/net/wellenreiter/libwellenreiter/source/log.cc b/noncore/net/wellenreiter/libwellenreiter/source/log.cc
new file mode 100644
index 0000000..af7f909
--- a/dev/null
+++ b/noncore/net/wellenreiter/libwellenreiter/source/log.cc
@@ -0,0 +1,51 @@
1/*
2 * Small functions to log to syslog
3 *
4 * $Id$
5 */
6
7#include "log.hh"
8
9/* Log to syslog INFO */
10void wl_loginfo(const char *fmt,...)
11{
12
13 char buffer[4096];
14 va_list ap;
15
16 memset(buffer, 0, sizeof(buffer));
17 va_start(ap, fmt);
18 vsnprintf(buffer, sizeof(buffer)-1, fmt, ap);
19 va_end(ap);
20
21 openlog("libwellenreiter", LOG_PID, LOG_SYSLOG);
22 syslog(LOG_INFO, "(info) %s", buffer);
23 closelog();
24
25#ifdef DEBUG
26 fprintf(stderr, "(info) %s\n", buffer);
27#endif
28
29}
30
31/* Log to syslog ERR */
32void wl_logerr(const char *fmt,...)
33{
34
35 char buffer[4096];
36 va_list ap;
37
38 memset(buffer, 0, sizeof(buffer));
39 va_start(ap, fmt);
40 vsnprintf(buffer, sizeof(buffer)-1, fmt, ap);
41 va_end(ap);
42
43 openlog("libwellenreiter", LOG_PID, LOG_SYSLOG);
44 syslog(LOG_INFO, "(err) %s", buffer);
45 closelog();
46
47#ifdef DEBUG
48 fprintf(stderr, "(err) %s\n", buffer);
49#endif
50
51}
diff --git a/noncore/net/wellenreiter/libwellenreiter/source/log.hh b/noncore/net/wellenreiter/libwellenreiter/source/log.hh
new file mode 100644
index 0000000..8f6e543
--- a/dev/null
+++ b/noncore/net/wellenreiter/libwellenreiter/source/log.hh
@@ -0,0 +1,14 @@
1/* $Id$ */
2
3#ifndef WLLOG_HH
4#define WLLOG_HH
5
6#include <stdio.h>
7#include <syslog.h>
8#include <stdarg.h>
9#include <string.h>
10
11void wl_loginfo(const char *, ...);
12void wl_logerr(const char *, ...);
13
14#endif /* WLLOG_HH */
diff --git a/noncore/net/wellenreiter/libwellenreiter/source/sock.cc b/noncore/net/wellenreiter/libwellenreiter/source/sock.cc
new file mode 100644
index 0000000..2cc16eb
--- a/dev/null
+++ b/noncore/net/wellenreiter/libwellenreiter/source/sock.cc
@@ -0,0 +1,73 @@
1/*
2 * Socket operations for wellenreiter
3 *
4 * $Id$
5 */
6
7#include "sock.hh"
8#include "log.hh"
9
10/* Setup UDP Socket for incoming commands */
11int commsock(const char *host, int port)
12{
13 struct sockaddr_in saddr;
14 int sock;
15
16 if((sock=socket(AF_INET, SOCK_DGRAM, 0)) < 0)
17 {
18 wl_logerr("Cannot set up socket: %s", strerror(errno));
19 return -1;
20 }
21
22 memset(&saddr, 0, sizeof(saddr));
23 saddr.sin_family = PF_INET;
24 saddr.sin_port = htons(port);
25 saddr.sin_addr.s_addr = inet_addr(host);
26
27 if(bind(sock,(struct sockaddr *)&saddr, sizeof(saddr)) < 0)
28 {
29 wl_logerr("Cannot bind socket: %s", strerror(errno));
30 close(sock);
31 return -1;
32 }
33
34 return sock;
35}
36
37/* Send a string to commsock */
38int sendcomm(const char *host, int port, const char *string, ...)
39{
40 int sock;
41 char buffer[4096];
42 struct sockaddr_in saddr;
43 va_list ap;
44
45 /* Generate string */
46 memset(buffer, 0, sizeof(buffer));
47 va_start(ap, string);
48 vsnprintf(buffer, sizeof(buffer)-1, string, ap);
49 va_end(ap);
50
51 /* Setup socket */
52 if((sock=socket(AF_INET, SOCK_DGRAM, 0)) < 0)
53 {
54 wl_logerr("Cannot set up socket: %s", strerror(errno));
55 return -1;
56 }
57
58 saddr.sin_family = AF_INET;
59 saddr.sin_port = htons(port);
60 saddr.sin_addr.s_addr = inet_addr(host);
61
62 if(sendto(sock, buffer, sizeof(buffer), 0, (struct sockaddr *)&saddr, sizeof(saddr)) < 0)
63 {
64 wl_logerr("Cannot write to socket: %s", strerror(errno));
65 close(sock);
66 return 0;
67 }
68
69 if(close(sock) < 0)
70 wl_logerr("Cannot close socket: %s", strerror(errno));
71
72 return 1;
73}
diff --git a/noncore/net/wellenreiter/libwellenreiter/source/sock.hh b/noncore/net/wellenreiter/libwellenreiter/source/sock.hh
new file mode 100644
index 0000000..afde641
--- a/dev/null
+++ b/noncore/net/wellenreiter/libwellenreiter/source/sock.hh
@@ -0,0 +1,19 @@
1/* $id */
2
3#ifndef WLSOCK_HH
4#define WLSOCK_HH
5
6#include <sys/types.h>
7#include <sys/socket.h>
8#include <netinet/in.h>
9#include <arpa/inet.h>
10#include <signal.h>
11#include <string.h>
12#include <unistd.h>
13#include <stdlib.h>
14#include <errno.h>
15
16int commsock(const char *, int);
17int sendcomm(const char *, int, const char *, ...);
18
19#endif /* WLSOCK_HH */