How to get UDP broadcast packets

Started by
5 comments, last by hplus0603 14 years ago
Hi, I am playing warcraft3 in LAN. What i noticed is that my game is sending and receiving UDP packets from 6112 port of my computer. I want to get those packets by code in java or c++. Any idea will be appreciate. Thanks in advance
Advertisement
Wouldn't opening a socket connection work for intercepting those ports ?
My game is running on my Computer "A" and i want to make a program which will also run on my computer "A". When game will run this will give and receive UDP packets from computer "B" and "C" in same network. My target is that computer "A" (after running game) should understand of my process as a client ( computer "D"). So when game will broadcast than i will also grab packets. But i am not able to connect with same port which are already using by game. What is concept behind it to understand same pc as client where server is hosting. is this virtual network ?

Here "A","B","C" and "D" are dummy name as for mentioning.
Use WinPCap. Easiest is to install and use Wireshark -- it can capture files that you can analyze from C++ or Java.
enum Bool { True, False, FileNotFound };
Btw: your post title says "broadcast," but your message just says "sending on port 6112."

If it really is UDP broadcast, then all you have to do is turn on SO_BROADCAST on the socket (with setsockopt()) and bind() to port 6112 on all local subnets (IPADDR_ANY), and you will get a copy of those broadcast packets.
enum Bool { True, False, FileNotFound };
Thanks for your response. but the problem is that my game is using the 6112 port to send and receive broadcast udp packets and i want those udp packets. cause the game is using 6112 port so i am not able to listen on 6112 port by my program because game and program is running on the same computer . please tell me how to get these packets by program.
If you create a socket, turn on SO_BROADCAST, and bind to port 6112, then you will get broadcast packets on that port. You may have to turn on SO_REUSEADDR to be able to bind more than one socket to the same port.
enum Bool { True, False, FileNotFound };

This topic is closed to new replies.

Advertisement