… | |
… | |
45 | |
45 | |
46 | use base 'Exporter'; |
46 | use base 'Exporter'; |
47 | |
47 | |
48 | our @EXPORT = qw( |
48 | our @EXPORT = qw( |
49 | getprotobyname |
49 | getprotobyname |
50 | parse_hostport |
50 | parse_hostport format_hostport |
51 | parse_ipv4 parse_ipv6 |
51 | parse_ipv4 parse_ipv6 |
52 | parse_ip parse_address |
52 | parse_ip parse_address |
53 | format_ipv4 format_ipv6 |
53 | format_ipv4 format_ipv6 |
54 | format_ip format_address |
54 | format_ip format_address |
55 | address_family |
55 | address_family |
… | |
… | |
278 | |
278 | |
279 | # hostnames must not contain :'s |
279 | # hostnames must not contain :'s |
280 | return if $host =~ /:/ && !parse_ipv6 $host; |
280 | return if $host =~ /:/ && !parse_ipv6 $host; |
281 | |
281 | |
282 | ($host, $port) |
282 | ($host, $port) |
|
|
283 | } |
|
|
284 | |
|
|
285 | =item $string = format_hostport $host, $port |
|
|
286 | |
|
|
287 | Takes a host (in textual form) and a port and formats in unambigiously in |
|
|
288 | a way that C<parse_hostport> can parse it again. C<$port> can be C<undef>. |
|
|
289 | |
|
|
290 | =cut |
|
|
291 | |
|
|
292 | sub format_hostport($;$) { |
|
|
293 | my ($host, $port) = @_; |
|
|
294 | |
|
|
295 | $port = ":$port" if length $port; |
|
|
296 | $host = "[$host]" if $host =~ /:/; |
|
|
297 | |
|
|
298 | "$host$port" |
283 | } |
299 | } |
284 | |
300 | |
285 | =item $sa_family = address_family $ipn |
301 | =item $sa_family = address_family $ipn |
286 | |
302 | |
287 | Returns the address family/protocol-family (AF_xxx/PF_xxx, in one value :) |
303 | Returns the address family/protocol-family (AF_xxx/PF_xxx, in one value :) |