inet_cidr_pton.c (156956) | inet_cidr_pton.c (170244) |
---|---|
1/* 2 * Copyright (c) 2004 by Internet Systems Consortium, Inc. ("ISC") 3 * Copyright (c) 1998,1999 by Internet Software Consortium. 4 * 5 * Permission to use, copy, modify, and distribute this software for any 6 * purpose with or without fee is hereby granted, provided that the above 7 * copyright notice and this permission notice appear in all copies. 8 * 9 * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES 10 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 11 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR 12 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 13 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 14 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT 15 * OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 16 */ 17 18#if defined(LIBC_SCCS) && !defined(lint) | 1/* 2 * Copyright (c) 2004 by Internet Systems Consortium, Inc. ("ISC") 3 * Copyright (c) 1998,1999 by Internet Software Consortium. 4 * 5 * Permission to use, copy, modify, and distribute this software for any 6 * purpose with or without fee is hereby granted, provided that the above 7 * copyright notice and this permission notice appear in all copies. 8 * 9 * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES 10 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 11 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR 12 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 13 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 14 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT 15 * OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 16 */ 17 18#if defined(LIBC_SCCS) && !defined(lint) |
19static const char rcsid[] = "$Id: inet_cidr_pton.c,v 1.2.2.1.8.2 2004/03/17 00:29:46 marka Exp $"; | 19static const char rcsid[] = "$Id: inet_cidr_pton.c,v 1.5.18.1 2005/04/27 05:00:53 sra Exp $"; |
20#endif 21#include <sys/cdefs.h> | 20#endif 21#include <sys/cdefs.h> |
22__FBSDID("$FreeBSD: head/lib/libc/inet/inet_cidr_pton.c 156956 2006-03-21 15:37:16Z ume $"); | 22__FBSDID("$FreeBSD: head/lib/libc/inet/inet_cidr_pton.c 170244 2007-06-03 17:20:27Z ume $"); |
23 24#include "port_before.h" 25 26#include <sys/types.h> 27#include <sys/socket.h> 28#include <netinet/in.h> 29#include <arpa/nameser.h> 30#include <arpa/inet.h> --- 15 unchanged lines hidden (view full) --- 46 47static int inet_cidr_pton_ipv4 __P((const char *src, u_char *dst, 48 int *bits, int ipv6)); 49static int inet_cidr_pton_ipv6 __P((const char *src, u_char *dst, 50 int *bits)); 51 52static int getbits(const char *, int ipv6); 53 | 23 24#include "port_before.h" 25 26#include <sys/types.h> 27#include <sys/socket.h> 28#include <netinet/in.h> 29#include <arpa/nameser.h> 30#include <arpa/inet.h> --- 15 unchanged lines hidden (view full) --- 46 47static int inet_cidr_pton_ipv4 __P((const char *src, u_char *dst, 48 int *bits, int ipv6)); 49static int inet_cidr_pton_ipv6 __P((const char *src, u_char *dst, 50 int *bits)); 51 52static int getbits(const char *, int ipv6); 53 |
54/* | 54/*% |
55 * int 56 * inet_cidr_pton(af, src, dst, *bits) 57 * convert network address from presentation to network format. 58 * accepts inet_pton()'s input for this "af" plus trailing "/CIDR". 59 * "dst" is assumed large enough for its "af". "bits" is set to the 60 * /CIDR prefix length, which can have defaults (like /32 for IPv4). 61 * return: 62 * -1 if an error occurred (inspect errno; ENOENT means bad format). --- 138 unchanged lines hidden (view full) --- 201 saw_xdigit = 0; 202 val = 0; 203 continue; 204 } 205 if (ch == '.' && ((tp + NS_INADDRSZ) <= endp) && 206 inet_cidr_pton_ipv4(curtok, tp, &bits, 1) == 0) { 207 tp += NS_INADDRSZ; 208 saw_xdigit = 0; | 55 * int 56 * inet_cidr_pton(af, src, dst, *bits) 57 * convert network address from presentation to network format. 58 * accepts inet_pton()'s input for this "af" plus trailing "/CIDR". 59 * "dst" is assumed large enough for its "af". "bits" is set to the 60 * /CIDR prefix length, which can have defaults (like /32 for IPv4). 61 * return: 62 * -1 if an error occurred (inspect errno; ENOENT means bad format). --- 138 unchanged lines hidden (view full) --- 201 saw_xdigit = 0; 202 val = 0; 203 continue; 204 } 205 if (ch == '.' && ((tp + NS_INADDRSZ) <= endp) && 206 inet_cidr_pton_ipv4(curtok, tp, &bits, 1) == 0) { 207 tp += NS_INADDRSZ; 208 saw_xdigit = 0; |
209 break; /* '\0' was seen by inet_pton4(). */ | 209 break; /*%< '\\0' was seen by inet_pton4(). */ |
210 } 211 if (ch == '/') { 212 bits = getbits(src, 1); 213 if (bits == -2) 214 goto enoent; 215 break; 216 } 217 goto enoent; --- 35 unchanged lines hidden (view full) --- 253 return (-1); 254} 255 256static int 257getbits(const char *src, int ipv6) { 258 int bits = 0; 259 char *cp, ch; 260 | 210 } 211 if (ch == '/') { 212 bits = getbits(src, 1); 213 if (bits == -2) 214 goto enoent; 215 break; 216 } 217 goto enoent; --- 35 unchanged lines hidden (view full) --- 253 return (-1); 254} 255 256static int 257getbits(const char *src, int ipv6) { 258 int bits = 0; 259 char *cp, ch; 260 |
261 if (*src == '\0') /* syntax */ | 261 if (*src == '\0') /*%< syntax */ |
262 return (-2); 263 do { 264 ch = *src++; 265 cp = strchr(digits, ch); | 262 return (-2); 263 do { 264 ch = *src++; 265 cp = strchr(digits, ch); |
266 if (cp == NULL) /* syntax */ | 266 if (cp == NULL) /*%< syntax */ |
267 return (-2); 268 bits *= 10; 269 bits += cp - digits; | 267 return (-2); 268 bits *= 10; 269 bits += cp - digits; |
270 if (bits == 0 && *src != '\0') /* no leading zeros */ | 270 if (bits == 0 && *src != '\0') /*%< no leading zeros */ |
271 return (-2); | 271 return (-2); |
272 if (bits > (ipv6 ? 128 : 32)) /* range error */ | 272 if (bits > (ipv6 ? 128 : 32)) /*%< range error */ |
273 return (-2); 274 } while (*src != '\0'); 275 276 return (bits); 277} | 273 return (-2); 274 } while (*src != '\0'); 275 276 return (bits); 277} |
278 279/*! \file */ |
|