sub send_msg { my ( $self, $mac, $ucp_method, $arg_ref ) = @_; $arg_ref = {} unless ref($arg_ref) eq 'HASH'; croak('Must specify ucp_method') if !defined $ucp_method; my $encoded_mac; # use MAC_ZERO for discovery packets # Otherwise MAC must be specified if ( ( $ucp_method eq UCP_METHOD_DISCOVER ) or ( $ucp_method eq UCP_METHOD_ADV_DISCOVER ) ) { $encoded_mac = MAC_ZERO; } else { croak( 'Must specify mac address for $ucp_method_name->{$ucp_method} packets' ) if !defined $mac; $encoded_mac = encode_mac($mac); } my $msg_args = { ucp_method => $ucp_method, dst_mac => $encoded_mac, data_to_get => $arg_ref->{data_to_get}, data_to_set => $arg_ref->{data_to_set}, }; $msg_args->{src_ip} = $arg_ref->{src_ip} if $arg_ref->{src_ip}; my $msg_ref; eval { $msg_ref = Net::UDAP::MessageOut->new($msg_args) } or do { carp($@); return; }; my $sock = $self->socket; $sock->sockopt( SO_BROADCAST, 1 ); my $dest_ip = inet_ntoa(INADDR_BROADCAST); my $dest = pack_sockaddr_in( PORT_UDAP, INADDR_BROADCAST ); log( info => '*** Broadcasting ' . $ucp_method_name->{$ucp_method} . ' message to MAC address ' . decode_mac($encoded_mac) . " on $dest_ip\n" ); return $sock->send( $msg_ref->packed, 0, $dest ); }