man tcllib_ip () - IPv4 and IPv6 address manipulation

NAME

tcllib_ip - IPv4 and IPv6 address manipulation

SYNOPSIS

package require Tcl 8.2 package require ip ?1.0.0? ::ip::version address ::ip::is class address ::ip::equal address address ::ip::normalize address ::ip::contract address ::ip::prefix address ::ip::type address ::ip::mask address

DESCRIPTION

This package provides a set of commands to help in parsing, displaying and comparing internet addresses. The package can handle both IPv4 (1) and IPv6 (2) address types.

COMMANDS

::ip::version address
Returns the protocol version of the address (4 or 6) or 0 if the address is neither IPv4 or IPv6.
::ip::is class address
Returns true if the address is a member of the given protocol class. The class parameter may be either ipv4 or ipv6 This is effectively a boolean equivalent of the version command. The class argument may be shortened to 4 or 6.
::ip::equal address address
Compare two address specifications for equivalence. The arguments are normalized and the address prefix determined (if a mask is supplied). The normalized addresses are then compared bit-by-bit and the procedure returns true if they match.
::ip::normalize address
Convert an IPv4 or IPv6 address into a fully expanded version. There are various shorthand ways to write internet addresses, missing out redundant parts or digts.. This procedure is the opposite of contract.
::ip::contract address
Convert a normalized internet address into a more compact form suitable for displaying to users.
::ip::prefix address
Returns the address prefix generated by masking the address part with the mask if provided. If there is no mask then it is equivalent to calling normalize
::ip::type address
::ip::mask address
If the address supplied includes a mask then this is returned otherwise returns an empty string.

EXAMPLES

% ip::version ::1
6
% ip::version 127.0.0.1
4
% ip::normalize 127/8
127.0.0.0/8
% ip::contract 192.168.0.0
192.168
%
% ip::normalize fec0::1
fec0:0000:0000:0000:0000:0000:0000:0001
% ip::contract fec0:0000:0000:0000:0000:0000:0000:0001
fec0::1
% ip::equal 192.168.0.4/16 192.168.0.0/16
1
% ip::equal fec0::1/10 fec0::fe01/10
1

REFERENCES

[1]
Postel, J. "Internet Protocol." RFC 791, September 1981, (http://www.ietf.org/rfc/rfc791.txt)
[2]
Hinden, R. and Deering, S., "Internet Protocol Version 6 (IPv6) Addressing Architecture", RFC 3513, April 2003 (http://www.ietf.org/rfc/rfc3513.txt)

AUTHORS

Pat Thoyts

SEE ALSO

inet(3), ip(7), ipv6(7)

KEYWORDS

internet address, ip, ipv4, ipv6, rfc 3513

COPYRIGHT

Copyright (c) 2004, Pat Thoyts