1tcllib_ip(n)                  Domain Name Service                 tcllib_ip(n)
2
3
4
5______________________________________________________________________________
6

NAME

8       tcllib_ip - IPv4 and IPv6 address manipulation
9

SYNOPSIS

11       package require Tcl  8.2
12
13       package require ip  ?1.1.2?
14
15       ::ip::version address
16
17       ::ip::is class address
18
19       ::ip::equal address address
20
21       ::ip::normalize address
22
23       ::ip::contract address
24
25       ::ip::prefix address
26
27       ::ip::type address
28
29       ::ip::mask address
30
31       ::ip::prefixToNative prefix
32
33       ::ip::nativeToPrefix nativeList|native ?-ipv4?
34
35       ::ip::intToString number ?-ipv4?
36
37       ::ip::toInteger ipaddr
38
39       ::ip::toHex ipaddr
40
41       ::ip::maskToInt ipmask
42
43       ::ip::broadcastAddress prefix ?-ipv4?
44
45       ::ip::maskToLength dottedMask|integerMask|hexMask ?-ipv4?
46
47       ::ip::lengthToMask maskLength ?-ipv4?
48
49       ::ip::nextNet ipaddr ipmask ?count? ?-ipv4?
50
51       ::ip::isOverlap prefix prefix...
52
53       ::ip::isOverlapNative ?-all? ?-inline? ?-ipv4? hexipaddr hexipmask hex‐
54       iplist
55
56       ::ip::ipToLayer2Multicast ipaddr
57
58       ::ip::ipHostFromPrefix prefix ?-exclude prefixExcludeList?
59
60       ::ip::reduceToAggregates prefixlist
61
62       ::ip::longestPrefixMatch ipaddr prefixlist ?-ipv4?
63
64_________________________________________________________________
65

DESCRIPTION

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

COMMANDS

72       ::ip::version address
73              Returns the protocol version of the address (4 or 6) or 0 if the
74              address is neither IPv4 or IPv6.
75
76       ::ip::is class address
77              Returns  true  if  the address is a member of the given protocol
78              class. The class parameter may be either ipv4 or  ipv6  This  is
79              effectively  a  boolean  equivalent  of the version command. The
80              class argument may be shortened to 4 or 6.
81
82       ::ip::equal address address
83              Compare two address specifications for  equivalence.  The  argu‐
84              ments  are  normalized  and  the address prefix determined (if a
85              mask is supplied). The normalized addresses  are  then  compared
86              bit-by-bit and the procedure returns true if they match.
87
88       ::ip::normalize address
89              Convert  an  IPv4 or IPv6 address into a fully expanded version.
90              There are various shorthand ways to  write  internet  addresses,
91              missing  out  redundant  parts  or digts.. This procedure is the
92              opposite of contract.
93
94       ::ip::contract address
95              Convert a normalized internet address into a more  compact  form
96              suitable for displaying to users.
97
98       ::ip::prefix address
99              Returns the address prefix generated by masking the address part
100              with the mask if provided. If there is no mask then it is equiv‐
101              alent to calling normalize
102
103       ::ip::type address
104
105       ::ip::mask address
106              If  the  address  supplied includes a mask then this is returned
107              otherwise returns an empty string.
108
109       ::ip::prefixToNative prefix
110              This  command  converts  the  string  prefix  from  dotted  form
111              (<ipaddr>/<mask>  format)  to  native (hex) form. Returns a list
112              containing two elements, ipaddress and mask, in this  order,  in
113              hexadecimal notation.
114
115
116                 % ip::prefixToNative 1.1.1.0/24
117                 0x01010100 0xffffff00
118
119
120       ::ip::nativeToPrefix nativeList|native ?-ipv4?
121              This command converts from native (hex) form to dotted form.  It
122              is the complement of ::ip::prefixToNative.
123
124
125              list nativeList (in)
126                     List of several ip addresses in native form.  The  native
127                     form is a list as returned by ::ip::prefixToNative.
128
129              list native (in)
130                     A list as returned by ::ip::prefixToNative.
131
132       The command returns a list of addresses in dotted form if it was called
133       with a list of addresses. Otherwise a single address in dotted form  is
134       returned.
135
136
137          % ip::nativeToPrefix {0x01010100 0xffffff00} -ipv4
138          1.1.1.0/24
139
140
141       ::ip::intToString number ?-ipv4?
142              This  command  converts  from an ip address specified as integer
143              number to dotted form.
144
145
146                     ip::intToString 4294967295
147                     255.255.255.255
148
149
150       ::ip::toInteger ipaddr
151              This command converts a dotted form ip into an integer number.
152
153
154                 % ::ip::toInteger 1.1.1.0
155                 16843008
156
157
158       ::ip::toHex ipaddr
159              This command converts dotted form ip into a hexadecimal number.
160
161
162                 % ::ip::toHex 1.1.1.0
163                 0x01010100
164
165
166       ::ip::maskToInt ipmask
167              This command convert an ipmask in either dotted  (255.255.255.0)
168              form or mask length form (24) into an integer number.
169
170
171                 ::ip::maskToInt 24
172                 4294967040
173
174
175       ::ip::broadcastAddress prefix ?-ipv4?
176              This commands returns a broadcast address in dotted form for the
177              given route prefix, either in the form "addr/mask", or in native
178              form. The result is in dotted form.
179
180
181                 ::ip::broadcastAddress 1.1.1.0/24
182                 1.1.1.255
183
184                 ::ip::broadcastAddress {0x01010100 0xffffff00}
185                 0x010101ff
186
187
188
189
190
191       ::ip::maskToLength dottedMask|integerMask|hexMask ?-ipv4?
192
193
194              This command converts the dotted or integer form of an ipmask to
195              the mask length form.
196
197
198
199
200
201
202
203                 ::ip::maskToLength 0xffffff00 -ipv4
204                 24
205
206                 % ::ip::maskToLength 255.255.255.0
207                 24
208
209
210       ::ip::lengthToMask maskLength ?-ipv4?
211              This command converts an ipmask in mask length form to its  dot‐
212              ted form.
213
214
215                 ::ip::lengthToMask 24
216                 255.255.255.0
217
218
219       ::ip::nextNet ipaddr ipmask ?count? ?-ipv4?
220              This  command  returns  an ipaddress in the same position in the
221              count next network. The default value for count is 1.
222
223              The address can be specified as either integer number or in dot‐
224              ted  form.  The  mask can be specified as either integer number,
225              dotted form, or mask length form.
226
227              The result is in hex form.
228
229       ::ip::isOverlap prefix prefix...
230              This command checks if the given ip prefixes overlap.  All argu‐
231              ments  are  in  dotted "addr/mask" form. All arguments after the
232              first prefix are compared against the first prefix.  The  result
233              is  a  boolean value. It is true if an overlap was found for any
234              of the prefixes.
235
236
237                % ::ip::isOverlap 1.1.1.0/24 2.1.0.1/32
238                0
239
240                ::ip::isOverlap 1.1.1.0/24 2.1.0.1/32 1.1.1.1/32
241                1
242
243
244       ::ip::isOverlapNative ?-all? ?-inline? ?-ipv4? hexipaddr hexipmask hex‐
245       iplist
246              This  command  is  similar to ::ip::isOverlap, however the argu‐
247              ments are in the native form, and the  form  of  the  result  is
248              under  greater  control  of  the  caller.  If the option -all is
249              specified it checks all addresses for overlap,  not  only  until
250              the  first one is found.  If the option -inline is specified the
251              command returns the overlapping prefix instead of index values.
252
253              The result  of  the  command  is,  depending  on  the  specified
254              options,
255
256              no options
257                     The  index  of  the first overlap found, or 0 if there is
258                     none.
259
260              -all   A list containing the indices of all overlaps  found,  or
261                     an empty list if there are none.
262
263              -inline
264                     The  first  overlapping  prefix,  or  an empoty string if
265                     there is none.
266
267              -all -inline
268                     A list containing the prefixes of all overlaps found,  or
269                     an empty list if there are none.
270
271
272         % ::ip::isOverlapNative 0x01010100 0xffffff00 {{0x02010001 0xffffffff}}
273         0
274
275         % ::ip::isOverlapNative 0x01010100 0xffffff00 {{0x02010001 0xffffffff} {0x01010101 0xffffffff}}
276         2
277
278
279       ::ip::ipToLayer2Multicast ipaddr
280              This  command  an  converts  ipv4  address in dotted form into a
281              layer 2 multicast address, also in dotted form.
282
283
284                % ::ip::ipToLayer2Multicast 224.0.0.2
285                01.00.5e.00.00.02
286
287
288       ::ip::ipHostFromPrefix prefix ?-exclude prefixExcludeList?
289              This command returns a host address from a prefix  in  the  form
290              "ipaddr/masklen",  also  making  sure  that the result is not an
291              address found in the prefixExcludeList.  The  result  is  an  ip
292              address in dotted form.
293
294
295                %::ip::ipHostFromPrefix  1.1.1.5/24
296                1.1.1.1
297
298                %::ip::ipHostFromPrefix  1.1.1.1/32
299                1.1.1.1
300
301
302       ::ip::reduceToAggregates prefixlist
303              This  command  finds  nets that overlap and filters out the more
304              specifc nets. The prefixes are in either addr/mask  form  or  in
305              native format.  The result is a list containing the non-overlap‐
306              ping ip prefixes from the input.
307
308
309                % ::ip::reduceToAggregates {1.1.1.0/24 1.1.0.0/8  2.1.1.0/24 1.1.1.1/32 }
310                1.0.0.0/8 2.1.1.0/24
311
312
313       ::ip::longestPrefixMatch ipaddr prefixlist ?-ipv4?
314              This command finds longest prefix match from  set  of  prefixes,
315              given  a  specific host address. The prefixes in the list are in
316              either native or dotted form, whereas the  host  address  is  in
317              either  ipprefix  format,  dotted  form,  or  integer form.  The
318              result is the prefix which is the most  specific  match  to  the
319              host address.
320
321
322                % ::ip::longestPrefixMatch 1.1.1.1 {1.1.1.0/24 1.0.0.0/8  2.1.1.0/24 1.1.1.0/28 }
323                1.1.1.0/28
324
325

EXAMPLES

327       % ip::version ::1
328       6
329       % ip::version 127.0.0.1
330       4
331
332
333       % ip::normalize 127/8
334       127.0.0.0/8
335       % ip::contract 192.168.0.0
336       192.168
337       %
338       % ip::normalize fec0::1
339       fec0:0000:0000:0000:0000:0000:0000:0001
340       % ip::contract fec0:0000:0000:0000:0000:0000:0000:0001
341       fec0::1
342
343
344       % ip::equal 192.168.0.4/16 192.168.0.0/16
345       1
346       % ip::equal fec0::1/10 fec0::fe01/10
347       1
348
349

REFERENCES

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

AUTHORS

359       Pat Thoyts
360

BUGS, IDEAS, FEEDBACK

362       This document, and the package it describes, will  undoubtedly  contain
363       bugs and other problems.  Please report such in the category dns of the
364       Tcllib  SF  Trackers  [http://sourceforge.net/tracker/?group_id=12883].
365       Please  also  report any ideas for enhancements you may have for either
366       package and/or documentation.
367

SEE ALSO

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

KEYWORDS

372       internet address, ip, ipv4, ipv6, rfc 3513
373
375       Copyright (c) 2004, Pat Thoyts
376       Copyright (c) 2005 Aamer Akhter <aakhter@cisco.com>
377
378
379
380
381dns                                  1.1.2                        tcllib_ip(n)
Impressum