aboutsummaryrefslogtreecommitdiff
path: root/net
diff options
context:
space:
mode:
Diffstat (limited to 'net')
-rw-r--r--net/udpreceive-help.pd91
-rw-r--r--net/udpreceive.c50
-rw-r--r--net/udpsend-help.pd18
-rw-r--r--net/udpsend.c39
4 files changed, 73 insertions, 125 deletions
diff --git a/net/udpreceive-help.pd b/net/udpreceive-help.pd
index cc5eb31..745beec 100644
--- a/net/udpreceive-help.pd
+++ b/net/udpreceive-help.pd
@@ -1,68 +1,43 @@
-#N canvas 340 455 880 401 12;
-#X floatatom 387 305 3 0 0 0 - - -;
-#X floatatom 414 305 3 0 0 0 - - -;
-#X floatatom 441 305 3 0 0 0 - - -;
-#X floatatom 468 305 3 0 0 0 - - -;
-#X obj 171 161 udpreceive 9997;
-#X floatatom 495 306 5 0 0 0 - - -;
-#X obj 387 279 unpack 0 0 0 0 0;
-#X msg 161 131 status;
-#X obj 750 246 print xxxx;
-#X floatatom 273 226 9 0 0 0 - - -;
-#X floatatom 648 247 7 0 0 0 - - -;
-#X text 466 361 Martin Peach 2010/07/13;
-#X obj 445 219 route multicast multicast_loop multicast_ttl;
-#X obj 445 252 tgl 15 0 empty empty empty 17 7 0 10 -4034 -1 -1 0 1
+#N canvas 238 505 742 371 12;
+#X floatatom 394 264 3 0 0 0 - - -;
+#X floatatom 421 264 3 0 0 0 - - -;
+#X floatatom 448 264 3 0 0 0 - - -;
+#X floatatom 475 264 3 0 0 0 - - -;
+#X obj 171 120 udpreceive 9997;
+#X floatatom 502 265 5 0 0 0 - - -;
+#X obj 394 238 unpack 0 0 0 0 0;
+#X msg 171 90 status;
+#X floatatom 273 185 9 0 0 0 - - -;
+#X obj 454 211 tgl 15 0 empty empty empty 17 7 0 10 -4034 -1 -1 0 1
;
-#X obj 546 252 tgl 15 0 empty empty empty 17 7 0 10 -4034 -1 -1 0 1
-;
-#X floatatom 330 252 9 0 0 0 - - -;
-#X obj 273 193 route received total from;
-#X text 423 107 IP address to accept from (optional);
-#X msg 90 60 ttl \$1;
-#X floatatom 108 11 5 0 256 0 - - -;
-#X obj 135 85 tgl 15 0 empty empty empty 17 7 0 10 -4034 -1 -1 0 1
-;
-#X msg 135 105 loop \$1;
-#X obj 90 34 f 1;
-#X obj 90 14 bng 15 250 50 0 empty empty empty 17 7 0 10 -4034 -1 -1
-;
-#X text -39 62 set multicast ttl:;
-#X text -40 106 set multicast loopback:;
-#X text -40 131 get status on right outlet:;
-#X text 166 226 bytes received:;
-#X text 179 252 total bytes received:;
-#X text 344 304 from:;
-#X text 421 128 Specify a multicast address (from 224.0.0.0 to 239.255.255.255)
+#X floatatom 333 211 9 0 0 0 - - -;
+#X text 301 76 IP address to accept from (optional);
+#X text -30 90 get status on right outlet:;
+#X text 166 185 bytes received:;
+#X text 181 209 total bytes received:;
+#X text 351 263 from:;
+#X text 299 97 Specify a multicast address (from 224.0.0.0 to 239.255.255.255)
to use multicasting;
-#X text 284 88 Creation arguments: port number to listen on (required)
+#X text 162 57 Creation arguments: port number to listen on (required)
;
-#X text 246 64 [udpreceive] receives bytes over a udp connection.;
-#X obj 171 295 spigot;
-#X obj 210 275 tgl 15 0 empty empty enable_print: -77 8 0 10 -4034
+#X text 124 33 [udpreceive] receives bytes over a udp connection.;
+#X obj 171 254 spigot;
+#X obj 210 234 tgl 15 0 empty empty enable_print: -77 8 0 10 -4034
-1 -1 0 1;
-#X obj 171 320 print received;
-#X connect 4 0 33 0;
-#X connect 4 1 16 0;
+#X obj 171 279 print received;
+#X obj 273 152 route received total from multicast;
+#X text 466 320 Martin Peach 2010/08/02;
+#X connect 4 0 19 0;
+#X connect 4 1 22 0;
#X connect 6 0 0 0;
#X connect 6 1 1 0;
#X connect 6 2 2 0;
#X connect 6 3 3 0;
#X connect 6 4 5 0;
#X connect 7 0 4 0;
-#X connect 12 0 13 0;
-#X connect 12 1 14 0;
-#X connect 12 2 10 0;
-#X connect 12 3 8 0;
-#X connect 16 0 9 0;
-#X connect 16 1 15 0;
-#X connect 16 2 6 0;
-#X connect 16 3 12 0;
-#X connect 18 0 4 0;
-#X connect 19 0 22 1;
-#X connect 20 0 21 0;
-#X connect 21 0 4 0;
-#X connect 22 0 18 0;
-#X connect 23 0 22 0;
-#X connect 33 0 35 0;
-#X connect 34 0 33 1;
+#X connect 19 0 21 0;
+#X connect 20 0 19 1;
+#X connect 22 0 8 0;
+#X connect 22 1 10 0;
+#X connect 22 2 6 0;
+#X connect 22 3 9 0;
diff --git a/net/udpreceive.c b/net/udpreceive.c
index 5517001..3a0886a 100644
--- a/net/udpreceive.c
+++ b/net/udpreceive.c
@@ -33,8 +33,6 @@ typedef struct _udpreceive
t_outlet *x_addrout;
int x_connectsocket;
int x_multicast_joined;
- unsigned int x_multicast_loop_state;
- unsigned int x_multicast_ttl;
long x_total_received;
t_atom x_addrbytes[5];
t_atom x_msgoutbuf[MAX_UDP_RECEIVE];
@@ -45,8 +43,6 @@ void udpreceive_setup(void);
static void udpreceive_free(t_udpreceive *x);
static void *udpreceive_new(t_symbol *s, int argc, t_atom *argv);
static void udpreceive_status(t_udpreceive *x);
-static void udpreceive_set_multicast_ttl(t_udpreceive *x, t_floatarg ttl_hops);
-static void udpreceive_set_multicast_loop(t_udpreceive *x, t_floatarg loop_state);
static void udpreceive_read(t_udpreceive *x, int sockfd);
static void udpreceive_read(t_udpreceive *x, int sockfd)
@@ -108,9 +104,6 @@ static void *udpreceive_new(t_symbol *s, int argc, t_atom *argv)
#endif
int sockfd, portno = 0;
int multicast_joined = 0;
- unsigned char multicast_loop_state;
- unsigned char multicast_ttl;
- unsigned int size;
int intarg, i;
char addr[256] = {'\0'};
@@ -185,10 +178,6 @@ static void *udpreceive_new(t_symbol *s, int argc, t_atom *argv)
{
multicast_joined = 1;
post ("udpreceive: added to multicast group");
- multicast_loop_state = 0;
- if (setsockopt(sockfd, IPPROTO_IP, IP_MULTICAST_LOOP,
- &multicast_loop_state, sizeof(multicast_loop_state)) < 0)
- error("udpreceive: setsockopt (IP_MULTICAST_LOOP) failed");
}
}
@@ -219,13 +208,7 @@ static void *udpreceive_new(t_symbol *s, int argc, t_atom *argv)
x->x_addrbytes[i].a_type = A_FLOAT;
x->x_addrbytes[i].a_w.w_float = 0;
}
- getsockopt(sockfd, IPPROTO_IP, IP_MULTICAST_LOOP, &multicast_loop_state, &size);
- //post("udpreceive: multicast loop state is %d", multicast_loop_state);
- getsockopt(sockfd, IPPROTO_IP, IP_MULTICAST_TTL, &multicast_ttl, &size);
- //post("udpreceive: multicast time to live is %d hop%s", multicast_ttl, (multicast_ttl == 1)?"":"s");
x->x_multicast_joined = multicast_joined;
- x->x_multicast_loop_state = multicast_loop_state;
- x->x_multicast_ttl = multicast_ttl;
x->x_total_received = 0L;
sys_addpollfn(x->x_connectsocket, (t_fdpollfn)udpreceive_read, x);
return (x);
@@ -237,41 +220,10 @@ static void udpreceive_status(t_udpreceive *x)
SETFLOAT(&output_atom, x->x_multicast_joined);
outlet_anything( x->x_addrout, gensym("multicast"), 1, &output_atom);
- SETFLOAT(&output_atom, x->x_multicast_loop_state);
- outlet_anything( x->x_addrout, gensym("multicast_loop"), 1, &output_atom);
- SETFLOAT(&output_atom, x->x_multicast_ttl);
- outlet_anything( x->x_addrout, gensym("multicast_ttl"), 1, &output_atom);
SETFLOAT(&output_atom, x->x_total_received);
outlet_anything( x->x_addrout, gensym("total"), 1, &output_atom);
}
-static void udpreceive_set_multicast_ttl(t_udpreceive *x, t_floatarg ttl_hops)
-{
- int sockfd = x->x_connectsocket;
- unsigned char multicast_ttl = ttl_hops;
- unsigned int size;
-
- if (setsockopt(sockfd, IPPROTO_IP, IP_MULTICAST_TTL,
- &multicast_ttl, sizeof(multicast_ttl)) < 0)
- error("udpreceive: setsockopt (IP_MULTICAST_LOOP) failed");
- getsockopt(sockfd, IPPROTO_IP, IP_MULTICAST_TTL, &multicast_ttl, &size);
- x->x_multicast_ttl = multicast_ttl;
-}
-
-static void udpreceive_set_multicast_loop(t_udpreceive *x, t_floatarg loop_state)
-{
- int sockfd = x->x_connectsocket;
- unsigned char multicast_loop_state = loop_state;
- unsigned int size;
-
-
- if (setsockopt(sockfd, IPPROTO_IP, IP_MULTICAST_LOOP,
- &multicast_loop_state, sizeof(multicast_loop_state)) < 0)
- error("udpreceive: setsockopt (IP_MULTICAST_LOOP) failed");
- getsockopt(sockfd, IPPROTO_IP, IP_MULTICAST_LOOP, &multicast_loop_state, &size);
- x->x_multicast_loop_state = multicast_loop_state;
-}
-
static void udpreceive_free(t_udpreceive *x)
{
if (x->x_connectsocket >= 0)
@@ -288,8 +240,6 @@ void udpreceive_setup(void)
sizeof(t_udpreceive), CLASS_DEFAULT, A_GIMME, 0);
class_addmethod(udpreceive_class, (t_method)udpreceive_status,
gensym("status"), 0);
- class_addmethod(udpreceive_class, (t_method)udpreceive_set_multicast_ttl, gensym("ttl"), A_DEFFLOAT, 0);
- class_addmethod(udpreceive_class, (t_method)udpreceive_set_multicast_loop, gensym("loop"), A_DEFFLOAT, 0);
}
/* end udpreceive.c */
diff --git a/net/udpsend-help.pd b/net/udpsend-help.pd
index f26795a..41b38a0 100644
--- a/net/udpsend-help.pd
+++ b/net/udpsend-help.pd
@@ -1,13 +1,13 @@
#N canvas 355 70 898 550 12;
#X msg 198 118 disconnect;
#X msg 17 -63 connect 127.0.0.1 9997;
-#X obj 405 368 tgl 15 0 empty empty connected 20 7 0 8 -24198 -241291
--1 1 1;
+#X obj 455 418 tgl 15 0 empty empty connected 20 7 0 8 -24198 -241291
+-1 0 1;
#X msg 39 -41 send 0 1 2 3;
-#X text 100 345 udpsend sends bytes over a udp connection.;
-#X text 177 395 Used in conjunction with packOSC will send OSC over
+#X text 150 395 udpsend sends bytes over a udp connection.;
+#X text 227 445 Used in conjunction with packOSC will send OSC over
udp;
-#X obj 405 345 udpsend;
+#X obj 455 395 udpsend;
#X msg 61 -19 send ../doc/5.reference/test.txt;
#X obj 131 27 openpanel;
#X msg 131 51 send \$1;
@@ -34,7 +34,11 @@ udp;
-1;
#X text 240 270 set multicast ttl:;
#X msg 375 295 multicast_ttl \$1;
-#X text 595 358 Martin Peach 2010/08/02;
+#X text 645 408 Martin Peach 2010/08/02;
+#X msg 425 345 multicast_loopback \$1;
+#X obj 425 323 tgl 15 0 empty empty empty 20 7 0 8 -24198 -241291 -1
+0 1;
+#X text 236 321 enable multicast loopback:;
#X connect 0 0 6 0;
#X connect 1 0 6 0;
#X connect 3 0 6 0;
@@ -52,3 +56,5 @@ udp;
#X connect 26 0 29 0;
#X connect 27 0 26 0;
#X connect 29 0 6 0;
+#X connect 31 0 6 0;
+#X connect 32 0 31 0;
diff --git a/net/udpsend.c b/net/udpsend.c
index 33d2d04..114c02c 100644
--- a/net/udpsend.c
+++ b/net/udpsend.c
@@ -29,6 +29,7 @@ typedef struct _udpsend
{
t_object x_obj;
int x_fd; /* the socket */
+ unsigned int x_multicast_loop_state;
unsigned int x_multicast_ttl; /* time to live for multicast */
} t_udpsend;
@@ -37,6 +38,7 @@ static void udpsend_free(t_udpsend *x);
static void udpsend_send(t_udpsend *x, t_symbol *s, int argc, t_atom *argv);
static void udpsend_disconnect(t_udpsend *x);
static void udpsend_connect(t_udpsend *x, t_symbol *hostname, t_floatarg fportno);
+static void udpsend_set_multicast_loopback(t_udpsend *x, t_floatarg loop_state);
static void udpsend_set_multicast_ttl(t_udpsend *x, t_floatarg ttl_hops);
static void udpsend_set_multicast_interface (t_udpsend *x, t_symbol *s, int argc, t_atom *argv);
static void *udpsend_new(void);
@@ -57,6 +59,9 @@ static void udpsend_connect(t_udpsend *x, t_symbol *hostname,
int sockfd;
int portno = fportno;
int broadcast = 1;/* nonzero is true */
+ unsigned char multicast_loop_state;
+ unsigned char multicast_ttl;
+ unsigned int size;
if (x->x_fd >= 0)
{
@@ -95,6 +100,10 @@ Enable sending of broadcast messages (if hostname is a broadcast address)*/
if (0xE0000000 == (ntohl(server.sin_addr.s_addr) & 0xF0000000))
post ("udpsend: connecting to a multicast address");
+ getsockopt(sockfd, IPPROTO_IP, IP_MULTICAST_LOOP, &multicast_loop_state, &size);
+ getsockopt(sockfd, IPPROTO_IP, IP_MULTICAST_TTL, &multicast_ttl, &size);
+ x->x_multicast_loop_state = multicast_loop_state;
+ x->x_multicast_ttl = multicast_ttl;
/* assign client port number */
server.sin_port = htons((u_short)portno);
@@ -110,6 +119,19 @@ Enable sending of broadcast messages (if hostname is a broadcast address)*/
outlet_float(x->x_obj.ob_outlet, 1);
}
+static void udpsend_set_multicast_loopback(t_udpsend *x, t_floatarg loop_state)
+{
+ int sockfd = x->x_fd;
+ unsigned char multicast_loop_state = loop_state;
+ unsigned int size;
+
+ if (setsockopt(sockfd, IPPROTO_IP, IP_MULTICAST_LOOP,
+ &multicast_loop_state, sizeof(multicast_loop_state)) < 0)
+ error("udpreceive: setsockopt (IP_MULTICAST_LOOP) failed");
+ getsockopt(sockfd, IPPROTO_IP, IP_MULTICAST_LOOP, &multicast_loop_state, &size);
+ x->x_multicast_loop_state = multicast_loop_state;
+}
+
static void udpsend_set_multicast_ttl(t_udpsend *x, t_floatarg ttl_hops)
{
int sockfd = x->x_fd;
@@ -343,18 +365,13 @@ static void udpsend_free(t_udpsend *x)
void udpsend_setup(void)
{
- udpsend_class = class_new(gensym("udpsend"), (t_newmethod)udpsend_new,
- (t_method)udpsend_free,
- sizeof(t_udpsend), 0, 0);
- class_addmethod(udpsend_class, (t_method)udpsend_connect,
- gensym("connect"), A_SYMBOL, A_FLOAT, 0);
+ udpsend_class = class_new(gensym("udpsend"), (t_newmethod)udpsend_new, (t_method)udpsend_free, sizeof(t_udpsend), 0, 0);
+ class_addmethod(udpsend_class, (t_method)udpsend_connect, gensym("connect"), A_SYMBOL, A_FLOAT, 0);
class_addmethod(udpsend_class, (t_method)udpsend_set_multicast_ttl, gensym("multicast_ttl"), A_DEFFLOAT, 0);
- class_addmethod(udpsend_class, (t_method)udpsend_set_multicast_interface,
- gensym("multicast_interface"), A_GIMME, 0);
- class_addmethod(udpsend_class, (t_method)udpsend_disconnect,
- gensym("disconnect"), 0);
- class_addmethod(udpsend_class, (t_method)udpsend_send, gensym("send"),
- A_GIMME, 0);
+ class_addmethod(udpsend_class, (t_method)udpsend_set_multicast_loopback, gensym("multicast_loopback"), A_DEFFLOAT, 0);
+ class_addmethod(udpsend_class, (t_method)udpsend_set_multicast_interface, gensym("multicast_interface"), A_GIMME, 0);
+ class_addmethod(udpsend_class, (t_method)udpsend_disconnect, gensym("disconnect"), 0);
+ class_addmethod(udpsend_class, (t_method)udpsend_send, gensym("send"), A_GIMME, 0);
class_addlist(udpsend_class, (t_method)udpsend_send);
}