35
35
* inet_pton4(src, dst)
36
36
* like inet_aton() but without all the hexadecimal and shorthand.
37
37
* return:
38
- * 1 if `src' is a valid dotted quad, else 0.
38
+ * length if `src' is a valid dotted quad, else 0.
39
39
* notice:
40
- * does not touch `dst' unless it's returning 1 .
40
+ * does not touch `dst' unless it's returning !0 .
41
41
* author:
42
42
* Paul Vixie, 1996.
43
43
*/
@@ -59,11 +59,11 @@ inet_pton4(const char *src, uint8_t *dst)
59
59
uint32_t new = * tp * 10 + (uint32_t )(pch - digits );
60
60
61
61
if (new > 255 )
62
- return -1 ;
62
+ return ( 0 ) ;
63
63
* tp = (uint8_t )new ;
64
64
if (! saw_digit ) {
65
65
if (++ octets > 4 )
66
- return -1 ;
66
+ return ( 0 ) ;
67
67
saw_digit = 1 ;
68
68
}
69
69
} else if (ch == '.' && saw_digit ) {
@@ -75,7 +75,7 @@ inet_pton4(const char *src, uint8_t *dst)
75
75
break ;
76
76
}
77
77
if (octets < 4 )
78
- return -1 ;
78
+ return ( 0 ) ;
79
79
80
80
memcpy (dst , tmp , NS_INADDRSZ );
81
81
return (int )(src - start );
@@ -85,9 +85,9 @@ inet_pton4(const char *src, uint8_t *dst)
85
85
* inet_pton6(src, dst)
86
86
* convert presentation level address to network order binary form.
87
87
* return:
88
- * 1 if `src' is a valid [RFC1884 2.2] address, else 0.
88
+ * length if `src' is a valid [RFC1884 2.2] address, else 0.
89
89
* notice:
90
- * (1) does not touch `dst' unless it's returning 1 .
90
+ * (1) does not touch `dst' unless it's returning !0 .
91
91
* (2) :: in a full address is silently ignored.
92
92
* credit:
93
93
* inspired by Mark Andrews.
@@ -112,7 +112,7 @@ inet_pton6(const char *src, uint8_t *dst)
112
112
/* Leading :: requires some special handling. */
113
113
if (* src == ':' )
114
114
if (* ++ src != ':' )
115
- return -1 ;
115
+ return ( 0 ) ;
116
116
curtok = src ;
117
117
saw_xdigit = 0 ;
118
118
val = 0 ;
@@ -125,7 +125,7 @@ inet_pton6(const char *src, uint8_t *dst)
125
125
val <<= 4 ;
126
126
val |= (pch - xdigits );
127
127
if (val > 0xffff )
128
- return -1 ;
128
+ return ( 0 ) ;
129
129
saw_xdigit = 1 ;
130
130
continue ;
131
131
}
@@ -156,7 +156,7 @@ inet_pton6(const char *src, uint8_t *dst)
156
156
}
157
157
if (saw_xdigit ) {
158
158
if (tp + NS_INT16SZ > endp )
159
- return -1 ;
159
+ return ( 0 ) ;
160
160
* tp ++ = (uint8_t ) (val >> 8 ) & 0xff ;
161
161
* tp ++ = (uint8_t ) val & 0xff ;
162
162
}
@@ -175,20 +175,15 @@ inet_pton6(const char *src, uint8_t *dst)
175
175
tp = endp ;
176
176
}
177
177
if (tp != endp )
178
- return -1 ;
178
+ return ( 0 ) ;
179
179
memcpy (dst , tmp , NS_IN6ADDRSZ );
180
180
return (int )(src - start );
181
181
}
182
182
183
183
nonnull_all
184
- static really_inline int32_t scan_ip6 (
185
- const char * text , uint8_t * wire , size_t * length )
184
+ static really_inline int32_t scan_ip6 (const char * text , uint8_t * wire )
186
185
{
187
- int len = inet_pton6 (text , wire );
188
- if (len == -1 )
189
- return -1 ;
190
- * length = (size_t )len ;
191
- return 16 ;
186
+ return inet_pton6 (text , wire );
192
187
}
193
188
194
189
nonnull_all
@@ -199,12 +194,10 @@ static really_inline int32_t parse_ip6(
199
194
rdata_t * rdata ,
200
195
const token_t * token )
201
196
{
202
- if (inet_pton6 (token -> data , rdata -> octets ) != -1 ) {
203
- rdata -> octets += 16 ;
204
- return 0 ;
205
- }
206
-
207
- SYNTAX_ERROR (parser , "Invalid %s in %s" , NAME (item ), NAME (type ));
197
+ if ((size_t )inet_pton6 (token -> data , rdata -> octets ) != token -> length )
198
+ SYNTAX_ERROR (parser , "Invalid %s in %s" , NAME (item ), NAME (type ));
199
+ rdata -> octets += 16 ;
200
+ return 0 ;
208
201
}
209
202
210
203
#endif // IP6_H
0 commit comments