aboutsummaryrefslogtreecommitdiffhomepage
path: root/backends/libmmbackend.h
blob: 31c4b9681944343a873714dd0a8eaa4cd76b8b47 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#include <stdint.h>
#include <stdlib.h>
#include <sys/types.h>
#ifdef _WIN32
#include <ws2tcpip.h>
//#define close closesocket
#else
#include <sys/socket.h>
#include <netdb.h>
#endif
#include <ctype.h>
#include <stdio.h>
#include <string.h>
#include <errno.h>
#include <unistd.h>
#include <fcntl.h>
#include "../portability.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, uint8_t mcast);

/*
 * Send arbitrary data over multiple writes if necessary
 * Returns 1 on failure, 0 on success.
 */
int mmbackend_send(int fd, uint8_t* data, size_t length);

/*
 * Wraps mmbackend_send for cstrings
 */
int mmbackend_send_str(int fd, char* data);