~ubuntu-branches/ubuntu/oneiric/postgresql-9.1/oneiric-security

« back to all changes in this revision

Viewing changes to doc/src/sgml/html/datatype-net-types.html

  • Committer: Bazaar Package Importer
  • Author(s): Martin Pitt
  • Date: 2011-05-11 10:41:53 UTC
  • Revision ID: james.westby@ubuntu.com-20110511104153-psbh2o58553fv1m0
Tags: upstream-9.1~beta1
ImportĀ upstreamĀ versionĀ 9.1~beta1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
 
2
<HTML
 
3
><HEAD
 
4
><TITLE
 
5
>Network Address Types</TITLE
 
6
><META
 
7
NAME="GENERATOR"
 
8
CONTENT="Modular DocBook HTML Stylesheet Version 1.79"><LINK
 
9
REV="MADE"
 
10
HREF="mailto:pgsql-docs@postgresql.org"><LINK
 
11
REL="HOME"
 
12
TITLE="PostgreSQL 9.1beta1 Documentation"
 
13
HREF="index.html"><LINK
 
14
REL="UP"
 
15
TITLE="Data Types"
 
16
HREF="datatype.html"><LINK
 
17
REL="PREVIOUS"
 
18
TITLE="Geometric Types"
 
19
HREF="datatype-geometric.html"><LINK
 
20
REL="NEXT"
 
21
TITLE="Bit String Types"
 
22
HREF="datatype-bit.html"><LINK
 
23
REL="STYLESHEET"
 
24
TYPE="text/css"
 
25
HREF="stylesheet.css"><META
 
26
HTTP-EQUIV="Content-Type"
 
27
CONTENT="text/html; charset=ISO-8859-1"><META
 
28
NAME="creation"
 
29
CONTENT="2011-04-27T21:20:33"></HEAD
 
30
><BODY
 
31
CLASS="SECT1"
 
32
><DIV
 
33
CLASS="NAVHEADER"
 
34
><TABLE
 
35
SUMMARY="Header navigation table"
 
36
WIDTH="100%"
 
37
BORDER="0"
 
38
CELLPADDING="0"
 
39
CELLSPACING="0"
 
40
><TR
 
41
><TH
 
42
COLSPAN="5"
 
43
ALIGN="center"
 
44
VALIGN="bottom"
 
45
><A
 
46
HREF="index.html"
 
47
>PostgreSQL 9.1beta1 Documentation</A
 
48
></TH
 
49
></TR
 
50
><TR
 
51
><TD
 
52
WIDTH="10%"
 
53
ALIGN="left"
 
54
VALIGN="top"
 
55
><A
 
56
TITLE="Geometric Types"
 
57
HREF="datatype-geometric.html"
 
58
ACCESSKEY="P"
 
59
>Prev</A
 
60
></TD
 
61
><TD
 
62
WIDTH="10%"
 
63
ALIGN="left"
 
64
VALIGN="top"
 
65
><A
 
66
TITLE="Data Types"
 
67
HREF="datatype.html"
 
68
>Fast Backward</A
 
69
></TD
 
70
><TD
 
71
WIDTH="60%"
 
72
ALIGN="center"
 
73
VALIGN="bottom"
 
74
>Chapter 8. Data Types</TD
 
75
><TD
 
76
WIDTH="10%"
 
77
ALIGN="right"
 
78
VALIGN="top"
 
79
><A
 
80
TITLE="Data Types"
 
81
HREF="datatype.html"
 
82
>Fast Forward</A
 
83
></TD
 
84
><TD
 
85
WIDTH="10%"
 
86
ALIGN="right"
 
87
VALIGN="top"
 
88
><A
 
89
TITLE="Bit String Types"
 
90
HREF="datatype-bit.html"
 
91
ACCESSKEY="N"
 
92
>Next</A
 
93
></TD
 
94
></TR
 
95
></TABLE
 
96
><HR
 
97
ALIGN="LEFT"
 
98
WIDTH="100%"></DIV
 
99
><DIV
 
100
CLASS="SECT1"
 
101
><H1
 
102
CLASS="SECT1"
 
103
><A
 
104
NAME="DATATYPE-NET-TYPES"
 
105
>8.9. Network Address Types</A
 
106
></H1
 
107
><P
 
108
>    <SPAN
 
109
CLASS="PRODUCTNAME"
 
110
>PostgreSQL</SPAN
 
111
> offers data types to store IPv4, IPv6, and MAC
 
112
    addresses, as shown in <A
 
113
HREF="datatype-net-types.html#DATATYPE-NET-TYPES-TABLE"
 
114
>Table 8-21</A
 
115
>.  It
 
116
    is better to use these types instead of plain text types to store
 
117
    network addresses, because
 
118
    these types offer input error checking and specialized
 
119
    operators and functions (see <A
 
120
HREF="functions-net.html"
 
121
>Section 9.12</A
 
122
>).
 
123
   </P
 
124
><DIV
 
125
CLASS="TABLE"
 
126
><A
 
127
NAME="DATATYPE-NET-TYPES-TABLE"
 
128
></A
 
129
><P
 
130
><B
 
131
>Table 8-21. Network Address Types</B
 
132
></P
 
133
><TABLE
 
134
BORDER="1"
 
135
CLASS="CALSTABLE"
 
136
><COL><COL><COL><THEAD
 
137
><TR
 
138
><TH
 
139
>Name</TH
 
140
><TH
 
141
>Storage Size</TH
 
142
><TH
 
143
>Description</TH
 
144
></TR
 
145
></THEAD
 
146
><TBODY
 
147
><TR
 
148
><TD
 
149
><TT
 
150
CLASS="TYPE"
 
151
>cidr</TT
 
152
></TD
 
153
><TD
 
154
>7 or 19 bytes</TD
 
155
><TD
 
156
>IPv4 and IPv6 networks</TD
 
157
></TR
 
158
><TR
 
159
><TD
 
160
><TT
 
161
CLASS="TYPE"
 
162
>inet</TT
 
163
></TD
 
164
><TD
 
165
>7 or 19 bytes</TD
 
166
><TD
 
167
>IPv4 and IPv6 hosts and networks</TD
 
168
></TR
 
169
><TR
 
170
><TD
 
171
><TT
 
172
CLASS="TYPE"
 
173
>macaddr</TT
 
174
></TD
 
175
><TD
 
176
>6 bytes</TD
 
177
><TD
 
178
>MAC addresses</TD
 
179
></TR
 
180
></TBODY
 
181
></TABLE
 
182
></DIV
 
183
><P
 
184
>    When sorting <TT
 
185
CLASS="TYPE"
 
186
>inet</TT
 
187
> or <TT
 
188
CLASS="TYPE"
 
189
>cidr</TT
 
190
> data types,
 
191
    IPv4 addresses will always sort before IPv6 addresses, including
 
192
    IPv4 addresses encapsulated or mapped to IPv6 addresses, such as
 
193
    ::10.2.3.4 or ::ffff:10.4.3.2.
 
194
   </P
 
195
><DIV
 
196
CLASS="SECT2"
 
197
><H2
 
198
CLASS="SECT2"
 
199
><A
 
200
NAME="DATATYPE-INET"
 
201
>8.9.1. <TT
 
202
CLASS="TYPE"
 
203
>inet</TT
 
204
></A
 
205
></H2
 
206
><P
 
207
>     The <TT
 
208
CLASS="TYPE"
 
209
>inet</TT
 
210
> type holds an IPv4 or IPv6 host address, and
 
211
     optionally its subnet, all in one field.
 
212
     The subnet is represented by the number of network address bits
 
213
     present in the host address (the
 
214
     <SPAN
 
215
CLASS="QUOTE"
 
216
>"netmask"</SPAN
 
217
>).  If the netmask is 32 and the address is IPv4,
 
218
     then the value does not indicate a subnet, only a single host.
 
219
     In IPv6, the address length is 128 bits, so 128 bits specify a
 
220
     unique host address.  Note that if you
 
221
     want to accept only networks, you should use the
 
222
     <TT
 
223
CLASS="TYPE"
 
224
>cidr</TT
 
225
> type rather than <TT
 
226
CLASS="TYPE"
 
227
>inet</TT
 
228
>.
 
229
    </P
 
230
><P
 
231
>      The input format for this type is
 
232
      <TT
 
233
CLASS="REPLACEABLE"
 
234
><I
 
235
>address/y</I
 
236
></TT
 
237
>
 
238
      where
 
239
      <TT
 
240
CLASS="REPLACEABLE"
 
241
><I
 
242
>address</I
 
243
></TT
 
244
>
 
245
      is an IPv4 or IPv6 address and
 
246
      <TT
 
247
CLASS="REPLACEABLE"
 
248
><I
 
249
>y</I
 
250
></TT
 
251
>
 
252
      is the number of bits in the netmask.  If the
 
253
      <TT
 
254
CLASS="REPLACEABLE"
 
255
><I
 
256
>/y</I
 
257
></TT
 
258
>
 
259
      portion is missing, the
 
260
      netmask is 32 for IPv4 and 128 for IPv6, so the value represents
 
261
      just a single host.  On display, the
 
262
      <TT
 
263
CLASS="REPLACEABLE"
 
264
><I
 
265
>/y</I
 
266
></TT
 
267
>
 
268
      portion is suppressed if the netmask specifies a single host.
 
269
    </P
 
270
></DIV
 
271
><DIV
 
272
CLASS="SECT2"
 
273
><H2
 
274
CLASS="SECT2"
 
275
><A
 
276
NAME="DATATYPE-CIDR"
 
277
>8.9.2. <TT
 
278
CLASS="TYPE"
 
279
>cidr</TT
 
280
></A
 
281
></H2
 
282
><P
 
283
>     The <TT
 
284
CLASS="TYPE"
 
285
>cidr</TT
 
286
> type holds an IPv4 or IPv6 network specification.
 
287
     Input and output formats follow Classless Internet Domain Routing
 
288
     conventions.
 
289
     The format for specifying networks is <TT
 
290
CLASS="REPLACEABLE"
 
291
><I
 
292
>address/y</I
 
293
></TT
 
294
> where <TT
 
295
CLASS="REPLACEABLE"
 
296
><I
 
297
>address</I
 
298
></TT
 
299
> is the network represented as an
 
300
     IPv4 or IPv6 address, and <TT
 
301
CLASS="REPLACEABLE"
 
302
><I
 
303
>y</I
 
304
></TT
 
305
> is the number of bits in the netmask.  If
 
306
     <TT
 
307
CLASS="REPLACEABLE"
 
308
><I
 
309
>y</I
 
310
></TT
 
311
> is omitted, it is calculated
 
312
     using assumptions from the older classful network numbering system, except
 
313
     it will be at least large enough to include all of the octets
 
314
     written in the input.  It is an error to specify a network address
 
315
     that has bits set to the right of the specified netmask.
 
316
    </P
 
317
><P
 
318
>     <A
 
319
HREF="datatype-net-types.html#DATATYPE-NET-CIDR-TABLE"
 
320
>Table 8-22</A
 
321
> shows some examples.
 
322
    </P
 
323
><DIV
 
324
CLASS="TABLE"
 
325
><A
 
326
NAME="DATATYPE-NET-CIDR-TABLE"
 
327
></A
 
328
><P
 
329
><B
 
330
>Table 8-22. <TT
 
331
CLASS="TYPE"
 
332
>cidr</TT
 
333
> Type Input Examples</B
 
334
></P
 
335
><TABLE
 
336
BORDER="1"
 
337
CLASS="CALSTABLE"
 
338
><COL><COL><COL><THEAD
 
339
><TR
 
340
><TH
 
341
><TT
 
342
CLASS="TYPE"
 
343
>cidr</TT
 
344
> Input</TH
 
345
><TH
 
346
><TT
 
347
CLASS="TYPE"
 
348
>cidr</TT
 
349
> Output</TH
 
350
><TH
 
351
><TT
 
352
CLASS="LITERAL"
 
353
><CODE
 
354
CLASS="FUNCTION"
 
355
>abbrev(<TT
 
356
CLASS="TYPE"
 
357
>cidr</TT
 
358
>)</CODE
 
359
></TT
 
360
></TH
 
361
></TR
 
362
></THEAD
 
363
><TBODY
 
364
><TR
 
365
><TD
 
366
>192.168.100.128/25</TD
 
367
><TD
 
368
>192.168.100.128/25</TD
 
369
><TD
 
370
>192.168.100.128/25</TD
 
371
></TR
 
372
><TR
 
373
><TD
 
374
>192.168/24</TD
 
375
><TD
 
376
>192.168.0.0/24</TD
 
377
><TD
 
378
>192.168.0/24</TD
 
379
></TR
 
380
><TR
 
381
><TD
 
382
>192.168/25</TD
 
383
><TD
 
384
>192.168.0.0/25</TD
 
385
><TD
 
386
>192.168.0.0/25</TD
 
387
></TR
 
388
><TR
 
389
><TD
 
390
>192.168.1</TD
 
391
><TD
 
392
>192.168.1.0/24</TD
 
393
><TD
 
394
>192.168.1/24</TD
 
395
></TR
 
396
><TR
 
397
><TD
 
398
>192.168</TD
 
399
><TD
 
400
>192.168.0.0/24</TD
 
401
><TD
 
402
>192.168.0/24</TD
 
403
></TR
 
404
><TR
 
405
><TD
 
406
>128.1</TD
 
407
><TD
 
408
>128.1.0.0/16</TD
 
409
><TD
 
410
>128.1/16</TD
 
411
></TR
 
412
><TR
 
413
><TD
 
414
>128</TD
 
415
><TD
 
416
>128.0.0.0/16</TD
 
417
><TD
 
418
>128.0/16</TD
 
419
></TR
 
420
><TR
 
421
><TD
 
422
>128.1.2</TD
 
423
><TD
 
424
>128.1.2.0/24</TD
 
425
><TD
 
426
>128.1.2/24</TD
 
427
></TR
 
428
><TR
 
429
><TD
 
430
>10.1.2</TD
 
431
><TD
 
432
>10.1.2.0/24</TD
 
433
><TD
 
434
>10.1.2/24</TD
 
435
></TR
 
436
><TR
 
437
><TD
 
438
>10.1</TD
 
439
><TD
 
440
>10.1.0.0/16</TD
 
441
><TD
 
442
>10.1/16</TD
 
443
></TR
 
444
><TR
 
445
><TD
 
446
>10</TD
 
447
><TD
 
448
>10.0.0.0/8</TD
 
449
><TD
 
450
>10/8</TD
 
451
></TR
 
452
><TR
 
453
><TD
 
454
>10.1.2.3/32</TD
 
455
><TD
 
456
>10.1.2.3/32</TD
 
457
><TD
 
458
>10.1.2.3/32</TD
 
459
></TR
 
460
><TR
 
461
><TD
 
462
>2001:4f8:3:ba::/64</TD
 
463
><TD
 
464
>2001:4f8:3:ba::/64</TD
 
465
><TD
 
466
>2001:4f8:3:ba::/64</TD
 
467
></TR
 
468
><TR
 
469
><TD
 
470
>2001:4f8:3:ba:2e0:81ff:fe22:d1f1/128</TD
 
471
><TD
 
472
>2001:4f8:3:ba:2e0:81ff:fe22:d1f1/128</TD
 
473
><TD
 
474
>2001:4f8:3:ba:2e0:81ff:fe22:d1f1</TD
 
475
></TR
 
476
><TR
 
477
><TD
 
478
>::ffff:1.2.3.0/120</TD
 
479
><TD
 
480
>::ffff:1.2.3.0/120</TD
 
481
><TD
 
482
>::ffff:1.2.3/120</TD
 
483
></TR
 
484
><TR
 
485
><TD
 
486
>::ffff:1.2.3.0/128</TD
 
487
><TD
 
488
>::ffff:1.2.3.0/128</TD
 
489
><TD
 
490
>::ffff:1.2.3.0/128</TD
 
491
></TR
 
492
></TBODY
 
493
></TABLE
 
494
></DIV
 
495
></DIV
 
496
><DIV
 
497
CLASS="SECT2"
 
498
><H2
 
499
CLASS="SECT2"
 
500
><A
 
501
NAME="DATATYPE-INET-VS-CIDR"
 
502
>8.9.3. <TT
 
503
CLASS="TYPE"
 
504
>inet</TT
 
505
> vs. <TT
 
506
CLASS="TYPE"
 
507
>cidr</TT
 
508
></A
 
509
></H2
 
510
><P
 
511
>    The essential difference between <TT
 
512
CLASS="TYPE"
 
513
>inet</TT
 
514
> and <TT
 
515
CLASS="TYPE"
 
516
>cidr</TT
 
517
>
 
518
    data types is that <TT
 
519
CLASS="TYPE"
 
520
>inet</TT
 
521
> accepts values with nonzero bits to
 
522
    the right of the netmask, whereas <TT
 
523
CLASS="TYPE"
 
524
>cidr</TT
 
525
> does not.
 
526
    </P
 
527
><DIV
 
528
CLASS="TIP"
 
529
><BLOCKQUOTE
 
530
CLASS="TIP"
 
531
><P
 
532
><B
 
533
>Tip: </B
 
534
>        If you do not like the output format for <TT
 
535
CLASS="TYPE"
 
536
>inet</TT
 
537
> or
 
538
        <TT
 
539
CLASS="TYPE"
 
540
>cidr</TT
 
541
> values, try the functions <CODE
 
542
CLASS="FUNCTION"
 
543
>host</CODE
 
544
>,
 
545
        <CODE
 
546
CLASS="FUNCTION"
 
547
>text</CODE
 
548
>, and <CODE
 
549
CLASS="FUNCTION"
 
550
>abbrev</CODE
 
551
>.
 
552
        </P
 
553
></BLOCKQUOTE
 
554
></DIV
 
555
></DIV
 
556
><DIV
 
557
CLASS="SECT2"
 
558
><H2
 
559
CLASS="SECT2"
 
560
><A
 
561
NAME="DATATYPE-MACADDR"
 
562
>8.9.4. <TT
 
563
CLASS="TYPE"
 
564
>macaddr</TT
 
565
></A
 
566
></H2
 
567
><P
 
568
>     The <TT
 
569
CLASS="TYPE"
 
570
>macaddr</TT
 
571
> type stores MAC addresses, known for example
 
572
     from Ethernet card hardware addresses (although MAC addresses are
 
573
     used for other purposes as well).  Input is accepted in the
 
574
     following formats:
 
575
 
 
576
     <P
 
577
></P
 
578
><TABLE
 
579
BORDER="0"
 
580
><TBODY
 
581
><TR
 
582
><TD
 
583
><TT
 
584
CLASS="LITERAL"
 
585
>'08:00:2b:01:02:03'</TT
 
586
></TD
 
587
></TR
 
588
><TR
 
589
><TD
 
590
><TT
 
591
CLASS="LITERAL"
 
592
>'08-00-2b-01-02-03'</TT
 
593
></TD
 
594
></TR
 
595
><TR
 
596
><TD
 
597
><TT
 
598
CLASS="LITERAL"
 
599
>'08002b:010203'</TT
 
600
></TD
 
601
></TR
 
602
><TR
 
603
><TD
 
604
><TT
 
605
CLASS="LITERAL"
 
606
>'08002b-010203'</TT
 
607
></TD
 
608
></TR
 
609
><TR
 
610
><TD
 
611
><TT
 
612
CLASS="LITERAL"
 
613
>'0800.2b01.0203'</TT
 
614
></TD
 
615
></TR
 
616
><TR
 
617
><TD
 
618
><TT
 
619
CLASS="LITERAL"
 
620
>'08002b010203'</TT
 
621
></TD
 
622
></TR
 
623
></TBODY
 
624
></TABLE
 
625
><P
 
626
></P
 
627
>
 
628
 
 
629
     These examples would all specify the same address.  Upper and
 
630
     lower case is accepted for the digits
 
631
     <TT
 
632
CLASS="LITERAL"
 
633
>a</TT
 
634
> through <TT
 
635
CLASS="LITERAL"
 
636
>f</TT
 
637
>.  Output is always in the
 
638
     first of the forms shown.
 
639
    </P
 
640
><P
 
641
>     IEEE Std 802-2001 specifies the second shown form (with hyphens)
 
642
     as the canonical form for MAC addresses, and specifies the first
 
643
     form (with colons) as the bit-reversed notation, so that
 
644
     08-00-2b-01-02-03 = 01:00:4D:08:04:0C.  This convention is widely
 
645
     ignored nowadays, and it is only relevant for obsolete network
 
646
     protocols (such as Token Ring).  PostgreSQL makes no provisions
 
647
     for bit reversal, and all accepted formats use the canonical LSB
 
648
     order.
 
649
    </P
 
650
><P
 
651
>     The remaining four input formats are not part of any standard.
 
652
    </P
 
653
></DIV
 
654
></DIV
 
655
><DIV
 
656
CLASS="NAVFOOTER"
 
657
><HR
 
658
ALIGN="LEFT"
 
659
WIDTH="100%"><TABLE
 
660
SUMMARY="Footer navigation table"
 
661
WIDTH="100%"
 
662
BORDER="0"
 
663
CELLPADDING="0"
 
664
CELLSPACING="0"
 
665
><TR
 
666
><TD
 
667
WIDTH="33%"
 
668
ALIGN="left"
 
669
VALIGN="top"
 
670
><A
 
671
HREF="datatype-geometric.html"
 
672
ACCESSKEY="P"
 
673
>Prev</A
 
674
></TD
 
675
><TD
 
676
WIDTH="34%"
 
677
ALIGN="center"
 
678
VALIGN="top"
 
679
><A
 
680
HREF="index.html"
 
681
ACCESSKEY="H"
 
682
>Home</A
 
683
></TD
 
684
><TD
 
685
WIDTH="33%"
 
686
ALIGN="right"
 
687
VALIGN="top"
 
688
><A
 
689
HREF="datatype-bit.html"
 
690
ACCESSKEY="N"
 
691
>Next</A
 
692
></TD
 
693
></TR
 
694
><TR
 
695
><TD
 
696
WIDTH="33%"
 
697
ALIGN="left"
 
698
VALIGN="top"
 
699
>Geometric Types</TD
 
700
><TD
 
701
WIDTH="34%"
 
702
ALIGN="center"
 
703
VALIGN="top"
 
704
><A
 
705
HREF="datatype.html"
 
706
ACCESSKEY="U"
 
707
>Up</A
 
708
></TD
 
709
><TD
 
710
WIDTH="33%"
 
711
ALIGN="right"
 
712
VALIGN="top"
 
713
>Bit String Types</TD
 
714
></TR
 
715
></TABLE
 
716
></DIV
 
717
></BODY
 
718
></HTML
 
719
>
 
 
b'\\ No newline at end of file'