2 * Prefix related functions.
3 * Copyright (C) 1997, 98, 99 Kunihiro Ishiguro
5 * This file is part of GNU Zebra.
7 * GNU Zebra is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License as published by the
9 * Free Software Foundation; either version 2, or (at your option) any
12 * GNU Zebra is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with GNU Zebra; see the file COPYING. If not, write to the Free
19 * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
27 #include "sockunion.h"
32 static const u_char maskbit[] = {0x00, 0x80, 0xc0, 0xe0, 0xf0,
33 0xf8, 0xfc, 0xfe, 0xff};
35 static const struct in6_addr maskbytes6[] =
37 /* /0 */ { { { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 } } },
38 /* /1 */ { { { 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 } } },
39 /* /2 */ { { { 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 } } },
40 /* /3 */ { { { 0xe0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 } } },
41 /* /4 */ { { { 0xf0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 } } },
42 /* /5 */ { { { 0xf8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 } } },
43 /* /6 */ { { { 0xfc, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 } } },
44 /* /7 */ { { { 0xfe, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 } } },
45 /* /8 */ { { { 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 } } },
46 /* /9 */ { { { 0xff, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 } } },
47 /* /10 */ { { { 0xff, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 } } },
48 /* /11 */ { { { 0xff, 0xe0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 } } },
49 /* /12 */ { { { 0xff, 0xf0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 } } },
50 /* /13 */ { { { 0xff, 0xf8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 } } },
51 /* /14 */ { { { 0xff, 0xfc, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 } } },
52 /* /15 */ { { { 0xff, 0xfe, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 } } },
53 /* /16 */ { { { 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 } } },
54 /* /17 */ { { { 0xff, 0xff, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 } } },
55 /* /18 */ { { { 0xff, 0xff, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 } } },
56 /* /19 */ { { { 0xff, 0xff, 0xe0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 } } },
57 /* /20 */ { { { 0xff, 0xff, 0xf0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 } } },
58 /* /21 */ { { { 0xff, 0xff, 0xf8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 } } },
59 /* /22 */ { { { 0xff, 0xff, 0xfc, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 } } },
60 /* /23 */ { { { 0xff, 0xff, 0xfe, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 } } },
61 /* /24 */ { { { 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 } } },
62 /* /25 */ { { { 0xff, 0xff, 0xff, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 } } },
63 /* /26 */ { { { 0xff, 0xff, 0xff, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 } } },
64 /* /27 */ { { { 0xff, 0xff, 0xff, 0xe0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 } } },
65 /* /28 */ { { { 0xff, 0xff, 0xff, 0xf0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 } } },
66 /* /29 */ { { { 0xff, 0xff, 0xff, 0xf8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 } } },
67 /* /30 */ { { { 0xff, 0xff, 0xff, 0xfc, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 } } },
68 /* /31 */ { { { 0xff, 0xff, 0xff, 0xfe, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 } } },
69 /* /32 */ { { { 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 } } },
70 /* /33 */ { { { 0xff, 0xff, 0xff, 0xff, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 } } },
71 /* /34 */ { { { 0xff, 0xff, 0xff, 0xff, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 } } },
72 /* /35 */ { { { 0xff, 0xff, 0xff, 0xff, 0xe0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 } } },
73 /* /36 */ { { { 0xff, 0xff, 0xff, 0xff, 0xf0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 } } },
74 /* /37 */ { { { 0xff, 0xff, 0xff, 0xff, 0xf8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 } } },
75 /* /38 */ { { { 0xff, 0xff, 0xff, 0xff, 0xfc, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 } } },
76 /* /39 */ { { { 0xff, 0xff, 0xff, 0xff, 0xfe, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 } } },
77 /* /40 */ { { { 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 } } },
78 /* /41 */ { { { 0xff, 0xff, 0xff, 0xff, 0xff, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 } } },
79 /* /42 */ { { { 0xff, 0xff, 0xff, 0xff, 0xff, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 } } },
80 /* /43 */ { { { 0xff, 0xff, 0xff, 0xff, 0xff, 0xe0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 } } },
81 /* /44 */ { { { 0xff, 0xff, 0xff, 0xff, 0xff, 0xf0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 } } },
82 /* /45 */ { { { 0xff, 0xff, 0xff, 0xff, 0xff, 0xf8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 } } },
83 /* /46 */ { { { 0xff, 0xff, 0xff, 0xff, 0xff, 0xfc, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 } } },
84 /* /47 */ { { { 0xff, 0xff, 0xff, 0xff, 0xff, 0xfe, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 } } },
85 /* /48 */ { { { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 } } },
86 /* /49 */ { { { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 } } },
87 /* /50 */ { { { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 } } },
88 /* /51 */ { { { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xe0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 } } },
89 /* /52 */ { { { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xf0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 } } },
90 /* /53 */ { { { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xf8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 } } },
91 /* /54 */ { { { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfc, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 } } },
92 /* /55 */ { { { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfe, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 } } },
93 /* /56 */ { { { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 } } },
94 /* /57 */ { { { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 } } },
95 /* /58 */ { { { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 } } },
96 /* /59 */ { { { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xe0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 } } },
97 /* /60 */ { { { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xf0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 } } },
98 /* /61 */ { { { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xf8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 } } },
99 /* /62 */ { { { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfc, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 } } },
100 /* /63 */ { { { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfe, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 } } },
101 /* /64 */ { { { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 } } },
102 /* /65 */ { { { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 } } },
103 /* /66 */ { { { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 } } },
104 /* /67 */ { { { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xe0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 } } },
105 /* /68 */ { { { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xf0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 } } },
106 /* /69 */ { { { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xf8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 } } },
107 /* /70 */ { { { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfc, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 } } },
108 /* /71 */ { { { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfe, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 } } },
109 /* /72 */ { { { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 } } },
110 /* /73 */ { { { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 } } },
111 /* /74 */ { { { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 } } },
112 /* /75 */ { { { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xe0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 } } },
113 /* /76 */ { { { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xf0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 } } },
114 /* /77 */ { { { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xf8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 } } },
115 /* /78 */ { { { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfc, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 } } },
116 /* /79 */ { { { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfe, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 } } },
117 /* /80 */ { { { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 } } },
118 /* /81 */ { { { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00 } } },
119 /* /82 */ { { { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00 } } },
120 /* /83 */ { { { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xe0, 0x00, 0x00, 0x00, 0x00, 0x00 } } },
121 /* /84 */ { { { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xf0, 0x00, 0x00, 0x00, 0x00, 0x00 } } },
122 /* /85 */ { { { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xf8, 0x00, 0x00, 0x00, 0x00, 0x00 } } },
123 /* /86 */ { { { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfc, 0x00, 0x00, 0x00, 0x00, 0x00 } } },
124 /* /87 */ { { { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfe, 0x00, 0x00, 0x00, 0x00, 0x00 } } },
125 /* /88 */ { { { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00 } } },
126 /* /89 */ { { { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x80, 0x00, 0x00, 0x00, 0x00 } } },
127 /* /90 */ { { { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xc0, 0x00, 0x00, 0x00, 0x00 } } },
128 /* /91 */ { { { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xe0, 0x00, 0x00, 0x00, 0x00 } } },
129 /* /92 */ { { { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xf0, 0x00, 0x00, 0x00, 0x00 } } },
130 /* /93 */ { { { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xf8, 0x00, 0x00, 0x00, 0x00 } } },
131 /* /94 */ { { { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfc, 0x00, 0x00, 0x00, 0x00 } } },
132 /* /95 */ { { { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfe, 0x00, 0x00, 0x00, 0x00 } } },
133 /* /96 */ { { { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00 } } },
134 /* /97 */ { { { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x80, 0x00, 0x00, 0x00 } } },
135 /* /98 */ { { { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xc0, 0x00, 0x00, 0x00 } } },
136 /* /99 */ { { { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xe0, 0x00, 0x00, 0x00 } } },
137 /* /100 */ { { { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xf0, 0x00, 0x00, 0x00 } } },
138 /* /101 */ { { { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xf8, 0x00, 0x00, 0x00 } } },
139 /* /102 */ { { { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfc, 0x00, 0x00, 0x00 } } },
140 /* /103 */ { { { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfe, 0x00, 0x00, 0x00 } } },
141 /* /104 */ { { { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00 } } },
142 /* /105 */ { { { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x80, 0x00, 0x00 } } },
143 /* /106 */ { { { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xc0, 0x00, 0x00 } } },
144 /* /107 */ { { { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xe0, 0x00, 0x00 } } },
145 /* /108 */ { { { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xf0, 0x00, 0x00 } } },
146 /* /109 */ { { { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xf8, 0x00, 0x00 } } },
147 /* /110 */ { { { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfc, 0x00, 0x00 } } },
148 /* /111 */ { { { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfe, 0x00, 0x00 } } },
149 /* /112 */ { { { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00 } } },
150 /* /113 */ { { { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x80, 0x00 } } },
151 /* /114 */ { { { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xc0, 0x00 } } },
152 /* /115 */ { { { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xe0, 0x00 } } },
153 /* /116 */ { { { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xf0, 0x00 } } },
154 /* /117 */ { { { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xf8, 0x00 } } },
155 /* /118 */ { { { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfc, 0x00 } } },
156 /* /119 */ { { { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfe, 0x00 } } },
157 /* /120 */ { { { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00 } } },
158 /* /121 */ { { { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x80 } } },
159 /* /122 */ { { { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xc0 } } },
160 /* /123 */ { { { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xe0 } } },
161 /* /124 */ { { { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xf0 } } },
162 /* /125 */ { { { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xf8 } } },
163 /* /126 */ { { { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfc } } },
164 /* /127 */ { { { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfe } } },
165 /* /128 */ { { { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff } } }
168 /* Number of bits in prefix type. */
173 #define MASKBIT(offset) ((0xff << (PNBBY - (offset))) & 0xff)
176 prefix_bit (const u_char *prefix, const u_char prefixlen)
178 unsigned int offset = prefixlen / 8;
179 unsigned int shift = 7 - (prefixlen % 8);
181 return (prefix[offset] >> shift) & 1;
185 prefix6_bit (const struct in6_addr *prefix, const u_char prefixlen)
187 return prefix_bit((const u_char *) &prefix->s6_addr, prefixlen);
191 str2family(const char *string)
193 if (!strcmp("ipv4", string))
195 else if (!strcmp("ipv6", string))
197 else if (!strcmp("ethernet", string))
202 /* Address Famiy Identifier to Address Family converter. */
204 afi2family (afi_t afi)
209 else if (afi == AFI_IP6)
211 #endif /* HAVE_IPV6 */
212 else if (afi == AFI_ETHER)
218 family2afi (int family)
220 if (family == AF_INET)
223 else if (family == AF_INET6)
225 #endif /* HAVE_IPV6 */
226 else if (family == AF_ETHERNET)
246 safi2str(safi_t safi)
261 /* If n includes p prefix then return 1 else return 0. */
263 prefix_match (const struct prefix *n, const struct prefix *p)
267 const u_char *np, *pp;
269 /* If n's prefix is longer than p's one return 0. */
270 if (n->prefixlen > p->prefixlen)
273 /* Set both prefix's head pointer. */
274 np = (const u_char *)&n->u.prefix;
275 pp = (const u_char *)&p->u.prefix;
277 offset = n->prefixlen / PNBBY;
278 shift = n->prefixlen % PNBBY;
281 if (maskbit[shift] & (np[offset] ^ pp[offset]))
285 if (np[offset] != pp[offset])
290 /* Copy prefix from src to dest. */
292 prefix_copy (struct prefix *dest, const struct prefix *src)
294 dest->family = src->family;
295 dest->prefixlen = src->prefixlen;
297 if (src->family == AF_INET)
298 dest->u.prefix4 = src->u.prefix4;
300 else if (src->family == AF_INET6)
301 dest->u.prefix6 = src->u.prefix6;
302 #endif /* HAVE_IPV6 */
303 else if (src->family == AF_UNSPEC)
305 dest->u.lp.id = src->u.lp.id;
306 dest->u.lp.adv_router = src->u.lp.adv_router;
308 else if (src->family == AF_ETHERNET)
310 dest->u.prefix_eth = src->u.prefix_eth;
314 zlog (NULL, LOG_ERR, "prefix_copy(): Unknown address family %d",
321 * Return 1 if the address/netmask contained in the prefix structure
322 * is the same, and else return 0. For this routine, 'same' requires
323 * that not only the prefix length and the network part be the same,
324 * but also the host part. Thus, 10.0.0.1/8 and 10.0.0.2/8 are not
325 * the same. Note that this routine has the same return value sense
326 * as '==' (which is different from prefix_cmp).
329 prefix_same (const struct prefix *p1, const struct prefix *p2)
331 if (p1->family == p2->family && p1->prefixlen == p2->prefixlen)
333 if (p1->family == AF_INET)
334 if (IPV4_ADDR_SAME (&p1->u.prefix4.s_addr, &p2->u.prefix4.s_addr))
337 if (p1->family == AF_INET6 )
338 if (IPV6_ADDR_SAME (&p1->u.prefix6.s6_addr, &p2->u.prefix6.s6_addr))
340 #endif /* HAVE_IPV6 */
341 if (p1->family == AF_ETHERNET) {
342 if (!memcmp(p1->u.prefix_eth.octet, p2->u.prefix_eth.octet, ETHER_ADDR_LEN))
350 * Return 0 if the network prefixes represented by the struct prefix
351 * arguments are the same prefix, and 1 otherwise. Network prefixes
352 * are considered the same if the prefix lengths are equal and the
353 * network parts are the same. Host bits (which are considered masked
354 * by the prefix length) are not significant. Thus, 10.0.0.1/8 and
355 * 10.0.0.2/8 are considered equivalent by this routine. Note that
356 * this routine has the same return sense as strcmp (which is different
360 prefix_cmp (const struct prefix *p1, const struct prefix *p2)
365 /* Set both prefix's head pointer. */
366 const u_char *pp1 = (const u_char *)&p1->u.prefix;
367 const u_char *pp2 = (const u_char *)&p2->u.prefix;
369 if (p1->family != p2->family || p1->prefixlen != p2->prefixlen)
372 offset = p1->prefixlen / PNBBY;
373 shift = p1->prefixlen % PNBBY;
376 if (maskbit[shift] & (pp1[offset] ^ pp2[offset]))
380 if (pp1[offset] != pp2[offset])
387 * Count the number of common bits in 2 prefixes. The prefix length is
388 * ignored for this function; the whole prefix is compared. If the prefix
389 * address families don't match, return -1; otherwise the return value is
390 * in range 0 ... maximum prefix length for the address family.
393 prefix_common_bits (const struct prefix *p1, const struct prefix *p2)
399 /* Set both prefix's head pointer. */
400 const u_char *pp1 = (const u_char *)&p1->u.prefix;
401 const u_char *pp2 = (const u_char *)&p2->u.prefix;
403 if (p1->family == AF_INET)
404 length = IPV4_MAX_BYTELEN;
406 if (p1->family == AF_INET6)
407 length = IPV6_MAX_BYTELEN;
409 if (p1->family != p2->family || !length)
412 for (pos = 0; pos < length; pos++)
413 if (pp1[pos] != pp2[pos])
418 xor = pp1[pos] ^ pp2[pos];
419 for (bit = 0; bit < 8; bit++)
420 if (xor & (1 << (7 - bit)))
423 return pos * 8 + bit;
426 /* Return prefix family type string. */
428 prefix_family_str (const struct prefix *p)
430 if (p->family == AF_INET)
433 if (p->family == AF_INET6)
435 #endif /* HAVE_IPV6 */
436 if (p->family == AF_ETHERNET)
441 /* Allocate new prefix_ipv4 structure. */
445 struct prefix_ipv4 *p;
447 /* Call prefix_new to allocate a full-size struct prefix to avoid problems
448 where the struct prefix_ipv4 is cast to struct prefix and unallocated
449 bytes were being referenced (e.g. in structure assignments). */
450 p = (struct prefix_ipv4 *)prefix_new();
455 /* Free prefix_ipv4 structure. */
457 prefix_ipv4_free (struct prefix_ipv4 *p)
459 prefix_free((struct prefix *)p);
462 /* When string format is invalid return 0. */
464 str2prefix_ipv4 (const char *str, struct prefix_ipv4 *p)
471 /* Find slash inside string. */
472 pnt = strchr (str, '/');
474 /* String doesn't contail slash. */
477 /* Convert string to prefix. */
478 ret = inet_aton (str, &p->prefix);
482 /* If address doesn't contain slash we assume it host address. */
484 p->prefixlen = IPV4_MAX_BITLEN;
490 cp = XMALLOC (MTYPE_TMP, (pnt - str) + 1);
491 strncpy (cp, str, pnt - str);
492 *(cp + (pnt - str)) = '\0';
493 ret = inet_aton (cp, &p->prefix);
494 XFREE (MTYPE_TMP, cp);
496 /* Get prefix length. */
497 plen = (u_char) atoi (++pnt);
498 if (plen > IPV4_MAX_PREFIXLEN)
508 /* When string format is invalid return 0. */
510 str2prefix_eth (const char *str, struct prefix_eth *p)
516 const char *str_addr = str;
520 /* Find slash inside string. */
521 pnt = strchr (str, '/');
525 /* Get prefix length. */
526 plen = (u_char) atoi (++pnt);
533 cp = XMALLOC (MTYPE_TMP, (pnt - str) + 1);
534 strncpy (cp, str, pnt - str);
535 *(cp + (pnt - str)) = '\0';
540 /* Convert string to prefix. */
541 if (sscanf(str_addr, "%2x:%2x:%2x:%2x:%2x:%2x",
542 a+0, a+1, a+2, a+3, a+4, a+5) != 6)
547 for (i = 0; i < 6; ++i)
549 p->eth_addr.octet[i] = a[i] & 0xff;
552 p->family = AF_ETHERNET;
557 XFREE (MTYPE_TMP, cp);
562 /* Convert masklen into IP address's netmask (network byte order). */
564 masklen2ip (const int masklen, struct in_addr *netmask)
566 assert (masklen >= 0 && masklen <= IPV4_MAX_BITLEN);
568 /* left shift is only defined for less than the size of the type.
569 * we unconditionally use long long in case the target platform
570 * has defined behaviour for << 32 (or has a 64-bit left shift) */
572 if (sizeof(unsigned long long) > 4)
573 netmask->s_addr = htonl(0xffffffffULL << (32 - masklen));
575 netmask->s_addr = htonl(masklen ? 0xffffffffU << (32 - masklen) : 0);
578 /* Convert IP address's netmask into integer. We assume netmask is
579 sequential one. Argument netmask should be network byte order. */
581 ip_masklen (struct in_addr netmask)
583 uint32_t tmp = ~ntohl(netmask.s_addr);
585 /* clz: count leading zeroes. sadly, the behaviour of this builtin
586 * is undefined for a 0 argument, even though most CPUs give 32 */
587 return __builtin_clz(tmp);
592 /* Apply mask to IPv4 prefix (network byte order). */
594 apply_mask_ipv4 (struct prefix_ipv4 *p)
597 masklen2ip(p->prefixlen, &mask);
598 p->prefix.s_addr &= mask.s_addr;
601 /* If prefix is 0.0.0.0/0 then return 1 else return 0. */
603 prefix_ipv4_any (const struct prefix_ipv4 *p)
605 return (p->prefix.s_addr == 0 && p->prefixlen == 0);
610 /* Allocate a new ip version 6 route */
612 prefix_ipv6_new (void)
614 struct prefix_ipv6 *p;
616 /* Allocate a full-size struct prefix to avoid problems with structure
618 p = (struct prefix_ipv6 *)prefix_new();
619 p->family = AF_INET6;
623 /* Free prefix for IPv6. */
625 prefix_ipv6_free (struct prefix_ipv6 *p)
627 prefix_free((struct prefix *)p);
630 /* If given string is valid return pin6 else return NULL */
632 str2prefix_ipv6 (const char *str, struct prefix_ipv6 *p)
638 pnt = strchr (str, '/');
640 /* If string doesn't contain `/' treat it as host route. */
643 ret = inet_pton (AF_INET6, str, &p->prefix);
646 p->prefixlen = IPV6_MAX_BITLEN;
652 cp = XMALLOC (MTYPE_TMP, (pnt - str) + 1);
653 strncpy (cp, str, pnt - str);
654 *(cp + (pnt - str)) = '\0';
655 ret = inet_pton (AF_INET6, cp, &p->prefix);
659 plen = (u_char) atoi (++pnt);
660 if (plen > IPV6_MAX_BITLEN)
664 p->family = AF_INET6;
669 /* Convert struct in6_addr netmask into integer.
670 * FIXME return u_char as ip_maskleni() does. */
672 ip6_masklen (struct in6_addr netmask)
678 pnt = (unsigned char *) & netmask;
680 while ((*pnt == 0xff) && len < IPV6_MAX_BITLEN)
686 if (len < IPV6_MAX_BITLEN)
699 masklen2ip6 (const int masklen, struct in6_addr *netmask)
701 assert (masklen >= 0 && masklen <= IPV6_MAX_BITLEN);
702 memcpy (netmask, maskbytes6 + masklen, sizeof (struct in6_addr));
706 apply_mask_ipv6 (struct prefix_ipv6 *p)
712 index = p->prefixlen / 8;
716 pnt = (u_char *) &p->prefix;
717 offset = p->prefixlen % 8;
719 pnt[index] &= maskbit[offset];
728 str2in6_addr (const char *str, struct in6_addr *addr)
733 /* %x must point to unsinged int */
734 for (i = 0; i < 16; i++)
736 sscanf (str + (i * 2), "%02x", &x);
737 addr->s6_addr[i] = x & 0xff;
740 #endif /* HAVE_IPV6 */
743 apply_mask (struct prefix *p)
748 apply_mask_ipv4 ((struct prefix_ipv4 *)p);
752 apply_mask_ipv6 ((struct prefix_ipv6 *)p);
754 #endif /* HAVE_IPV6 */
761 /* Utility function of convert between struct prefix <=> union sockunion.
762 * FIXME This function isn't used anywhere. */
764 sockunion2prefix (const union sockunion *dest,
765 const union sockunion *mask)
767 if (dest->sa.sa_family == AF_INET)
769 struct prefix_ipv4 *p;
771 p = prefix_ipv4_new ();
773 p->prefix = dest->sin.sin_addr;
774 p->prefixlen = ip_masklen (mask->sin.sin_addr);
775 return (struct prefix *) p;
778 if (dest->sa.sa_family == AF_INET6)
780 struct prefix_ipv6 *p;
782 p = prefix_ipv6_new ();
783 p->family = AF_INET6;
784 p->prefixlen = ip6_masklen (mask->sin6.sin6_addr);
785 memcpy (&p->prefix, &dest->sin6.sin6_addr, sizeof (struct in6_addr));
786 return (struct prefix *) p;
788 #endif /* HAVE_IPV6 */
792 /* Utility function of convert between struct prefix <=> union sockunion. */
794 sockunion2hostprefix (const union sockunion *su, struct prefix *prefix)
796 if (su->sa.sa_family == AF_INET)
798 struct prefix_ipv4 *p;
800 p = prefix ? (struct prefix_ipv4 *) prefix : prefix_ipv4_new ();
802 p->prefix = su->sin.sin_addr;
803 p->prefixlen = IPV4_MAX_BITLEN;
804 return (struct prefix *) p;
807 if (su->sa.sa_family == AF_INET6)
809 struct prefix_ipv6 *p;
811 p = prefix ? (struct prefix_ipv6 *) prefix : prefix_ipv6_new ();
812 p->family = AF_INET6;
813 p->prefixlen = IPV6_MAX_BITLEN;
814 memcpy (&p->prefix, &su->sin6.sin6_addr, sizeof (struct in6_addr));
815 return (struct prefix *) p;
817 #endif /* HAVE_IPV6 */
822 prefix2sockunion (const struct prefix *p, union sockunion *su)
824 memset (su, 0, sizeof (*su));
826 su->sa.sa_family = p->family;
827 if (p->family == AF_INET)
828 su->sin.sin_addr = p->u.prefix4;
830 if (p->family == AF_INET6)
831 memcpy (&su->sin6.sin6_addr, &p->u.prefix6, sizeof (struct in6_addr));
832 #endif /* HAVE_IPV6 */
836 prefix_blen (const struct prefix *p)
841 return IPV4_MAX_BYTELEN;
845 return IPV6_MAX_BYTELEN;
847 #endif /* HAVE_IPV6 */
849 return ETHER_ADDR_LEN;
854 /* Generic function for conversion string to struct prefix. */
856 str2prefix (const char *str, struct prefix *p)
860 /* First we try to convert string to struct prefix_ipv4. */
861 ret = str2prefix_ipv4 (str, (struct prefix_ipv4 *) p);
866 /* Next we try to convert string to struct prefix_ipv6. */
867 ret = str2prefix_ipv6 (str, (struct prefix_ipv6 *) p);
870 #endif /* HAVE_IPV6 */
872 /* Next we try to convert string to struct prefix_eth. */
873 ret = str2prefix_eth (str, (struct prefix_eth *) p);
881 prefix2str (union prefix46constptr pu, char *str, int size)
883 const struct prefix *p = pu.p;
886 if (p->family == AF_ETHERNET) {
890 assert(size > (3*ETHER_ADDR_LEN) + 1 /* slash */ + 3 /* plen */ );
891 for (i = 0; i < ETHER_ADDR_LEN; ++i) {
892 sprintf(s, "%02x", p->u.prefix_eth.octet[i]);
893 if (i < (ETHER_ADDR_LEN - 1)) {
900 sprintf(s, "/%d", p->prefixlen);
904 inet_ntop (p->family, &p->u.prefix, buf, BUFSIZ);
905 snprintf (str, size, "%s/%d", buf, p->prefixlen);
914 p = XCALLOC (MTYPE_PREFIX, sizeof *p);
918 /* Free prefix structure. */
920 prefix_free (struct prefix *p)
922 XFREE (MTYPE_PREFIX, p);
925 /* Utility function. Check the string only contains digit
927 * FIXME str.[c|h] would be better place for this function. */
929 all_digit (const char *str)
931 for (; *str != '\0'; str++)
932 if (!isdigit ((int) *str))
937 /* Utility function to convert ipv4 prefixes to Classful prefixes */
938 void apply_classful_mask_ipv4 (struct prefix_ipv4 *p)
941 u_int32_t destination;
943 destination = ntohl (p->prefix.s_addr);
945 if (p->prefixlen == IPV4_MAX_PREFIXLEN);
946 /* do nothing for host routes */
947 else if (IN_CLASSC (destination))
952 else if (IN_CLASSB(destination))
965 ipv4_network_addr (in_addr_t hostaddr, int masklen)
969 masklen2ip (masklen, &mask);
970 return hostaddr & mask.s_addr;
974 ipv4_broadcast_addr (in_addr_t hostaddr, int masklen)
978 masklen2ip (masklen, &mask);
979 return (masklen != IPV4_MAX_PREFIXLEN-1) ?
981 (hostaddr | ~mask.s_addr) :
982 /* special case for /31 */
983 (hostaddr ^ ~mask.s_addr);
986 /* Utility function to convert ipv4 netmask to prefixes
987 ex.) "1.1.0.0" "255.255.0.0" => "1.1.0.0/16"
988 ex.) "1.0.0.0" NULL => "1.0.0.0/8" */
990 netmask_str2prefix_str (const char *net_str, const char *mask_str,
993 struct in_addr network;
996 u_int32_t destination;
999 ret = inet_aton (net_str, &network);
1005 ret = inet_aton (mask_str, &mask);
1009 prefixlen = ip_masklen (mask);
1013 destination = ntohl (network.s_addr);
1015 if (network.s_addr == 0)
1017 else if (IN_CLASSC (destination))
1019 else if (IN_CLASSB (destination))
1021 else if (IN_CLASSA (destination))
1027 sprintf (prefix_str, "%s/%d", net_str, prefixlen);
1033 /* Utility function for making IPv6 address string. */
1035 inet6_ntoa (struct in6_addr addr)
1037 static char buf[INET6_ADDRSTRLEN];
1039 inet_ntop (AF_INET6, &addr, buf, INET6_ADDRSTRLEN);
1042 #endif /* HAVE_IPV6 */