diff options
author | Martin Peach <mrpeach@users.sourceforge.net> | 2010-08-02 16:00:44 +0000 |
---|---|---|
committer | Martin Peach <mrpeach@users.sourceforge.net> | 2010-08-02 16:00:44 +0000 |
commit | 33a18c5fd94f8f7d3830e17c22399c643ef98206 (patch) | |
tree | 27cff73c7fa9b3c3f46a5673ea91f2771a4b8a74 /net/udpsend.c | |
parent | f10ce88ffc77440145007f63242e1042b33df355 (diff) |
Added method to set multicast TTL, updated help patch.
svn path=/trunk/externals/mrpeach/; revision=13737
Diffstat (limited to 'net/udpsend.c')
-rw-r--r-- | net/udpsend.c | 20 |
1 files changed, 18 insertions, 2 deletions
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, |