1addrinfo(3) User Contributed Perl Documentation addrinfo(3)
2
3
4
6 Net::addrinfo - interface to POSIX getaddrinfo(3) and related
7 constants, structures and functions.
8
10 use Net::addrinfo;
11 my $ainfo = getaddrinfo("www.marzot.net");
12
14 This Perl module is designed to implement and export functionality
15 related to the POSIX getaddrinfo(3) system call. The Net::addrinfo data
16 object is provided with field name accsessor functions, similarly named
17 to the the C data structure definition in netdb.h. The getaddrinfo(3),
18 gai_strerror(3) calls, and related constants are exported.
19
20 The getaddrinfo() routine mimics the POSIX documented funtion (see
21 system man page getaddrinfo(3)).
22
23 On success the getaddrinfo() will return an array of Net::addrinfo data
24 objects.
25
26 In scalar context getaddrinfo() will return the first element from the
27 Net::addrinfo array.
28
29 In case of error, a numeric error code is returned.
30
31 The error code may be passed to gai_strerror() to get a string
32 representation of the error.
33
34 New Net::addrinfo objects may be created with the package constructor
35 and any number (or none) of the fields may be specified.
36
37 flags => scalar integer
38 family => scalar integer (e.g., AF_INET,m AF_INET6, etc.)
39 socktype => scalar integer (e.g., SOCK_DGRAM, SOCK_STREAM, etc.)
40 protocol => scalar integer (e.g., IPPROTO_UDP, IPPROTO_TCP, etc.)
41 addrlen => scalar integer (can be computed by length($self->addr))
42 addr => packed bytes (e.g., $self->addr(inet_aton("192.168.1.1")); )
43
44 Flags may be set in the structure so that it may be used as a 'hint'
45 parameter to the getaddrinfo() function. See exported @AI_FLAGS for
46 list of acceptable constants.
47
48 (Note: a special scalar integer field, 'val_status', is provided in
49 support of DNSSEC aware addrinfo results (see
50 Net::DNS::SEC::Validator))
51
53 use Net::addrinfo;
54 use Socket qw(:all);
55
56 my $hint = new Net::addrinfo(flags => AI_CANONNAME,
57 family => AF_INET,
58 socktype => SOCK_DGRAM);
59
60 my (@ainfo) = getaddrinfo("www.marzot.net", "http", $hint);
61
62 foreach $ainfo (@ainfo) {
63 if (ref $ainfo eq 'Net::addrinfo') {
64 print $ainfo->stringify(), "\n";
65 print "addr = ", inet_ntoa($ainfo->addr), "\n";
66 ...
67 connect(SH, $ainfo->addr);
68 } else {
69 print "Error($ainfo):", gai_strerror($ainfo), "\n";
70 }
71 }
72
74 One should not rely on the internal representation of this class.
75
77 G. S. Marzot (marz@users.sourceforge.net)
78
80 Copyright (c) 2006 G. S. Marzot. All rights reserved. This program
81 is free software; you can redistribute it and/or modify it under
82 the same terms as Perl itself.
83
84 Copyright (c) 2006-2008 SPARTA, Inc. All Rights Reserved. This program
85 is free software; you can redistribute it and/or modify it under
86 the same terms as Perl itself.
87
88
89
90perl v5.12.4 2011-01-04 addrinfo(3)