aboutsummaryrefslogtreecommitdiff
path: root/net
diff options
context:
space:
mode:
Diffstat (limited to 'net')
-rw-r--r--net/udpsend-help.pd60
-rw-r--r--net/udpsend.c20
2 files changed, 53 insertions, 27 deletions
diff --git a/net/udpsend-help.pd b/net/udpsend-help.pd
index 7401fa5..f26795a 100644
--- a/net/udpsend-help.pd
+++ b/net/udpsend-help.pd
@@ -1,34 +1,40 @@
-#N canvas 304 215 898 550 12;
-#X msg 268 188 disconnect;
-#X msg 87 7 connect 127.0.0.1 9997;
+#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 0 1;
-#X msg 109 29 send 0 1 2 3;
+-1 1 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
udp;
#X obj 405 345 udpsend;
-#X msg 131 51 send ../doc/5.reference/test.txt;
-#X obj 201 97 openpanel;
-#X msg 201 121 send \$1;
-#X obj 201 78 bng 15 250 50 0 empty empty empty 17 7 0 10 -24198 -241291
+#X msg 61 -19 send ../doc/5.reference/test.txt;
+#X obj 131 27 openpanel;
+#X msg 131 51 send \$1;
+#X obj 131 8 bng 15 250 50 0 empty empty empty 17 7 0 10 -24198 -241291
-1;
-#X text 42 52 send a file;
-#X text 207 28 send raw data;
-#X text 221 77 ...any file;
-#X msg 234 154 99 98 97;
-#X text 299 154 'send' prefix is optional;
-#X msg 371 291 multicast_interface 192.168.0.88;
-#X msg 346 266 multicast_interface eth1;
-#X msg 298 218 connect 239.200.200.200 9977;
-#X text 595 358 Martin Peach 2010/07/30;
-#X text 251 6 <--first connect to a host and port;
-#X text 349 187 <--disconnect before connecting to another address
+#X text -28 -18 send a file;
+#X text 137 -42 send raw data;
+#X text 151 7 ...any file;
+#X msg 164 84 99 98 97;
+#X text 229 84 'send' prefix is optional;
+#X msg 301 221 multicast_interface 192.168.0.88;
+#X msg 276 196 multicast_interface eth1;
+#X msg 228 148 connect 239.200.200.200 9977;
+#X text 181 -64 <--first connect to a host and port;
+#X text 279 117 <--disconnect before connecting to another address
;
-#X text 509 217 send to a multicast address;
-#X text 481 242 specify an interface to use with multicast;
-#X msg 323 243 multicast_interface 1;
-#X text 531 265 by index \, name or address;
+#X text 439 147 send to a multicast address;
+#X text 411 172 specify an interface to use with multicast;
+#X msg 253 173 multicast_interface 1;
+#X text 461 195 by index \, name or address;
+#X floatatom 393 246 5 0 256 0 - - -;
+#X obj 375 269 f 1;
+#X obj 375 249 bng 15 250 50 0 empty empty empty 17 7 0 10 -4034 -1
+-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 connect 0 0 6 0;
#X connect 1 0 6 0;
#X connect 3 0 6 0;
@@ -41,4 +47,8 @@ udp;
#X connect 16 0 6 0;
#X connect 17 0 6 0;
#X connect 18 0 6 0;
-#X connect 24 0 6 0;
+#X connect 23 0 6 0;
+#X connect 25 0 26 1;
+#X connect 26 0 29 0;
+#X connect 27 0 26 0;
+#X connect 29 0 6 0;
diff --git a/net/udpsend.c b/net/udpsend.c
index e4117c2..33d2d04 100644
--- a/net/udpsend.c
+++ b/net/udpsend.c
@@ -27,8 +27,9 @@ static t_class *udpsend_class;
typedef struct _udpsend
{
- t_object x_obj;
- int x_fd;
+ t_object x_obj;
+ int x_fd; /* the socket */
+ unsigned int x_multicast_ttl; /* time to live for multicast */
} t_udpsend;
void udpsend_setup(void);
@@ -36,6 +37,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_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);
@@ -108,6 +110,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_ttl(t_udpsend *x, t_floatarg ttl_hops)
+{
+ int sockfd = x->x_fd;
+ unsigned char multicast_ttl = ttl_hops;
+ unsigned int size;
+
+ if (setsockopt(sockfd, IPPROTO_IP, IP_MULTICAST_TTL,
+ &multicast_ttl, sizeof(multicast_ttl)) < 0)
+ error("udpsend: setsockopt (IP_MULTICAST_LOOP) failed");
+ getsockopt(sockfd, IPPROTO_IP, IP_MULTICAST_TTL, &multicast_ttl, &size);
+ x->x_multicast_ttl = multicast_ttl;
+}
+
static void udpsend_set_multicast_interface (t_udpsend *x, t_symbol *s, int argc, t_atom *argv)
{
#ifdef _WIN32
@@ -333,6 +348,7 @@ void udpsend_setup(void)
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,