From 6da89627ce52d508400aefc284a451f99075541b Mon Sep 17 00:00:00 2001 From: Martin Peach Date: Tue, 13 Jul 2010 20:32:14 +0000 Subject: Added messages to set multicast ttl and loopback, updated the help patch. svn path=/trunk/externals/mrpeach/; revision=13711 --- net/udpreceive.c | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) (limited to 'net/udpreceive.c') 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 */ -- cgit v1.2.1