aboutsummaryrefslogtreecommitdiffhomepage
path: root/backends/libmmbackend.c
diff options
context:
space:
mode:
authorcbdev <cb@cbcdn.com>2019-12-22 13:19:37 +0100
committercbdev <cb@cbcdn.com>2019-12-22 13:19:37 +0100
commita305f5d9b2794315fb536dbe4d4949f1cf26aeea (patch)
tree1e9180b69347396a0f71e2ca1fb3488c16a01c45 /backends/libmmbackend.c
parentb5d5f26835ea8840fc3aedd38780f3025d2959b3 (diff)
parent172d8a210f7df36a26b01d2fe018ff4c959a6987 (diff)
downloadmidimonster-a305f5d9b2794315fb536dbe4d4949f1cf26aeea.tar.gz
midimonster-a305f5d9b2794315fb536dbe4d4949f1cf26aeea.tar.bz2
midimonster-a305f5d9b2794315fb536dbe4d4949f1cf26aeea.zip
Merge branch 'master' into rtpmidi
Diffstat (limited to 'backends/libmmbackend.c')
-rw-r--r--backends/libmmbackend.c33
1 files changed, 24 insertions, 9 deletions
diff --git a/backends/libmmbackend.c b/backends/libmmbackend.c
index ccbeb52..ffa403b 100644
--- a/backends/libmmbackend.c
+++ b/backends/libmmbackend.c
@@ -1,6 +1,8 @@
#include "libmmbackend.h"
-void mmbackend_parse_hostspec(char* spec, char** host, char** port){
+#define LOGPF(format, ...) fprintf(stderr, "libmmbe\t" format "\n", __VA_ARGS__)
+
+void mmbackend_parse_hostspec(char* spec, char** host, char** port, char** options){
size_t u = 0;
if(!spec || !host || !port){
@@ -29,6 +31,19 @@ void mmbackend_parse_hostspec(char* spec, char** host, char** port){
spec[u] = 0;
*port = spec + u + 1;
}
+
+ if(options){
+ *options = NULL;
+ if(*port){
+ //scan for space after port
+ for(u = 0; (*port)[u] && !isspace((*port)[u]); u++){
+ }
+ if(isspace((*port)[u])){
+ (*port)[u] = 0;
+ *options = (*port) + u + 1;
+ }
+ }
+ }
}
int mmbackend_parse_sockaddr(char* host, char* port, struct sockaddr_storage* addr, socklen_t* len){
@@ -39,7 +54,7 @@ int mmbackend_parse_sockaddr(char* host, char* port, struct sockaddr_storage* ad
int error = getaddrinfo(host, port, &hints, &head);
if(error || !head){
- fprintf(stderr, "Failed to parse address %s port %s: %s\n", host, port, gai_strerror(error));
+ LOGPF("Failed to parse address %s port %s: %s", host, port, gai_strerror(error));
return 1;
}
@@ -63,7 +78,7 @@ int mmbackend_socket(char* host, char* port, int socktype, uint8_t listener, uin
status = getaddrinfo(host, port, &hints, &info);
if(status){
- fprintf(stderr, "Failed to parse address %s port %s: %s\n", host, port, gai_strerror(status));
+ LOGPF("Failed to parse address %s port %s: %s", host, port, gai_strerror(status));
return -1;
}
@@ -77,18 +92,18 @@ int mmbackend_socket(char* host, char* port, int socktype, uint8_t listener, uin
//set required socket options
yes = 1;
if(setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, (void*)&yes, sizeof(yes)) < 0){
- fprintf(stderr, "Failed to enable SO_REUSEADDR on socket\n");
+ LOGPF("Failed to enable SO_REUSEADDR on socket: %s", strerror(errno));
}
if(mcast){
yes = 1;
if(setsockopt(fd, SOL_SOCKET, SO_BROADCAST, (void*)&yes, sizeof(yes)) < 0){
- fprintf(stderr, "Failed to enable SO_BROADCAST on socket\n");
+ LOGPF("Failed to enable SO_BROADCAST on socket: %s", strerror(errno));
}
yes = 0;
if(setsockopt(fd, IPPROTO_IP, IP_MULTICAST_LOOP, (void*)&yes, sizeof(yes)) < 0){
- fprintf(stderr, "Failed to disable IP_MULTICAST_LOOP on socket: %s\n", strerror(errno));
+ LOGPF("Failed to disable IP_MULTICAST_LOOP on socket: %s", strerror(errno));
}
}
@@ -112,7 +127,7 @@ int mmbackend_socket(char* host, char* port, int socktype, uint8_t listener, uin
freeaddrinfo(info);
if(!addr_it){
- fprintf(stderr, "Failed to create socket for %s port %s\n", host, port);
+ LOGPF("Failed to create socket for %s port %s", host, port);
return -1;
}
@@ -126,7 +141,7 @@ int mmbackend_socket(char* host, char* port, int socktype, uint8_t listener, uin
#else
int flags = fcntl(fd, F_GETFL, 0);
if(fcntl(fd, F_SETFL, flags | O_NONBLOCK) < 0){
- fprintf(stderr, "Failed to set socket nonblocking\n");
+ LOGPF("Failed to set socket nonblocking: %s", strerror(errno));
close(fd);
return -1;
}
@@ -140,7 +155,7 @@ int mmbackend_send(int fd, uint8_t* data, size_t length){
while(total < length){
sent = send(fd, data + total, length - total, 0);
if(sent < 0){
- fprintf(stderr, "Failed to send: %s\n", strerror(errno));
+ LOGPF("Failed to send: %s", strerror(errno));
return 1;
}
total += sent;