aboutsummaryrefslogtreecommitdiffstats
path: root/libglouglou/libglouglou.c
diff options
context:
space:
mode:
authorLaurent Ghigonis <laurent@p1sec.com>2012-12-02 19:41:08 +0100
committerLaurent Ghigonis <laurent@p1sec.com>2012-12-02 19:41:08 +0100
commit49ed06bd05ca0998e0028e2c654282c4c3214cf3 (patch)
treebd9a55a570c1c8cac1787018f6977837a2a98c37 /libglouglou/libglouglou.c
parentadd some evdns spikes (diff)
downloadglouglou-49ed06bd05ca0998e0028e2c654282c4c3214cf3.tar.xz
glouglou-49ed06bd05ca0998e0028e2c654282c4c3214cf3.zip
source cleanup and utils improvements
* move utils functions to utils.c * add log functions * use an ifndef for the whole libglouglou.h for multiple inclusion * move gg_packet_props to libglougloud.c and set it as extern in libglouglou.h
Diffstat (limited to 'libglouglou/libglouglou.c')
-rw-r--r--libglouglou/libglouglou.c74
1 files changed, 18 insertions, 56 deletions
diff --git a/libglouglou/libglouglou.c b/libglouglou/libglouglou.c
index 0b0ab48..1ec8916 100644
--- a/libglouglou/libglouglou.c
+++ b/libglouglou/libglouglou.c
@@ -17,7 +17,7 @@
#define error(fmt, ...) \
if (_verbosity >= 0) \
- printf("libgg: %s: ERROR: " fmt "\n", __func__, ##__VA_ARGS__)
+ printf("libgg: %s: ERROR: " fmt "\n", __func__, ##__VA_ARGS__)
#define verbose(fmt, ...) \
if (_verbosity >= 1) \
printf("libgg: %s: " fmt "\n", __func__, ##__VA_ARGS__)
@@ -41,6 +41,23 @@ int pkt_encode(struct gg_packet *, struct gg_packet *);
int _verbosity = 0;
+gg_packet_props_t gg_packet_props[] = {
+ [PACKET_NEWCONN] = \
+ { (PACKET_HEADER_SIZE + sizeof((struct gg_packet *)0)->pdat.newconn) },
+ [PACKET_DELCONN] = \
+ { (PACKET_HEADER_SIZE + sizeof((struct gg_packet *)0)->pdat.delconn) },
+ [PACKET_DATA] = \
+ { (PACKET_HEADER_SIZE + sizeof((struct gg_packet *)0)->pdat.data) },
+ [PACKET_NAME] = \
+ { ((PACKET_HEADER_SIZE + sizeof((struct gg_packet *)0)->pdat.name) - GG_PKTARG_MAX) },
+ [PACKET_FORK] = \
+ { (PACKET_HEADER_SIZE + sizeof((struct gg_packet *)0)->pdat.fork) },
+ [PACKET_EXEC] = \
+ { ((PACKET_HEADER_SIZE + sizeof((struct gg_packet *)0)->pdat.exec) - GG_PKTARG_MAX) },
+ [PACKET_EXIT] = \
+ { (PACKET_HEADER_SIZE + sizeof((struct gg_packet *)0)->pdat.exit) },
+};
+
/*
* Server
*/
@@ -702,58 +719,3 @@ gg_verbosity_set(int verb)
{
_verbosity = verb;
}
-
-/*
- * Utils
- */
-
-void *
-xmalloc(size_t size)
-{
- void *data;
-
- data = malloc(size);
- if (!data)
- err(1, "could not malloc %d", (int)size);
- return data;
-}
-
-void *
-xcalloc(size_t nmemb, size_t size)
-{
- void *data;
-
- data = calloc(nmemb, size);
- if (!data)
- err(1, "could not calloc %d", (int)size);
- return data;
-}
-
-void
-fd_nonblock(int fd)
-{
- int flags = fcntl(fd, F_GETFL, 0);
- int rc = fcntl(fd, F_SETFL, flags | O_NONBLOCK);
- if (rc == -1)
- error("failed to set fd %i non-blocking", fd);
-}
-
-void
-addrcpy(struct sockaddr_in *dst, struct sockaddr_in *src)
-{
- dst->sin_addr.s_addr = src->sin_addr.s_addr;
- dst->sin_port = src->sin_port;
- dst->sin_family = src->sin_family;
-}
-
-int
-addrcmp(struct sockaddr_in *a, struct sockaddr_in *b)
-{
- if (a->sin_addr.s_addr != b->sin_addr.s_addr)
- return -1;
- if (a->sin_port != b->sin_port)
- return -2;
- if (a->sin_family != b->sin_family)
- return -3;
- return 0;
-}