473,587 Members | 2,448 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to determine origin of incoming message (uincast/multicast/broadcast)

Plater
7,872 Recognized Expert Expert
(Sorry about the title, i'm not sure how to explain this)

I am wondering if it is possible to tell on socket, HOW the incoming data was sent.
Now, what I mean by that is, I have a UDP socket just reading messages in a loop that come in on a port and pumping out a msg such like "Data from [IP Addy] arrived".
But if I "send" data to it, I want to know if it came from unicast, broadcast, or multicast.
Is that possible? It seems like it should be, but maybe I need to be in RAW mode and examine the bytes in the various headers?
Any thoughts?
Nov 2 '10 #1
17 12142
Oralloy
988 Recognized Expert Contributor
Do you mean you want to know if it was sent to a unicast, broadcast, or multicast address, or it was sent from such an address?

I think the answer is that you need to inspect the address to determine its status.

Here is the wikipedia on IP Multicast addressing.

Here are the pertinent bits from the article:

Unicast: The most common concept of an IP address is in unicast addressing, available in both IPv4 and IPv6. It normally refers to a single sender or a single receiver, and can be used for both sending and receiving. Usually, a unicast address is associated with a single device or host, but it is not a one-to-one correspondence. Some individual PCs have several distinct unicast addresses, each for its own distinct purpose. Sending the same data to multiple unicast addresses requires the sender to send all the data many times over, once for each recipient.

Broadcast: In IPv4 it is possible to send data to all possible destinations ("all-hosts broadcast"), which permits the sender to send the data only once, and all receivers receive a copy of it. In the IPv4 protocol, the address 255.255.255.255 is used for local broadcast. In addition, a directed (limited) broadcast can be made by combining the network prefix with a host suffix composed entirely of binary 1s. For example, the destination address used for a directed broadcast to devices on the 192.0.2.0/24 network is 192.0.2.255. IPv6 does not implement broadcast addressing and replaces it with multicast to the specially-defined all-nodes multicast address.

Multicast: A multicast address is associated with a group of interested receivers. In IPv4, addresses 224.0.0.0 through 239.255.255.255 (the former Class D addresses) are designated as multicast addresses.[2] The sender sends a single datagram from its unicast address to the multicast group address and the intermediary routers take care of making copies and sending them to all receivers that have joined the corresponding multicast group. IPv6 uses the address block with the prefix ff00::/8 for multicast applications.

Anycast (here for completeness): Like broadcast and multicast, anycast is a one-to-many routing topology. However, the data stream is not transmitted to all receivers, just the one which the router decides is the "closest" in the network.[Note 1] Anycast is useful for global load balancing and is commonly used in DNS communications.

I don't remember if there are macros available to check addresses or not, though.

Good luck!
Nov 2 '10 #2
Plater
7,872 Recognized Expert Expert
I guess who it was going TO is my question.

For instance with that UDP socket spitting out packets it sees (call it the "server"), I did the following:
*Had a client software on the same system send a UDP message to 255.255.255.255 (broadcast) on the port and my "server" saw the message and said "message from 127.0.0.1"
*Had a client software on the same system send to a multicast ip and my "server" saw the message and said "message from 192.168.1.7" (which is the IP of the machine the code was running on)

I was wondering if on the server I could tell the difference between those two messages (and a unicast to 192.168.1.7).
Would I change my server to have sockets be bound to a specific address (one to 192.168.1.7 and one to the multicast address) would that allow me to tell them apart?

While it is not crucial to the design that i know how the messages were received by my server, it would make things a bit easier on me.

(For what it is worth, I am playing with UPNP and listening for traffic on 1900. Messages from the multicast address are going to be general discover/announce payloads, messages sent to ME(unicast) are directed responses)
Nov 2 '10 #3
Oralloy
988 Recognized Expert Contributor
It looks like you're doing local loop-back for your testing, from what I read, correct?

If I recall correctly, sockets can bind to multiple addresses on a system. This is especially important for listening sockets, as they'll listen on 127.0.0.1 (loopback) as well the systems "normal" addresses. If you want to mask out localhost-loopback messages from your testing, you'll need to be careful about that. The problem is exacerbated with each IP address you add to your system, of course.

Alternately, you can drain off all recieved messages, expecting to recieve multiples. I happen to think that this is the better option.

Remember that it's the recipient's IP address that determines how a message is moved around the network. Which means that you can sent to a multi-cast address from a unicast address, right? That is, I can send a message from my local (unicast) IP of 10.1.2.3 to the multicast IP 224.1.2.3, right?

So, the address you recieved the message at determines how the message was sent.

The address the message was sent from determines how the reply will be handled. [as an aside, this is how SMURF and other attacks are crafted using raw sockets].

Since I don't know what your application is, I'm not sure what else to tell you which will help. Hopefully I'm not confusing you here.

Cheers!
Nov 2 '10 #4
Plater
7,872 Recognized Expert Expert
Well the end result would be the packets would be coming from other computers on my network, it is just in testing that i happened to be using the same machine for it.
I am thinking there is no good way to tell (outside of being in raw mode) I may have to look into that method
Nov 2 '10 #5
Oralloy
988 Recognized Expert Contributor
I guess I'm confused.

If you're listening on a UDP socket, you'll get the sender's address attached to your message. You already know the recieving address, if you set up your sockets correctly. Nothing prevents you from opening multiple listening sockets in parallel.

As for a TCP socket, you also get the sender's address as part of the connection request. Once listen() returns, you'll be able to get the address.
Nov 2 '10 #6
Plater
7,872 Recognized Expert Expert
I know I can get the senders address, what i want is the address the sender SENT to.

If my server UDP socket is listening (IPANY, PORT 1900)
Has IP 192.168.1.7
Subscribed to multicast IP 239.255.255.250

If the client software:
Has IP 192.168.1.4
Sends one message unicast to 192.168.1.7:190 0
Sends one message multicast to 239.255.255.250 :1900
Sends one message to broadcast 255.255.255.255 :1900

My server UDP will see all 3 messages, all will say they came from 192.168.1.4. Is there a way to tell on the SERVER which message was sent out in what manor (which one was sent to 239.255.255.250 and etc)?
Nov 3 '10 #7
Oralloy
988 Recognized Expert Contributor
Ok, I did some quick research, and it's not clear how to extract the recieving address from a conversation.

BTW, are you trying to build a network sniffer of some sort?

Regardless, I'm surprised that you're able to see multicast messages that you haven't registered in the multicast group for. That seems to be how the newer sockets protocol specification wants software to behave.

At this point, I'd start actively consider using raw sockets, just to make sure that I got all the requisite information from the incoming UDP packets. I can't think of any other way of extracting all requisite information, although we might have someone else here who is more knowledgable than I am.

Sorry I can't give you better information than that.

Good luck!
Nov 3 '10 #8
Plater
7,872 Recognized Expert Expert
Just trying to implememnt UPNP "by hand" so to speak.
And sorry, yes I have subscribed to the multicast group with the IP_ADD_MEMBERSH IP.

I was hoping there was some sort of API to read the extra data from the packet, but i can see why there isn't.
Raw socket it is probably going to be.
Nov 4 '10 #9
Oralloy
988 Recognized Expert Contributor
Plater - you, Sir, are an ambitious man.

Good luck with your home-brew UPnP. I hope it works out well for you.

When you get done, let us know what your implementation is, would you, please?

Cheers!
Oralloy
Nov 4 '10 #10

Sign in to post your reply or Sign up for a free account.

Similar topics

3
2403
by: Fred Palmer | last post by:
I am trying to get reponses from multiple devices on my network by sending the following message via UDP: // Create the message Byte bytesSent = new Byte {0x00, 0x00, 0x00, 0xF6}; Socket s = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp); // Send the message to be broadcast s.SendTo(bytesSent,...
3
2808
by: Tom Opgenorth | last post by:
I'm experiencing a problem with sockets, and I'm really hoping someone can help me, please and thank you. I've written a TCP Server, which listens on a port for an incoming connection. When the client connects, the connection is NEVER to be closed by the server. The client will send messages as necessary. After each message the server is...
2
2175
by: Ronodev.Sen | last post by:
the way my program needs to go is -- 1) open a socket and listen on it 2) moment a client connects to the socket - process some data (by sending it to another machine), get the result and send it back to the SAME socket - the data isnt a large value (measured in bytes rather than MB or GB) i TRIED thinking of this in the Asynchronous...
4
8173
by: John A Grandy | last post by:
How to determine if a request originated from a link click , or otherwise ( such as pasting the url the browser ). This would seem to work ... if (Request.Url.Host == Request.UrlReferrer.Host) { But what if Request.UrlReferrer == null ... ?
8
3216
by: swell | last post by:
I would like to write a server with the low level API of python ( socket+select and/or socket+thread ) that allow me to register client and update them every X seconds ( could be the time, the temperature, a stock quote, a message , ... ). How to write the server that keep hot connections with clients and update them when events are...
1
6243
by: jlamanna | last post by:
Hi. I'm adding IPV6 support to my app, and I have a UDP Broadcast socket that I need to redo using IPV6. I know that IPV6 doesn't have a notion of broadcast anymore, its all multicast (broadcast translates to a multicast address of ff02::1 essentially). However, the following code throws an exception on the SetSocketOption() call: Socket...
0
1594
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'
1
2066
by: Jean-Paul Calderone | last post by:
On Thu, 9 Oct 2008 06:03:44 -0700 (PDT), Stodge <stodge@gmail.comwrote: Your server and client are both listening on the multicast address 224.0.0.1. Traffic sent to that address will be delivered to both of them. If you want to send something to all clients listening on that address, then that's the address to pass to transport.write. ...
0
1556
by: rahulsengar | last post by:
Hey how can i lauch my application on incoming call notification in windows mobile . hey can u please help me how to launch my application automatically when an incoming call occurs. Is there any way to lauch my application without opening it. The process which i went through was i created a cab file of my application which is working...
0
1895
by: LTCCTL | last post by:
hi all, I have an application to send and recieve an SMS but my application is not catching the incoming message. can anyone tell what's wrong with the following code: import javax.microedition.midlet.*; import javax.microedition.lcdui.*;
0
7920
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...
0
7849
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
1
7973
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...
0
8220
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...
0
6626
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...
1
5718
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...
0
3844
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...
1
2358
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1454
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.