26 #include <sys/types.h>
39 #include <sys/socket.h>
47 #define MSG_NOSIGNAL 0
55 #define geterror() WSAGetLastError()
57 #define geterror() errno
66 const char *file,
int line);
75 const char *path,
const char *types, ...)
83 const char *file =
"";
98 if (ret == -1) t->errstr =
"unknown type";
99 else t->errstr =
"bad format/args";
116 const char *path,
const char *types, ...)
119 const char *path,
const char *types, ...)
129 const char *file =
"";
158 const char *path,
const char *types, ...)
161 const char *path,
const char *types, ...)
169 const char *file =
"";
207 This (incomplete) function converts from printf-style formats to OSC typetags,
208 but I think its dangerous and mislieading so its not available
at the moment.
210 static
char *format_to_types(const
char *format);
212 static
char *format_to_types(const
char *format)
215 char *types = malloc(
sizeof(format) + 1);
225 for (ptr = format; *ptr; ptr++) {
229 }
else if (*ptr >=
'0' && *ptr <=
'9') {
231 number += *ptr -
'0';
232 }
else if (*ptr ==
'd') {
233 if (width < 2 && number < 64) {
238 }
else if (*ptr ==
'f') {
239 if (width < 2 && number < 64) {
244 }
else if (*ptr ==
'%') {
245 fprintf(stderr,
"liblo warning, unexpected '%%' in format\n");
250 fprintf(stderr,
"liblo warning, unrecognised character '%c' "
251 "in format\n", *ptr);
262 fprintf(stderr,
"liblo warning, unrecognised character '%c' "
263 "in format\n", *ptr);
281 struct addrinfo hints;
283 memset(&hints, 0,
sizeof(hints));
285 hints.ai_family = PF_UNSPEC;
287 hints.ai_family = PF_INET;
289 hints.ai_socktype = a->protocol ==
LO_UDP ? SOCK_DGRAM : SOCK_STREAM;
291 if ((ret = getaddrinfo(a->host, a->port, &hints, &ai))) {
293 a->errstr = gai_strerror(ret);
308 a->socket = socket(a->ai->ai_family, a->ai->ai_socktype, 0);
309 if (a->socket == -1) {
315 if (a->protocol ==
LO_TCP) {
317 if ((connect(a->socket, a->ai->ai_addr, a->ai->ai_addrlen))) {
327 else if (a->protocol ==
LO_UDP && a->ai->ai_family == AF_INET)
331 struct sockaddr_in* si = (
struct sockaddr_in*)a->ai->ai_addr;
332 unsigned char* ip = (
unsigned char*)&(si->sin_addr);
334 if (ip[0]==255 && ip[1]==255 && ip[2]==255 && ip[3]==255)
337 setsockopt(a->socket, SOL_SOCKET, SO_BROADCAST, &opt,
sizeof(
int));
343 else if (a->protocol ==
LO_UNIX) {
344 struct sockaddr_un sa;
346 a->socket = socket(PF_UNIX, SOCK_DGRAM, 0);
347 if (a->socket == -1) {
353 sa.sun_family = AF_UNIX;
354 strncpy(sa.sun_path, a->port,
sizeof(sa.sun_path)-1);
356 if ((connect(a->socket, (
struct sockaddr *)&sa,
sizeof(sa))) < 0) {
379 if(!initWSock())
return -1;
384 a->errstr =
"Attempted to send message in excess of maximum "
397 sock = from->sockets[0].fd;
411 if (a->protocol ==
LO_TCP) {
412 int32_t size = htonl(data_len);
417 if (a->protocol ==
LO_UDP) {
419 unsigned char ttl = (
unsigned char)a->ttl;
420 setsockopt(sock,IPPROTO_IP,IP_MULTICAST_TTL,&ttl,
sizeof(ttl));
423 a->ai->ai_addr, a->ai->ai_addrlen);
428 if (a->protocol ==
LO_TCP && ret == -1) {
456 int ret =
send_data( a, from, data, data_len );
461 if (ret == -1 && a->protocol ==
LO_TCP)
462 ret =
send_data( a, from, data, data_len );
465 if (data) free( data );
483 int ret =
send_data( a, from, data, data_len );
486 if (data) free( data );