Net::B...::Entry(3pm)

πŸ’– Net::B...::Entry(3pm) πŸ’–

okay bestie so this is a page from the User Contributed Perl Documentation and honestly? it's giving networking icon. buckle up πŸŽ€


✨ NAME ✨

Net::Bonjour::Entry β€” the support module for mDNS service discovery (that's Apple's Bonjour, iykyk) πŸ¦‹


🌸 SYNOPSIS 🌸

use Net::Bonjour;

my $res = Net::Bonjour->new(<service>[, <protocol>]); $res->discover;

foreach my $entry ( $res->entries ) {      print $entry->name, "\n"; }

πŸ’… DESCRIPTION πŸ’…

So Net::Bonjour::Entry is the module that manages all the entries that come back from an mDNS service discovery (Apple's Bonjour, yes that Bonjour). If you want the whole picture, go read Net::Bonjour β€” this one's the little sister that handles the individual entries πŸ’œ


πŸ‘‘ METHODS πŸ‘‘

🫢 new([<fqdn>])

Makes you a brand new Net::Bonjour::Entry object, slay. That optional argument? It sets the fully qualifed domain name (FQDN) of the entry. But real talk β€” if you're using the Net::Bonjour module normally, you will not need to build Net::Bonjour::Entry objects yourself, because they get created automatically during the discovery process. the module does it for you, periodt ✨

πŸ¦‹ address

Hands you the IP address of the entry.

🌈 all_attrs

Returns every current attribute, in the form of a hashed array.

πŸ“ attribute(<attribute>)

Returns the attribute you asked for from the TXT record of the entry. TXT records are where the extra info lives, like the path for http. lowkey essential πŸ’…

⭐ dnsrr([<record type>])

Returns a DNS answer packet of the entry, and the output comes as a Net::DNS::Packet object. The record type is what resource record you want it to answer with, i.e. PTR, SRV, or TXT. The default? PTR.

🧚 fetch

Reloads the entry's info via mDNS. a little refresh moment πŸ’–

🌸 fqdn

Returns the fully qualifed domain name (FQDN) of the entry. An example FQDN is server._afpovertcp._tcp.local

πŸ’œ hostname

Returns the hostname of the server, e.g. 'server.local'.

πŸŽ€ name

Returns the name of the entry. With that fqdn example above, the name would be 'server'. But heads up: this name may not be the hostname of the server. For example, names for presence/tcp will be the name of the user, and http/tcp will be the title of the web resource. it's giving "name is a vibe, not an address" 😭

πŸ”₯ port

Returns the TCP or UDP port of the entry.

πŸ’€ sockaddr

Returns the binary socket address for the resource, and you can use it directly to bind() sockets. no cap, that's the good stuff.


πŸ™ˆ EXAMPLES πŸ™ˆ

print "<HTML><TITLE>Local Websites</TITLE>";

use Net::Bonjour;

my $res = Net::Bonjour->new('http');
$res->discover;

foreach my $entry ( $res->entries) {
        printf "<A HREF='http://%s%s'>%s</A><BR>",
                $entry->address, $entry->attribute('path'),
                $entry->name;
}

print "</HTML>";

πŸ¦‹ Find a service and connect to it

use Net::Bonjour;

my $res = Net::Bonjour->new('custom');
$res->discover;

my $entry = $res->shift_entry;

socket SOCK, PF_INET, SOCK_STREAM, scalar(getprotobyname('tcp'));

connect SOCK, $entry->sockaddr;

print SOCK "Send a message to the service";

while ($line = <SOCK>) { print $line; }

close SOCK;

🌟 SEE ALSO 🌟

  • Net::Bonjour

This library is free software and can be distributed or modified under the same terms as Perl itself. πŸ’–

Bonjour (in this context) is a trademark of Apple Computer, Inc.

πŸ’« AUTHORS πŸ’«

The Net::Bonjour::Entry module was created by George Chlipala <george@walnutcs.com> β€” give him his flowers πŸ’


and that's the whole page bestie, no crumbs left ✨ this was perl v5.32.0, dated 2021-01-05, from the Net::B...::Entry(3pm) manual β€” mwah, go build something iconic πŸ’…πŸ«Ά

πŸ“¦ where this page comes from