aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--net/udpreceive-help.pd108
-rw-r--r--net/udpreceive.c31
2 files changed, 97 insertions, 42 deletions
diff --git a/net/udpreceive-help.pd b/net/udpreceive-help.pd
index 30de47c..cc5eb31 100644
--- a/net/udpreceive-help.pd
+++ b/net/udpreceive-help.pd
@@ -1,44 +1,68 @@
-#N canvas 501 474 729 401 12;
-#X floatatom 223 255 3 0 0 0 - - -;
-#X floatatom 250 255 3 0 0 0 - - -;
-#X floatatom 277 255 3 0 0 0 - - -;
-#X floatatom 304 255 3 0 0 0 - - -;
-#X text 180 254 from;
-#X obj 7 143 print message;
-#X obj 7 111 udpreceive 9997;
-#X text 46 16 udpreceive receives bytes over a udp connection.;
-#X floatatom 331 256 5 0 0 0 - - -;
-#X obj 223 229 unpack 0 0 0 0 0;
-#X msg 7 83 status;
-#X obj 586 196 print xxxx;
-#X floatatom 109 176 9 0 0 0 - - -;
-#X floatatom 484 197 7 0 0 0 - - -;
-#X text 302 311 Martin Peach 2010/07/13;
-#X obj 281 169 route multicast multicast_loop multicast_ttl;
-#X obj 281 202 tgl 15 0 empty empty empty 17 7 0 10 -262144 -1 -1 0
-1;
-#X obj 382 202 tgl 15 0 empty empty empty 17 7 0 10 -262144 -1 -1 1
-1;
-#X floatatom 166 202 9 0 0 0 - - -;
-#X obj 109 143 route received total from;
-#X text 84 40 creation arguments: port number to listen on (required)
+#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
;
-#X text 223 59 IP address to accept from (optional);
-#X text 221 80 specify a multicast address (from 224.0.0.0 to 239.255.255.255)
+#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)
to use multicasting;
-#X connect 6 0 5 0;
-#X connect 6 1 19 0;
-#X connect 9 0 0 0;
-#X connect 9 1 1 0;
-#X connect 9 2 2 0;
-#X connect 9 3 3 0;
-#X connect 9 4 8 0;
-#X connect 10 0 6 0;
-#X connect 15 0 16 0;
-#X connect 15 1 17 0;
-#X connect 15 2 13 0;
-#X connect 15 3 11 0;
-#X connect 19 0 12 0;
-#X connect 19 1 18 0;
-#X connect 19 2 9 0;
-#X connect 19 3 15 0;
+#X text 284 88 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
+-1 -1 0 1;
+#X obj 171 320 print received;
+#X connect 4 0 33 0;
+#X connect 4 1 16 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;
diff --git a/net/udpreceive.c b/net/udpreceive.c
index a6b5985..4dc4a74 100644
--- a/net/udpreceive.c
+++ b/net/udpreceive.c
@@ -45,6 +45,8 @@ 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)
@@ -234,6 +236,33 @@ static void udpreceive_status(t_udpreceive *x)
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 int 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 int 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)
@@ -250,6 +279,8 @@ 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 */