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.


In reply to AnyEvent::Handle::UDP -- can't get it to receive? by creeble

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.