aboutsummaryrefslogtreecommitdiff
path: root/OSC
diff options
context:
space:
mode:
Diffstat (limited to 'OSC')
-rw-r--r--OSC/dumpOSC.c20
-rw-r--r--OSC/htmsocket.c27
-rw-r--r--OSC/makefile2
3 files changed, 29 insertions, 20 deletions
diff --git a/OSC/dumpOSC.c b/OSC/dumpOSC.c
index 3af5027..1d82a2c 100644
--- a/OSC/dumpOSC.c
+++ b/OSC/dumpOSC.c
@@ -64,11 +64,12 @@ Technologies, University of California, Berkeley.
*/
#include "m_pd.h"
+#include "s_stuff.h"
//#include "x_osc.h"
/* declarations */
-typedef void (*t_fdpollfn)(void *ptr, int fd);
+// typedef void (*t_fdpollfn)(void *ptr, int fd);
void sys_addpollfn(int fd, t_fdpollfn fn, void *ptr);
@@ -201,7 +202,7 @@ static void dumpOSC_read(t_dumpOSC *x, int sockfd) {
#ifdef WIN32
if ((n = recvfrom(sockfd, mbuf, MAXMESG, 0, (SOCKADDR*)&x->x_server, &clilen)) >0)
#else
- if ((n = recvfrom(sockfd, mbuf, MAXMESG, 0, &x->x_server, &clilen)) >0)
+ if ((n = recvfrom(sockfd, mbuf, MAXMESG, 0, (struct sockaddr *)&x->x_server, &clilen)) >0)
#endif
{
//int r;
@@ -241,13 +242,12 @@ static void *dumpOSC_new(t_symbol *compatflag,
//x->x_outatc = 0; {{raf}}
/* create a socket */
- sockfd = socket(AF_INET, (udp ? SOCK_DGRAM : SOCK_STREAM), 0);
-
- if (sockfd < 0)
+ if ((sockfd = socket(AF_INET, (udp ? SOCK_DGRAM : SOCK_STREAM), 0)) == -1)
{
sys_sockerror("socket");
return (0);
}
+
server.sin_family = AF_INET;
server.sin_addr.s_addr = INADDR_ANY;
/* assign server port number */
@@ -265,15 +265,9 @@ static void *dumpOSC_new(t_symbol *compatflag,
x->x_msgout = outlet_new(&x->x_obj, &s_anything);
- if (udp) /* datagram protocol */
+ // if (udp) /* datagram protocol */
{
-/* t_socketreceiver *y = socketreceiver_new((void *)x, */
-/* 0, */
-/* (x->x_msgout ? dumpOSC_doit : 0)); */
-
- // sys_addpollfn(sockfd, (t_fdpollfn)socketreceiver_read_x, y);
-
sys_addpollfn(sockfd, (t_fdpollfn)dumpOSC_read, x);
x->x_connectout = 0;
}
@@ -481,7 +475,7 @@ void PrintClientAddr(ClientAddr CA) {
printf(" clilen %d, sockfd %d\n", CA->clilen, CA->sockfd);
printf(" sin_family %d, sin_port %d\n", CA->cl_addr.sin_family,
CA->cl_addr.sin_port);
- printf(" address: (%x) %s\n", addr, inet_ntoa(CA->cl_addr.sin_addr));
+ printf(" address: (%x) %s\n", addr, inet_ntoa(CA->cl_addr.sin_addr));
printf(" sin_zero = \"%c%c%c%c%c%c%c%c\"\n",
CA->cl_addr.sin_zero[0],
diff --git a/OSC/htmsocket.c b/OSC/htmsocket.c
index 9666ebe..cba230e 100644
--- a/OSC/htmsocket.c
+++ b/OSC/htmsocket.c
@@ -121,6 +121,7 @@ void *OpenHTMSocket(char *host, int portnumber)
o = malloc(sizeof(*o));
if(!o)
return 0;
+ int oval = 1;
#ifndef WIN32
@@ -162,14 +163,14 @@ void *OpenHTMSocket(char *host, int portnumber)
if (bind(sockfd, (struct sockaddr *) &ucl_addr, clilen) < 0)
{
- perror("client: can't bind local address");
- close(sockfd);
- sockfd = -1;
+ perror("client: can't bind local address");
+ close(sockfd);
+ sockfd = -1;
}
}
else
- perror("unable to make socket\n");
-
+ perror("unable to make socket\n");
+
}else
#endif
@@ -228,6 +229,11 @@ void *OpenHTMSocket(char *host, int portnumber)
cl_addr.sin_addr.s_addr = htonl(INADDR_ANY);
cl_addr.sin_port = htons(0);
+ // enable broadcast
+ if(setsockopt(sockfd, SOL_SOCKET, SO_BROADCAST, &oval, sizeof(int)) == -1) {
+ perror("setsockopt");
+ }
+
if(bind(sockfd, (struct sockaddr *) &cl_addr, sizeof(cl_addr)) < 0) {
perror("could not bind\n");
closesocket(sockfd);
@@ -244,6 +250,11 @@ void *OpenHTMSocket(char *host, int portnumber)
cl_addr.sin_addr.s_addr = htonl(INADDR_ANY);
cl_addr.sin_port = htons(0);
+ // enable broadcast
+ if(setsockopt(sockfd, SOL_SOCKET, SO_BROADCAST, &oval, sizeof(int)) == -1) {
+ perror("setsockopt");
+ }
+
if(bind(sockfd, (struct sockaddr *) &cl_addr, sizeof(cl_addr)) < 0) {
perror("could not bind\n");
close(sockfd);
@@ -293,7 +304,11 @@ void CloseHTMSocket(void *htmsendhandle)
return;
}
#else
- close(o->sockfd);
+ if(close(o->sockfd) == -1)
+ {
+ perror("CloseHTMSocket::closesocket failed");
+ return;
+ }
#endif
free(o);
diff --git a/OSC/makefile b/OSC/makefile
index 346be68..9c554d0 100644
--- a/OSC/makefile
+++ b/OSC/makefile
@@ -44,7 +44,7 @@ LINUXCFLAGS = -DPD -DUNIX -O2 -funroll-loops -fomit-frame-pointer \
-Wno-unused -Wno-parentheses -Wno-switch
# where is your m_pd.h ???
-LINUXINCLUDE = -I../../../src/pd-0.35-0/src
+LINUXINCLUDE = -I../../../pd-0.37-test4/src
LINUXEXTERNALS = htmsocket.o OSC-pattern-match.o sendOSC.o dumpOSC.o routeOSC.o