aboutsummaryrefslogtreecommitdiffhomepage
path: root/backends/libmmbackend.h
diff options
context:
space:
mode:
authorcbdev <cb@cbcdn.com>2019-03-24 19:22:30 +0100
committercbdev <cb@cbcdn.com>2019-03-24 19:22:30 +0100
commit1ed17293bedaf5bf5182d863cd406d7eb66b4501 (patch)
treec62b03610f95fa8340dfa245c31f0d2072452b42 /backends/libmmbackend.h
parentfa8f005a6c97480a671146c483cf1183d5f1b083 (diff)
downloadmidimonster-1ed17293bedaf5bf5182d863cd406d7eb66b4501.tar.gz
midimonster-1ed17293bedaf5bf5182d863cd406d7eb66b4501.tar.bz2
midimonster-1ed17293bedaf5bf5182d863cd406d7eb66b4501.zip
Factor out socket operations (Fixes #13)
Diffstat (limited to 'backends/libmmbackend.h')
-rw-r--r--backends/libmmbackend.h31
1 files changed, 31 insertions, 0 deletions
diff --git a/backends/libmmbackend.h b/backends/libmmbackend.h
new file mode 100644
index 0000000..38bfca0
--- /dev/null
+++ b/backends/libmmbackend.h
@@ -0,0 +1,31 @@
+#include <stdint.h>
+#include <stdlib.h>
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <netdb.h>
+#include <ctype.h>
+#include <stdio.h>
+#include <string.h>
+#include <errno.h>
+#include <unistd.h>
+#include <fcntl.h>
+
+/* Parse spec as host specification in the form
+ * host port
+ * into its constituent parts.
+ * Returns offsets into the original string and modifies it.
+ * Returns NULL in *port if none given.
+ * Returns NULL in both *port and *host if spec was an empty string.
+ */
+void mmbackend_parse_hostspec(char* spec, char** host, char** port);
+
+/* Parse a given host / port combination into a sockaddr_storage
+ * suitable for usage with connect / sendto
+ * Returns 0 on success
+ */
+int mmbackend_parse_sockaddr(char* host, char* port, struct sockaddr_storage* addr, socklen_t* len);
+
+/* Create a socket of given type and mode for a bind / connect host.
+ * Returns -1 on failure, a valid file descriptor for the socket on success.
+ */
+int mmbackend_socket(char* host, char* port, int socktype, uint8_t listener);