@@ -37,6 +37,7 @@ inet_pton4(const char *src, uint8_t *dst)
3737 static const char digits [] = "0123456789" ;
3838 int saw_digit , octets , ch ;
3939 uint8_t tmp [NS_INADDRSZ ], * tp ;
40+ const char * start = src ;
4041
4142 saw_digit = 0 ;
4243 octets = 0 ;
@@ -48,11 +49,11 @@ inet_pton4(const char *src, uint8_t *dst)
4849 uint32_t new = * tp * 10 + (uint32_t )(pch - digits );
4950
5051 if (new > 255 )
51- return ( 0 ) ;
52+ return -1 ;
5253 * tp = (uint8_t )new ;
5354 if (! saw_digit ) {
5455 if (++ octets > 4 )
55- return ( 0 ) ;
56+ return -1 ;
5657 saw_digit = 1 ;
5758 }
5859 } else if (ch == '.' && saw_digit ) {
@@ -61,13 +62,13 @@ inet_pton4(const char *src, uint8_t *dst)
6162 * ++ tp = 0 ;
6263 saw_digit = 0 ;
6364 } else
64- return ( 0 ) ;
65+ break ;
6566 }
6667 if (octets < 4 )
67- return ( 0 ) ;
68+ return -1 ;
6869
6970 memcpy (dst , tmp , NS_INADDRSZ );
70- return (1 );
71+ return (int )( src - start );
7172}
7273
7374/* int
@@ -92,14 +93,16 @@ inet_pton6(const char *src, uint8_t *dst)
9293 const char * xdigits , * curtok ;
9394 int ch , saw_xdigit ;
9495 uint32_t val ;
96+ int len ;
97+ const char * start = src ;
9598
9699 memset ((tp = tmp ), '\0' , NS_IN6ADDRSZ );
97100 endp = tp + NS_IN6ADDRSZ ;
98101 colonp = NULL ;
99102 /* Leading :: requires some special handling. */
100103 if (* src == ':' )
101104 if (* ++ src != ':' )
102- return ( 0 ) ;
105+ return -1 ;
103106 curtok = src ;
104107 saw_xdigit = 0 ;
105108 val = 0 ;
@@ -112,7 +115,7 @@ inet_pton6(const char *src, uint8_t *dst)
112115 val <<= 4 ;
113116 val |= (pch - xdigits );
114117 if (val > 0xffff )
115- return ( 0 ) ;
118+ return -1 ;
116119 saw_xdigit = 1 ;
117120 continue ;
118121 }
@@ -133,16 +136,17 @@ inet_pton6(const char *src, uint8_t *dst)
133136 continue ;
134137 }
135138 if (ch == '.' && ((tp + NS_INADDRSZ ) <= endp ) &&
136- inet_pton4 (curtok , tp ) > 0 ) {
139+ (len = inet_pton4 (curtok , tp )) > 0 ) {
140+ src += len ;
137141 tp += NS_INADDRSZ ;
138142 saw_xdigit = 0 ;
139143 break ; /* '\0' was seen by inet_pton4(). */
140144 }
141- return ( 0 ) ;
145+ return -1 ;
142146 }
143147 if (saw_xdigit ) {
144148 if (tp + NS_INT16SZ > endp )
145- return ( 0 ) ;
149+ return -1 ;
146150 * tp ++ = (uint8_t ) (val >> 8 ) & 0xff ;
147151 * tp ++ = (uint8_t ) val & 0xff ;
148152 }
@@ -161,9 +165,20 @@ inet_pton6(const char *src, uint8_t *dst)
161165 tp = endp ;
162166 }
163167 if (tp != endp )
164- return ( 0 ) ;
168+ return -1 ;
165169 memcpy (dst , tmp , NS_IN6ADDRSZ );
166- return (1 );
170+ return (int )(src - start );
171+ }
172+
173+ zone_nonnull_all
174+ static zone_really_inline int32_t scan_ip6 (
175+ const char * text , uint8_t * wire , size_t * length )
176+ {
177+ int len = inet_pton6 (text , wire );
178+ if (len == -1 )
179+ return -1 ;
180+ * length = (size_t )len ;
181+ return 16 ;
167182}
168183
169184zone_nonnull_all
@@ -178,7 +193,7 @@ static zone_really_inline int32_t parse_ip6(
178193 if ((r = have_contiguous (parser , type , field , token )) < 0 )
179194 return r ;
180195
181- if (inet_pton6 (token -> data , & parser -> rdata -> octets [parser -> rdata -> length ]) == 1 ) {
196+ if (inet_pton6 (token -> data , & parser -> rdata -> octets [parser -> rdata -> length ]) != - 1 ) {
182197 parser -> rdata -> length += 16 ;
183198 return ZONE_IP6 ;
184199 }
0 commit comments