Solved

UDP Boradcast source IP address (1 liner easy if you know it!)

Posted on 2001-08-14
4
186 Views
Last Modified: 2013-11-13
I am currently working on my app's socket security...
In a couple of servers I listen for UDP broadcasts to do a few different thingies... but I need to verify the source of the broadcast before acting on it.

WinBroadcast is the winsock control I am using...
I put a line where the comment in the code below is that read...

msgbox WinBroadcast.RemoteHost & vbcrlf & _
 WinBroadcast.RemoteHostIP, vbInformation

but these properties all came back as "" (null)
How can I tell the IP address of the broadcaster??

Thanks guys n gals....



Private Sub WinBroadcast_DataArrival(ByVal bytesTotal As Long)
 Dim thestr As String
 '
 ' Need code here to determine the source IP
 '
 WinBroadcast.GetData thestr
 Select Case thestr
    Case "Terminate"
         Unload Me
         End
    Case "Show"
         Me.Show
 End Select
End Sub
0
Comment
Question by:LuckyPhill
  • 2
4 Comments
 
LVL 8

Accepted Solution

by:
DennisBorg earned 50 total points
ID: 6385917
You have to use GetData first, then check the RemoteHost and RemoteHostIP properties.

When you receive something, you'd perform the following steps:

   1) Get the data sent
   2) Inspect the RemoteHost/RemoteHostIP
   3) If you like the sender, act on the request, otherwise ignore the request.


-Dennis Borg
0
 
LVL 16

Expert Comment

by:Richie_Simonetti
ID: 6386024
Clear enought, i think.
0
 
LVL 1

Author Comment

by:LuckyPhill
ID: 6386774
damb! do you know I had this line the WRONG side of the getdata and took it out!!

If WinBroadcast.RemoteHostIP <> "127.0.0.1" Then Exit Sub

0
 
LVL 8

Expert Comment

by:DennisBorg
ID: 6388329
You were close. I ran into that once and noticed that the RemoteHost/IP properties were filled in *after* I got the data. It really had me running in circles for a while.

Glad to have helped, and that it was a simple solution for you.

Take care,

Dennis Borg
0

Featured Post

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
There is an easy way, in .NET, to centralize the treatment of all unexpected errors. First of all, instead of launching the application directly in a Form, you need first to write a Sub called Main, in a module. Then, set the Startup Object to th…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.

805 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question