473,856 Members | 1,638 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Multicast UDP deamon and VLAN interfaces

Hi guys,
I have a daemon running on Debian and listening for multicast packets
sent to 224.0.0.251:535 3 (ZeroConf Multicast DNS queries).
The server is plugged into a VLAN trunk with eth0 and joins several
VLANs using virtual interfaces (i.e. eth0.xxx). It should be able to
capture the UDP packets on any interfaces, so it spawns a thread for
each interface specified in a config file, and for each thread it
creates a socket:

/*************** *************** *************** *************** *************** ***********/
// Inside a function whose parameters are:
// int *sfd - the socket file descriptor
// struct in_addr bound_ip - the IP on which to listen

#define PORT 5353
#define MGRP "224.0.0.0. 251"

struct sockaddr_in addr;
struct ip_mreq mc;

*sfd = socket( AF_INET, SOCK_DGRAM, IPPROTO_UDP );

bzero( &addr, sizeof( addr ) );
addr.sin_family = AF_INET;
addr.sin_port = htons( PORT );
addr.sin_addr = bound_ip;

bind( *sfd, (struct sockaddr *) &addr, sizeof(addr));

int flag = 1;
mc.imr_multiadd r.s_addr = inet_addr( MGRP );
mc.imr_interfac e = bound_ip;

setsockopt( *sfd, IPPROTO_IP, IP_ADD_MEMBERSH IP, &mc, sizeof(mc));
setsockopt( *sfd, SOL_SOCKET, SO_REUSEADDR, (char *) &flag,
sizeof(flag));
setsockopt( *sfd, SOL_SOCKET, SO_REUSEPORT, (char *) &flag,
sizeof(flag));

/*************** *************** *************** *************** *************** ***********/

The problem is that the server captures the UDP packets sent to the
Multicast group only when bound_ip is set to 0 (INADDR_ANY), and even
then, only when the packets are coming on the first interface (eth0).

If I see right, the problem could be that I want to capture packets
sent to 224.0.0.251 while listening on IP, say, 192.168.2.103. But even
then, how could one specify on which interface to listen for a
Multicast packet?

What I'd like is to
- be able to specify several interfaces and spawn one daemon for each
one
- receive Multicast UDP packets only on the specified interfaces

Any hints are appreciated

Thank you,

Regards

Dec 1 '06 #1
7 8500

pi************@ gmail.com wrote:
Hi guys,
I have a daemon running on Debian and listening for multicast packets
sent to 224.0.0.251:535 3 (ZeroConf Multicast DNS queries).
The server is plugged into a VLAN trunk with eth0 and joins several
VLANs using virtual interfaces (i.e. eth0.xxx). It should be able to
capture the UDP packets on any interfaces, so it spawns a thread for
each interface specified in a config file, and for each thread it
creates a socket:

/*************** *************** *************** *************** *************** ***********/
// Inside a function whose parameters are:
// int *sfd - the socket file descriptor
// struct in_addr bound_ip - the IP on which to listen

#define PORT 5353
#define MGRP "224.0.0.0. 251"

struct sockaddr_in addr;
struct ip_mreq mc;

*sfd = socket( AF_INET, SOCK_DGRAM, IPPROTO_UDP );

bzero( &addr, sizeof( addr ) );
addr.sin_family = AF_INET;
addr.sin_port = htons( PORT );
addr.sin_addr = bound_ip;

bind( *sfd, (struct sockaddr *) &addr, sizeof(addr));

int flag = 1;
mc.imr_multiadd r.s_addr = inet_addr( MGRP );
mc.imr_interfac e = bound_ip;

setsockopt( *sfd, IPPROTO_IP, IP_ADD_MEMBERSH IP, &mc, sizeof(mc));
setsockopt( *sfd, SOL_SOCKET, SO_REUSEADDR, (char *) &flag,
sizeof(flag));
setsockopt( *sfd, SOL_SOCKET, SO_REUSEPORT, (char *) &flag,
sizeof(flag));

/*************** *************** *************** *************** *************** ***********/

The problem is that the server captures the UDP packets sent to the
Multicast group only when bound_ip is set to 0 (INADDR_ANY), and even
then, only when the packets are coming on the first interface (eth0).
UNIX® Network Programming Volume 1 by R.W.Stevens says:

If the local interface is specified as the wildcard address for IPv4
(INADDR_ANY) or as an index of 0 for IPv6, then a single local
interface is chosen by the kernel.
If I see right, the problem could be that I want to capture packets
sent to 224.0.0.251 while listening on IP, say, 192.168.2.103. But even
then, how could one specify on which interface to listen for a
Multicast packet?

What I'd like is to
- be able to specify several interfaces and spawn one daemon for each
one
- receive Multicast UDP packets only on the specified interfaces
man ip(7)

IP_ADD_MEMBERSH IP
Join a multicast group. Argument is an ip_mreqn
structure.

struct ip_mreqn {
struct in_addr imr_multiaddr; /* IP multicast group
address */
struct in_addr imr_address; /* IP address of local
interface */
int imr_ifindex; /* interface index */
};

imr_multiaddr contains the address of the multicast
group the
application wants to join or leave. It must be a valid
multi-
cast address. imr_address is the address of the local
interface
with which the system should join the multicast group; if
it is
equal to INADDR_ANY an appropriate interface is chosen
by the
system. imr_ifindex is the interface index of the
interface
that should join/leave the imr_multiaddr group, or 0 to
indicate
any interface.

For compatibility, the old ip_mreq structure is still
supported.
It differs from ip_mreqn only by not including the
imr_ifindex
field. Only valid as a setsockopt(2).

Dec 1 '06 #2
pi************@ gmail.com wrote:
>
I have a daemon running on Debian and listening for multicast packets
sent to 224.0.0.251:535 3 (ZeroConf Multicast DNS queries).
The server is plugged into a VLAN trunk with eth0 and joins several
VLANs using virtual interfaces (i.e. eth0.xxx). It should be able to
capture the UDP packets on any interfaces, so it spawns a thread for
each interface specified in a config file, and for each thread it
creates a socket:
Off topic. C knows nothing about multicast, servers, eth0, VLANs,
UDP, packets, threads, sockets, etc. Find a newsgroup that deals
with your system. comp.unix.progr ammer is one possibility, another
is something that has 'debian' in its name.

--
Some informative links:
<news:news.anno unce.newusers
<http://www.geocities.c om/nnqweb/>
<http://www.catb.org/~esr/faqs/smart-questions.html>
<http://www.caliburn.nl/topposting.html >
<http://www.netmeister. org/news/learn2quote.htm l>
<http://cfaj.freeshell. org/google/>
Dec 1 '06 #3

Maxim Yegorushkin ha scritto:
pi************@ gmail.com wrote:
man ip(7)
struct ip_mreqn {
struct in_addr imr_multiaddr; /* IP multicast group
address */
struct in_addr imr_address; /* IP address of local
interface */
int imr_ifindex; /* interface index */
};
Ok, i passed from ip_mreq to ip_mreqn, but that wasn't my problem:
it seems that the interface doesn't even join the multicast group:

Using this:
struct ip_mreqn mc;
mc.imr_multiadd r = conf.multicast_ group;
mc.imr_address = bound_ip;
mc.imr_ifindex = 0;
setsockopt( *sfd, IPPROTO_IP, IP_ADD_MEMBERSH IP, &mc, sizeof(mc))

I still can't see any packet come into the daemon, even when netcat'ing
to 224.0.0.251:535 3 using UDP.
# nc -u 224.0.0.251 5353

It just seems that the daemon doesn't capture packets sent to the
multicast group.

Thanx in advance,

Dec 1 '06 #4

pi************@ gmail.com wrote:
Maxim Yegorushkin ha scritto:
pi************@ gmail.com wrote:
man ip(7)
struct ip_mreqn {
struct in_addr imr_multiaddr; /* IP multicast group
address */
struct in_addr imr_address; /* IP address of local
interface */
int imr_ifindex; /* interface index */
};

Ok, i passed from ip_mreq to ip_mreqn, but that wasn't my problem:
it seems that the interface doesn't even join the multicast group:

Using this:
struct ip_mreqn mc;
mc.imr_multiadd r = conf.multicast_ group;
mc.imr_address = bound_ip;
mc.imr_ifindex = 0;
setsockopt( *sfd, IPPROTO_IP, IP_ADD_MEMBERSH IP, &mc, sizeof(mc))
Your new code is equivalent to the code you posted before. What happens
is that you let the kernel determine which one interface joins the
group. This is why you receive datagrams from one interface only. To
join a multicast group on a specific interface set imr_address as the
local address of that interface, rather than INADDR_ANY.
I still can't see any packet come into the daemon, even when netcat'ing
to 224.0.0.251:535 3 using UDP.
# nc -u 224.0.0.251 5353

It just seems that the daemon doesn't capture packets sent to the
multicast group.
Use netstat -gn to see which interface joined which group.

Dec 1 '06 #5


On 1 Dic, 14:29, "Maxim Yegorushkin" <maxim.yegorush ...@gmail.com>
wrote:
pietro.ceru...@ gmail.com wrote:
Maxim Yegorushkin ha scritto:
pietro.ceru...@ gmail.com wrote:
man ip(7)
struct ip_mreqn {
struct in_addr imr_multiaddr; /* IP multicast group
address */
struct in_addr imr_address; /* IP address of local
interface */
int imr_ifindex; /* interface index */
};
Ok, i passed from ip_mreq to ip_mreqn, but that wasn't my problem:
it seems that the interface doesn't even join the multicast group:
Using this:
struct ip_mreqn mc;
mc.imr_multiadd r = conf.multicast_ group;
mc.imr_address = bound_ip;
mc.imr_ifindex = 0;
setsockopt( *sfd, IPPROTO_IP, IP_ADD_MEMBERSH IP, &mc, sizeof(mc))
>Your new code is equivalent to the code you posted before.
Please note that bound_ip is actually the IP address of the interface
this thread is responsible to.
>
It just seems that the daemon doesn't capture packets sent to the
multicast group.Use netstat -gn to see which interface joined which group.
Thanx

Dec 1 '06 #6
CBFalconer <cb********@yah oo.comwrites:
pi************@ gmail.com wrote:
>I have a daemon running on Debian and listening for multicast packets
sent to 224.0.0.251:535 3 (ZeroConf Multicast DNS queries).
The server is plugged into a VLAN trunk with eth0 and joins several
VLANs using virtual interfaces (i.e. eth0.xxx). It should be able to
capture the UDP packets on any interfaces, so it spawns a thread for
each interface specified in a config file, and for each thread it
creates a socket:

Off topic. C knows nothing about multicast, servers, eth0, VLANs,
UDP, packets, threads, sockets, etc. Find a newsgroup that deals
with your system. comp.unix.progr ammer is one possibility, another
is something that has 'debian' in its name.
Note that this thread is also cross-posted to comp.unix.progr ammer,
comp.protocols. tcp-ip, and comp.os.linux.n etworking. But yes, it's
off-topic for comp.lang.c.

--
Keith Thompson (The_Other_Keit h) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <* <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
Dec 1 '06 #7
Keith Thompson wrote:
>
CBFalconer <cb********@yah oo.comwrites:
pi************@ gmail.com wrote:
I have a daemon running on Debian and listening for multicast packets
sent to 224.0.0.251:535 3 (ZeroConf Multicast DNS queries).
The server is plugged into a VLAN trunk with eth0 and joins several
VLANs using virtual interfaces (i.e. eth0.xxx). It should be able to
capture the UDP packets on any interfaces, so it spawns a thread for
each interface specified in a config file, and for each thread it
creates a socket:
Off topic. C knows nothing about multicast, servers, eth0, VLANs,
UDP, packets, threads, sockets, etc. Find a newsgroup that deals
with your system. comp.unix.progr ammer is one possibility, another
is something that has 'debian' in its name.

Note that this thread is also cross-posted to comp.unix.progr ammer,
comp.protocols. tcp-ip, and comp.os.linux.n etworking. But yes, it's
off-topic for comp.lang.c.
True. I rarely look at the cross-post list. If I had I would have
set follow-ups, as I have done now.

--
Chuck F (cbfalconer at maineline dot net)
Available for consulting/temporary embedded and systems.
<http://cbfalconer.home .att.net>
Dec 1 '06 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
6529
by: PHLICS_Admin | last post by:
Hi All, There are two network cards in one computer (named A) , and there is one network card in another computer(named B). On computer A: one network card is used to connect to internet, and the other network card is used in intranet whose ipaddress is 192.168.0.1 On computer B: the network card's ipaddress is 192.168.0.2. These two computer can connect to each other.
7
7720
by: Jim H | last post by:
Is there something special I need to do to send data to a multicast IP and have it go across a router? Router is a Win2000 Server connecting 2 networks via RRAS PPTP. The routing appears to be working because I can ping the multicast address and get responses from the server on the other network. I didn't think ping would work like that but as long as I have the server process running I can ping the multicast IP and get a response. The...
2
3131
by: Terry | last post by:
I've got a strange problem receiving multicast packets in a C# application. What's strange is that it works *sometimes* but not always. I create a socket, call bind(), set the multicast socket option and then fire off a thread that calls "receiveFrom()" in a loop. This works sometimes, but other times it'll get into a funk where the "receiveFrom()" call doesn't return even though a packet trace capture (Ethereal) shows that the...
0
370
by: pietro.cerutti | last post by:
Hi guys, I have a daemon running on Debian and listening for multicast packets sent to 224.0.0.251:5353 (ZeroConf Multicast DNS queries). The server is plugged into a VLAN trunk with eth0 and joins several VLANs using virtual interfaces (i.e. eth0.xxx). It should be able to capture the UDP packets on any interfaces, so it spawns a thread for each interface specified in a config file, and for each thread it creates a socket: ...
1
4164
by: Jayme.Pechan | last post by:
I was working on a multicast client and ran into a possible problem. Here is the code... udpClient = new UdpClient(4000); udpClient.JoinMulticastGroup(IPAddress.Parse("224.1.1.1")); udpClient.BeginReceive(new AsyncCallback(DoUDPReceive), this); My concern is that it seems to make exclusive use of port 4000 so I worry that in a Citrix environment, it would fail with an AddressAlreadyInUse exception like it does if you run two...
2
3510
by: Sophie000 | last post by:
Based on my understanding, VLAN is similar to multicast. But one happens at L2, the other happens at L3: VLAN restricts Broadcast to a part of LAN, multicast restricts Broadcast to a part of network. VLAN table is kept by bridge; multicast is kept by multicast router. It is correct? My question is how do I decide which VLAN should the packet be broadcast to? It is said that there is an Ethernet frame tag header for VLAN ID. Does it use ...
5
3364
by: mcfly1204 | last post by:
I setup a vlan, vlan 5, and will have our ip phones as well as the phone server on this vlan. All the ports for this vlan are on the same physical switch, so I do not think I will have the need to venture off into vtp configurations. I was looking at dhcp snooping to given hosts on vlan 5 the ability to request ip addresses. Essentially, here is what I would like to accomplish: 1. the ip phone need to communicate with the phone server,...
5
8933
by: AliRezaGoogle | last post by:
Hi, I have a conceptual question on Events and Multicast Delegates. Let me explain: As we know an event is a multicast delegate. What we declare as an event is inherently a multicast delegate. I really do not undrestand what additional features the "event" keyword adds to multicast delegate. The only thing that I see as an additional feature is a "Thunder Icon" near event name in VS IDE when intellisense works;).
0
1610
by: Stodge | last post by:
I'm trying to get a simple multicast application working using Twisted; so far I have: from twisted.internet.protocol import DatagramProtocol from twisted.internet import reactor from twisted.application.internet import MulticastServer class MulticastServerUDP(DatagramProtocol): def startProtocol(self): print 'Started Listening'
0
9919
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10699
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10787
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10390
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9534
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7932
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
7098
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5762
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
3
3203
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.