From 33a18c5fd94f8f7d3830e17c22399c643ef98206 Mon Sep 17 00:00:00 2001 From: Martin Peach Date: Mon, 2 Aug 2010 16:00:44 +0000 Subject: Added method to set multicast TTL, updated help patch. svn path=/trunk/externals/mrpeach/; revision=13737 --- net/udpsend.c | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) (limited to 'net/udpsend.c') 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, -- cgit v1.2.1