inet_aton.c (126274) | inet_aton.c (157016) |
---|---|
1/* OPENBSD ORIGINAL: lib/libc/net/inet_addr.c */ | 1/* $OpenBSD: inet_addr.c,v 1.9 2005/08/06 20:30:03 espie Exp $ */ |
2 | 2 |
3/* $OpenBSD: inet_addr.c,v 1.7 2003/06/02 20:18:35 millert Exp $ */ 4 | |
5/* 6 * Copyright (c) 1983, 1990, 1993 7 * The Regents of the University of California. All rights reserved. 8 * 9 * Redistribution and use in source and binary forms, with or without 10 * modification, are permitted provided that the following conditions 11 * are met: 12 * 1. Redistributions of source code must retain the above copyright --- 33 unchanged lines hidden (view full) --- 46 * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR 47 * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS 48 * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS 49 * SOFTWARE. 50 * - 51 * --Copyright-- 52 */ 53 | 3/* 4 * Copyright (c) 1983, 1990, 1993 5 * The Regents of the University of California. All rights reserved. 6 * 7 * Redistribution and use in source and binary forms, with or without 8 * modification, are permitted provided that the following conditions 9 * are met: 10 * 1. Redistributions of source code must retain the above copyright --- 33 unchanged lines hidden (view full) --- 44 * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR 45 * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS 46 * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS 47 * SOFTWARE. 48 * - 49 * --Copyright-- 50 */ 51 |
52/* OPENBSD ORIGINAL: lib/libc/net/inet_addr.c */ 53 |
|
54#include "includes.h" 55 56#if !defined(HAVE_INET_ATON) 57 | 54#include "includes.h" 55 56#if !defined(HAVE_INET_ATON) 57 |
58#if defined(LIBC_SCCS) && !defined(lint) 59#if 0 60static char sccsid[] = "@(#)inet_addr.c 8.1 (Berkeley) 6/17/93"; 61static char rcsid[] = "$From: inet_addr.c,v 8.5 1996/08/05 08:31:35 vixie Exp $"; 62#else 63static char rcsid[] = "$OpenBSD: inet_addr.c,v 1.7 2003/06/02 20:18:35 millert Exp $"; 64#endif 65#endif /* LIBC_SCCS and not lint */ 66 | |
67#include <sys/types.h> 68#include <sys/param.h> 69#include <netinet/in.h> 70#include <arpa/inet.h> 71#include <ctype.h> 72 73#if 0 74/* 75 * Ascii internet address interpretation routine. 76 * The value returned is in network order. 77 */ 78in_addr_t | 58#include <sys/types.h> 59#include <sys/param.h> 60#include <netinet/in.h> 61#include <arpa/inet.h> 62#include <ctype.h> 63 64#if 0 65/* 66 * Ascii internet address interpretation routine. 67 * The value returned is in network order. 68 */ 69in_addr_t |
79inet_addr(cp) 80 register const char *cp; | 70inet_addr(const char *cp) |
81{ 82 struct in_addr val; 83 84 if (inet_aton(cp, &val)) 85 return (val.s_addr); 86 return (INADDR_NONE); 87} 88#endif 89 90/* 91 * Check whether "cp" is a valid ascii representation 92 * of an Internet address and convert to a binary address. 93 * Returns 1 if the address is valid, 0 if not. 94 * This replaces inet_addr, the return value from which 95 * cannot distinguish between failure and a local broadcast address. 96 */ 97int 98inet_aton(const char *cp, struct in_addr *addr) 99{ | 71{ 72 struct in_addr val; 73 74 if (inet_aton(cp, &val)) 75 return (val.s_addr); 76 return (INADDR_NONE); 77} 78#endif 79 80/* 81 * Check whether "cp" is a valid ascii representation 82 * of an Internet address and convert to a binary address. 83 * Returns 1 if the address is valid, 0 if not. 84 * This replaces inet_addr, the return value from which 85 * cannot distinguish between failure and a local broadcast address. 86 */ 87int 88inet_aton(const char *cp, struct in_addr *addr) 89{ |
100 register u_int32_t val; 101 register int base, n; 102 register char c; 103 unsigned int parts[4]; 104 register unsigned int *pp = parts; | 90 u_int32_t val; 91 int base, n; 92 char c; 93 u_int parts[4]; 94 u_int *pp = parts; |
105 106 c = *cp; 107 for (;;) { 108 /* 109 * Collect number up to ``.''. 110 * Values are specified as for C: 111 * 0x=hex, 0=octal, isdigit=decimal. 112 */ --- 77 unchanged lines hidden --- | 95 96 c = *cp; 97 for (;;) { 98 /* 99 * Collect number up to ``.''. 100 * Values are specified as for C: 101 * 0x=hex, 0=octal, isdigit=decimal. 102 */ --- 77 unchanged lines hidden --- |