Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
I am on Windows and using Strawberry Perl, and I also have a Windows virtual machine (VM) installed on my machine. The VM creates a network interface with the description "VirtualBox Host-Only Ethernet Adapter", and its IPv4 is: 192.168.56.1 (I configured the VM's network to run in bridge adapter mode, so the VM has an Ethernet interface at address 192.168.1.12). Normally, I use a wireless interface with an IPv4 address at 192.168.1.6.
I want to broadcast in the local subnet. So I ran this code:
use strict; use warnings; use IO::Socket::INET; my $broadcast_address = '255.255.255.255'; my $socket = IO::Socket::INET->new( Proto => 'udp', Broadcast => 1, LocalPort => 8888, PeerAddr => $broadcast_address, PeerPort => 9999, ) or die "Could not create socket: $!\n"; my $message = "Broadcast message!"; $socket->send($message) or die "Send error: $IO::Socket::errstr\n"; my $hostAddr = $socket->sockhost(); my $hostPort = $socket->sockport(); print "Broadcast message sent from address $hostAddr:$hostPort\n"; $socket->close();
The problem is it printed this out: "Broadcast message sent from address 192.168.56.1:8888".. The receiver couldn't receive the broadcast message from 192.168.56.1 address, but if I changed the $broadcast_address to 192.168.1.255, it would work.
I diagnosed that the Perl module automatically chooses 192.168.56.1 as the main IP address and then uses it to send messages. How do I get rid of that? And how to make the wireless interface the chosen?
Thanks in advance.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Broadcast when host machine contains virtual interface
by NERDVANA (Priest) on Aug 29, 2024 at 02:08 UTC | |
by Anonymous Monk on Aug 29, 2024 at 03:43 UTC | |
by NERDVANA (Priest) on Aug 29, 2024 at 04:05 UTC | |
|
Re: Broadcast when host machine contains virtual interface
by Anonymous Monk on Aug 29, 2024 at 15:19 UTC |