Debian Codegraph @

upstream/mageia-cauldron/man3pm/Net::hostent.3pm

raw
1 .\" -*- mode: troff; coding: utf-8 -*-
2 .\" Automatically generated by Pod::Man v6.0.2 (Pod::Simple 3.45)
3 .\"
4 .\" Standard preamble:
5 .\" ========================================================================
6 .de Sp \" Vertical space (when we can't use .PP)
7 .if t .sp .5v
8 .if n .sp
9 ..
10 .de Vb \" Begin verbatim text
11 .ft CW
12 .nf
13 .ne \\$1
14 ..
15 .de Ve \" End verbatim text
16 .ft R
17 .fi
18 ..
19 .\" \*(C` and \*(C' are quotes in nroff, nothing in troff, for use with C<>.
20 .ie n \{\
21 . ds C` ""
22 . ds C' ""
23 'br\}
24 .el\{\
25 . ds C`
26 . ds C'
27 'br\}
28 .\"
29 .\" Escape single quotes in literal strings from groff's Unicode transform.
30 .ie \n(.g .ds Aq \(aq
31 .el .ds Aq '
32 .\"
33 .\" If the F register is >0, we'll generate index entries on stderr for
34 .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index
35 .\" entries marked with X<> in POD. Of course, you'll have to process the
36 .\" output yourself in some meaningful fashion.
37 .\"
38 .\" Avoid warning from groff about undefined register 'F'.
39 .de IX
40 ..
41 .nr rF 0
42 .if \n(.g .if rF .nr rF 1
43 .if (\n(rF:(\n(.g==0)) \{\
44 . if \nF \{\
45 . de IX
46 . tm Index:\\$1\t\\n%\t"\\$2"
47 ..
48 . if !\nF==2 \{\
49 . nr % 0
50 . nr F 2
51 . \}
52 . \}
53 .\}
54 .rr rF
55 .\"
56 .\" Required to disable full justification in groff 1.23.0.
57 .if n .ds AD l
58 .\" ========================================================================
59 .\"
60 .IX Title "Net::hostent 3pm"
61 .TH Net::hostent 3pm 2023-12-22 "perl v5.42.0" "Perl Programmers Reference Guide"
62 .\" For nroff, turn off justification. Always turn off hyphenation; it makes
63 .\" way too many mistakes in technical documents.
64 .if n .ad l
65 .nh
66 .SH NAME
67 Net::hostent \- by\-name interface to Perl\*(Aqs built\-in gethost*() functions
68 .SH SYNOPSIS
69 .IX Header "SYNOPSIS"
70 .Vb 1
71 \& use Net::hostent;
72 .Ve
73 .SH DESCRIPTION
74 .IX Header "DESCRIPTION"
75 This module\*(Aqs default exports override the core \fBgethostbyname()\fR and
76 \&\fBgethostbyaddr()\fR functions, replacing them with versions that return
77 "Net::hostent" objects. This object has methods that return the similarly
78 named structure field name from the C\*(Aqs hostent structure from \fInetdb.h\fR;
79 namely name, aliases, addrtype, length, and addr_list. The aliases and
80 addr_list methods return array reference, the rest scalars. The addr
81 method is equivalent to the zeroth element in the addr_list array
82 reference.
83 .PP
84 You may also import all the structure fields directly into your namespace
85 as regular variables using the :FIELDS import tag. (Note that this still
86 overrides your core functions.) Access these fields as variables named
87 with a preceding \f(CW\*(C`h_\*(C'\fR. Thus, \f(CW\*(C`$host_obj\->name()\*(C'\fR corresponds to
88 \&\f(CW$h_name\fR if you import the fields. Array references are available as
89 regular array variables, so for example \f(CW\*(C`@{ $host_obj\->aliases()
90 }\*(C'\fR would be simply \f(CW@h_aliases\fR.
91 .PP
92 The \fBgethost()\fR function is a simple front\-end that forwards a numeric
93 argument to \fBgethostbyaddr()\fR by way of Socket::inet_aton, and the rest
94 to \fBgethostbyname()\fR.
95 .PP
96 To access this functionality without the core overrides,
97 pass the \f(CW\*(C`use\*(C'\fR an empty import list, and then access
98 function functions with their full qualified names.
99 On the other hand, the built\-ins are still available
100 via the \f(CW\*(C`CORE::\*(C'\fR pseudo\-package.
101 .SH EXAMPLES
102 .IX Header "EXAMPLES"
103 .Vb 2
104 \& use Net::hostent;
105 \& use Socket;
106 \&
107 \& @ARGV = (\*(Aqnetscape.com\*(Aq) unless @ARGV;
108 \&
109 \& for $host ( @ARGV ) {
110 \&
111 \& unless ($h = gethost($host)) {
112 \& warn "$0: no such host: $host\en";
113 \& next;
114 \& }
115 \&
116 \& printf "\en%s is %s%s\en",
117 \& $host,
118 \& lc($h\->name) eq lc($host) ? "" : "*really* ",
119 \& $h\->name;
120 \&
121 \& print "\etaliases are ", join(", ", @{$h\->aliases}), "\en"
122 \& if @{$h\->aliases};
123 \&
124 \& if ( @{$h\->addr_list} > 1 ) {
125 \& my $i;
126 \& for $addr ( @{$h\->addr_list} ) {
127 \& printf "\etaddr #%d is [%s]\en", $i++, inet_ntoa($addr);
128 \& }
129 \& } else {
130 \& printf "\etaddress is [%s]\en", inet_ntoa($h\->addr);
131 \& }
132 \&
133 \& if ($h = gethostbyaddr($h\->addr)) {
134 \& if (lc($h\->name) ne lc($host)) {
135 \& printf "\etThat addr reverses to host %s!\en", $h\->name;
136 \& $host = $h\->name;
137 \& redo;
138 \& }
139 \& }
140 \& }
141 .Ve
142 .SH NOTE
143 .IX Header "NOTE"
144 While this class is currently implemented using the Class::Struct
145 module to build a struct\-like class, you shouldn\*(Aqt rely upon this.
146 .SH AUTHOR
147 .IX Header "AUTHOR"
148 Tom Christiansen