creeble has asked for the wisdom of the Perl Monks concerning the following question:
Okay, let's rephrase my previous question with more code.
I'm successfully sending out an mDNS query with the following code, and I see mDNS replies over tcpdump. But the UDP watcher never fires, or at least the on_recv callback never gets called:
use strict; use AnyEvent; #use AnyEvent::DNS; use AnyEvent::Handle::UDP; use AnyEvent::Socket (); use Socket; # try this my $cb = sub {}; my($proto) = shift; my $fqdn = "$proto.local"; #my $data = AnyEvent::DNS::dns_pack { rd => 1, qd => [[$fqdn, "ptr"]] +}; my $d = Net::DNS::Packet->new($fqdn, "PTR"); my $data = $d->data; my($name, $alias, $udp_proto) = AnyEvent::Socket::getprotobyname('udp' +); socket my($sock), PF_INET, SOCK_DGRAM, $udp_proto; AnyEvent::Util::fh_nonblocking $sock, 1; bind $sock, sockaddr_in(0, Socket::inet_aton('0.0.0.0')); my %found; my $callback = sub {}; my $t; $t = AnyEvent::Handle::UDP->new( fh => $sock, #bind => ['0.0.0.0', 5353], timeout => 3, on_timeout => sub { print STDERR "WTF? timeout...\n"; #undef $t; #$cb->(values %found); }, on_recv => sub { print STDERR "callback!!\n"; my $buf = shift; my $handle = shift; #my $res = AnyEvent::DNS::dns_unpack $buf; my ($res,$err) = Net::DNS::Packet->new(\$buf, 1); my @rr = grep { lc $_->[0] eq $fqdn && $_->[1] eq 'ptr' } @{ +$res->{an} }; my @srv = grep { $_->[1] eq 'srv' } @{$res->{ar}}; if (@rr == 1 && @srv == 1) { my $name = $rr[0]->[3]; $name =~ s/\.$fqdn$//; my $service = { name => $name, host => $srv[0]->[6], port => $srv[0]->[5], proto => $proto, }; $found{$rr[0]->[3]} ||= do { $callback->($service) if $callback; $service; }; } }, ); send $sock, $data, 0, sockaddr_in(5353, Socket::inet_aton('224.0.0.251 +')); # defined wantarray && AnyEvent::Util::guard { undef $t }; AnyEvent->condvar->recv;
There are a couple of varieties of packing the message above, both seem to elicit replies, but neither reply gets caught by the AnyEvent::Handle::UDP watcher.
AnyEvent monks, come from your caves and help a lost soul!
Eric.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: AnyEvent::Handle::UDP -- can't get it to receive?
by Neighbour (Friar) on Apr 26, 2012 at 08:51 UTC | |
by Anonymous Monk on Apr 27, 2012 at 00:16 UTC | |
by creeble (Sexton) on Apr 27, 2012 at 00:21 UTC | |
by Neighbour (Friar) on May 03, 2012 at 08:17 UTC |