Date: Fri, 18 Dec 2009 10:18:55 -0600 From: Dex Nada <dxnada@gmail.com> To: Pieter de Goeje <pieter@degoeje.nl> Cc: freebsd-questions@freebsd.org Subject: Re: Joining multiple Multicast Streams Message-ID: <ce0994f50912180818w753c3492o4f524ab3632e188e@mail.gmail.com> In-Reply-To: <200912172128.14426.pieter@degoeje.nl> References: <ce0994f50912171045g41b9769eqfb26d714224826de@mail.gmail.com> <200912172128.14426.pieter@degoeje.nl>
next in thread | previous in thread | raw e-mail | index | archive | help
Thank you very much. I currently use the SO_REUSEADDR flag. I will try the SO_REUSEPORT as well - makes sense. Thank again. -DxN On Thu, Dec 17, 2009 at 2:28 PM, Pieter de Goeje <pieter@degoeje.nl> wrote: > On Thursday 17 December 2009 19:45:24 Dex Nada wrote: >> Hi: >> >> I am writing an application that joins a multicast stream on a specific UDP >> port. But when I run more than one instance of the same application, the >> second instance complains that the port is already in use. For example if I >> join stream 229.10.10.133:2000 on one instance and 229.10.10..134:2000 on >> another instance, the second one fails to join - I can however join it if I >> kill the first instance. I have compiled that application with SOCKET_REUSE >> option, but I wonder if I need to enable/recompile-with any special >> multicast kernel option for this to work. I do not have this problem when I >> run this code on Linux (Ubuntu 9.10) but I really want to get this working >> on FreeBSD. >> >> Thanks in advance. >> >> -DxN > > Try SO_REUSEPORT. The manpage (getsockopt(2)) specifically mentions multiple > listeners for the same multicast stream. The following pseudo C seems to work > fine: > > int reuseport = 1; > > memset(&addr, 0, sizeof(addr)); > addr.sin_family = AF_INET; > addr.sin_addr.s_addr = htonl(INADDR_ANY); > addr.sin_port = htons(port); > > mreq.imr_multiaddr.s_addr = maddr; > mreq.imr_interface.s_addr = INADDR_ANY; > > int fd = socket(AF_INET, SOCK_DGRAM, 0); > setsockopt(fd, SOL_SOCKET, SO_REUSEPORT, &reuseport, sizeof(reuseport)); > bind(fd, (struct sockaddr *)&addr, sizeof(addr)); > setsockopt(fd, IPPROTO_IP, IP_ADD_MEMBERSHIP, &mreq, sizeof(mreq)); > recvfrom(fd, ....); > > Good luck, > > Pieter de Goeje >
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?ce0994f50912180818w753c3492o4f524ab3632e188e>