| | 1445 | =item gethost |
| | 1446 | |
| | 1447 | our OS::Name multi OS::gethost() |
| | 1448 | our OS::Name multi OS::gethost( Str $name, OS::Addfamily :$type ) |
| | 1449 | our OS::Name multi method gethost( OS::Addr $addr: ) is export |
| | 1450 | our OS::Name multi method gethost( URI $uri: ) is export |
| | 1451 | |
| | 1452 | The C<gethost> function operates on host naming or address information |
| | 1453 | and returns an C<OS::Name>. An C<OS::Name> is, minimally: |
| | 1454 | |
| | 1455 | class OS::Name { |
| | 1456 | has Str $.name; |
| | 1457 | has OS::Addr $.addr; |
| | 1458 | has Array of Str @.aliases; |
| | 1459 | has Array of OS::Addr @.addrs; |
| | 1460 | } |
| | 1461 | |
| | 1462 | Such names can apply to anything which has a name that maps |
| | 1463 | to an address, however, in this case the name is a hostname |
| | 1464 | and the address is some sort of network identifier (e.g. |
| | 1465 | an IPV4 address when resolving hosts that have IPV4 addresses). |
| | 1466 | |
| | 1467 | When stringified, an C<OS::Name> yields its name. When |
| | 1468 | stringified, an C<OS::addr> yields its address in an |
| | 1469 | appropriate text format (e.g. "10.1.2.3" for an IPV4 address). |
| | 1470 | |
| | 1471 | The optional C<type> adverb can be passed when resolving a hostname, |
| | 1472 | and will filter the result to only those addresses that are of |
| | 1473 | the appropriate address family. This feature may be supported by |
| | 1474 | the underlying operating system, or Perl may emulate it. |
| | 1475 | |
| | 1476 | Examples: |
| | 1477 | |
| | 1478 | say "Connection from {$socket.peer.gethost}"; |
| | 1479 | my $address = gethost("foo.example.com").addr; |
| | 1480 | my $hostname = gethost(:addr<"10.1.2.3">); |
| | 1481 | |