inet_addr.c (165903) | inet_addr.c (170244) |
---|---|
1/* 2 * Copyright (c) 1983, 1990, 1993 3 * The Regents of the University of California. All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright --- 52 unchanged lines hidden (view full) --- 61 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 62 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 63 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT 64 * OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 65 */ 66 67#if defined(LIBC_SCCS) && !defined(lint) 68static const char sccsid[] = "@(#)inet_addr.c 8.1 (Berkeley) 6/17/93"; | 1/* 2 * Copyright (c) 1983, 1990, 1993 3 * The Regents of the University of California. All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright --- 52 unchanged lines hidden (view full) --- 61 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 62 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 63 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT 64 * OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 65 */ 66 67#if defined(LIBC_SCCS) && !defined(lint) 68static const char sccsid[] = "@(#)inet_addr.c 8.1 (Berkeley) 6/17/93"; |
69static const char rcsid[] = "$Id: inet_addr.c,v 1.2.206.2 2004/03/17 00:29:45 marka Exp $"; | 69static const char rcsid[] = "$Id: inet_addr.c,v 1.4.18.1 2005/04/27 05:00:52 sra Exp $"; |
70#endif /* LIBC_SCCS and not lint */ 71#include <sys/cdefs.h> | 70#endif /* LIBC_SCCS and not lint */ 71#include <sys/cdefs.h> |
72__FBSDID("$FreeBSD: head/lib/libc/inet/inet_addr.c 165903 2007-01-09 00:28:16Z imp $"); | 72__FBSDID("$FreeBSD: head/lib/libc/inet/inet_addr.c 170244 2007-06-03 17:20:27Z ume $"); |
73 74#include "port_before.h" 75 76#include <sys/types.h> 77#include <sys/param.h> 78 79#include <netinet/in.h> 80#include <arpa/inet.h> 81 82#include <ctype.h> 83 84#include "port_after.h" 85 | 73 74#include "port_before.h" 75 76#include <sys/types.h> 77#include <sys/param.h> 78 79#include <netinet/in.h> 80#include <arpa/inet.h> 81 82#include <ctype.h> 83 84#include "port_after.h" 85 |
86/* | 86/*% |
87 * Ascii internet address interpretation routine. 88 * The value returned is in network order. 89 */ 90in_addr_t /* XXX should be struct in_addr :( */ 91inet_addr(const char *cp) { 92 struct in_addr val; 93 94 if (inet_aton(cp, &val)) 95 return (val.s_addr); 96 return (INADDR_NONE); 97} 98 | 87 * Ascii internet address interpretation routine. 88 * The value returned is in network order. 89 */ 90in_addr_t /* XXX should be struct in_addr :( */ 91inet_addr(const char *cp) { 92 struct in_addr val; 93 94 if (inet_aton(cp, &val)) 95 return (val.s_addr); 96 return (INADDR_NONE); 97} 98 |
99/* | 99/*% |
100 * Check whether "cp" is a valid ascii representation 101 * of an Internet address and convert to a binary address. 102 * Returns 1 if the address is valid, 0 if not. 103 * This replaces inet_addr, the return value from which 104 * cannot distinguish between failure and a local broadcast address. 105 */ 106int 107inet_aton(const char *cp, struct in_addr *addr) { --- 64 unchanged lines hidden (view full) --- 172 if (!digit) 173 return (0); 174 /* 175 * Concoct the address according to 176 * the number of parts specified. 177 */ 178 n = pp - parts + 1; 179 switch (n) { | 100 * Check whether "cp" is a valid ascii representation 101 * of an Internet address and convert to a binary address. 102 * Returns 1 if the address is valid, 0 if not. 103 * This replaces inet_addr, the return value from which 104 * cannot distinguish between failure and a local broadcast address. 105 */ 106int 107inet_aton(const char *cp, struct in_addr *addr) { --- 64 unchanged lines hidden (view full) --- 172 if (!digit) 173 return (0); 174 /* 175 * Concoct the address according to 176 * the number of parts specified. 177 */ 178 n = pp - parts + 1; 179 switch (n) { |
180 case 1: /* a -- 32 bits */ | 180 case 1: /*%< a -- 32 bits */ |
181 break; 182 | 181 break; 182 |
183 case 2: /* a.b -- 8.24 bits */ | 183 case 2: /*%< a.b -- 8.24 bits */ |
184 if (val > 0xffffffU) 185 return (0); 186 val |= parts[0] << 24; 187 break; 188 | 184 if (val > 0xffffffU) 185 return (0); 186 val |= parts[0] << 24; 187 break; 188 |
189 case 3: /* a.b.c -- 8.8.16 bits */ | 189 case 3: /*%< a.b.c -- 8.8.16 bits */ |
190 if (val > 0xffffU) 191 return (0); 192 val |= (parts[0] << 24) | (parts[1] << 16); 193 break; 194 | 190 if (val > 0xffffU) 191 return (0); 192 val |= (parts[0] << 24) | (parts[1] << 16); 193 break; 194 |
195 case 4: /* a.b.c.d -- 8.8.8.8 bits */ | 195 case 4: /*%< a.b.c.d -- 8.8.8.8 bits */ |
196 if (val > 0xffU) 197 return (0); 198 val |= (parts[0] << 24) | (parts[1] << 16) | (parts[2] << 8); 199 break; 200 } 201 if (addr != NULL) 202 addr->s_addr = htonl(val); 203 return (1); 204} 205 206/* 207 * Weak aliases for applications that use certain private entry points, 208 * and fail to include <arpa/inet.h>. 209 */ 210#undef inet_addr 211__weak_reference(__inet_addr, inet_addr); 212#undef inet_aton 213__weak_reference(__inet_aton, inet_aton); | 196 if (val > 0xffU) 197 return (0); 198 val |= (parts[0] << 24) | (parts[1] << 16) | (parts[2] << 8); 199 break; 200 } 201 if (addr != NULL) 202 addr->s_addr = htonl(val); 203 return (1); 204} 205 206/* 207 * Weak aliases for applications that use certain private entry points, 208 * and fail to include <arpa/inet.h>. 209 */ 210#undef inet_addr 211__weak_reference(__inet_addr, inet_addr); 212#undef inet_aton 213__weak_reference(__inet_aton, inet_aton); |
214 215/*! \file */ |
|