From 3705dc02cc18b79c77d8f5aba934e02c7a91467f Mon Sep 17 00:00:00 2001 From: Benjamin Franzke Date: Sat, 9 Mar 2013 06:30:21 +0100 Subject: Add util mostly for socket-based tasks --- util.h | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 util.h (limited to 'util.h') diff --git a/util.h b/util.h new file mode 100644 index 0000000..4d0e27d --- /dev/null +++ b/util.h @@ -0,0 +1,28 @@ +#ifndef _UTIL_H_ +#define _UTIL_H_ + +#include + +#define MAX(a, b) (((a) > (b)) ? (a) : (b)) +#define ARRAY_SIZE(arr) (sizeof (arr) / sizeof ((arr)[0])) + +#define STR_EXPAND(tok) #tok +#define STR(str) STR_EXPAND(str) + +uint32_t +sock_get_ipv4_addr(int fd); +uint32_t +sock_get_peer_ipv4_addr(int fd); +uint32_t +sock_get_netmask(int fd); + +void +set_ip(uint8_t *ipbuf, uint32_t ip); +int +bind_socket(int socktype, const char *host, const char *port); +int +connect_to_host(int socktype, const char *host, const char *port); +ssize_t +loop_read(int fd, void *buf, size_t nbytes, uint8_t do_poll); + +#endif /* _UTIL_H_ */ -- cgit