realhostname.c (116344) | realhostname.c (121193) |
---|---|
1/*- 2 * Copyright (c) 1999 Brian Somers <brian@Awfulhak.org> 3 * 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 --- 11 unchanged lines hidden (view full) --- 20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24 * SUCH DAMAGE. 25 */ 26 27#include <sys/cdefs.h> | 1/*- 2 * Copyright (c) 1999 Brian Somers <brian@Awfulhak.org> 3 * 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 --- 11 unchanged lines hidden (view full) --- 20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24 * SUCH DAMAGE. 25 */ 26 27#include <sys/cdefs.h> |
28__FBSDID("$FreeBSD: head/lib/libutil/realhostname.c 116344 2003-06-14 18:42:37Z markm $"); | 28__FBSDID("$FreeBSD: head/lib/libutil/realhostname.c 121193 2003-10-18 10:04:16Z markm $"); |
29 30#include <sys/param.h> 31#include <sys/socket.h> 32 33#include <netdb.h> 34#include <netinet/in.h> 35#include <arpa/inet.h> 36 --- 16 unchanged lines hidden (view full) --- 53int 54realhostname(char *host, size_t hsize, const struct in_addr *ip) 55{ 56 char trimmed[MAXHOSTNAMELEN]; 57 int result; 58 struct hostent *hp; 59 60 result = HOSTNAME_INVALIDADDR; | 29 30#include <sys/param.h> 31#include <sys/socket.h> 32 33#include <netdb.h> 34#include <netinet/in.h> 35#include <arpa/inet.h> 36 --- 16 unchanged lines hidden (view full) --- 53int 54realhostname(char *host, size_t hsize, const struct in_addr *ip) 55{ 56 char trimmed[MAXHOSTNAMELEN]; 57 int result; 58 struct hostent *hp; 59 60 result = HOSTNAME_INVALIDADDR; |
61 hp = gethostbyaddr((char *)ip, sizeof(*ip), AF_INET); | 61 hp = gethostbyaddr((const char *)ip, sizeof(*ip), AF_INET); |
62 63 if (hp != NULL) { 64 strlcpy(trimmed, hp->h_name, sizeof(trimmed)); 65 trimdomain(trimmed, strlen(trimmed)); 66 if (strlen(trimmed) <= hsize) { 67 char lookup[MAXHOSTNAMELEN]; 68 69 strncpy(lookup, hp->h_name, sizeof(lookup) - 1); --- 19 unchanged lines hidden (view full) --- 89 return result; 90} 91 92int 93realhostname_sa(char *host, size_t hsize, struct sockaddr *addr, int addrlen) 94{ 95 int result, error; 96 char buf[NI_MAXHOST]; | 62 63 if (hp != NULL) { 64 strlcpy(trimmed, hp->h_name, sizeof(trimmed)); 65 trimdomain(trimmed, strlen(trimmed)); 66 if (strlen(trimmed) <= hsize) { 67 char lookup[MAXHOSTNAMELEN]; 68 69 strncpy(lookup, hp->h_name, sizeof(lookup) - 1); --- 19 unchanged lines hidden (view full) --- 89 return result; 90} 91 92int 93realhostname_sa(char *host, size_t hsize, struct sockaddr *addr, int addrlen) 94{ 95 int result, error; 96 char buf[NI_MAXHOST]; |
97 struct sockaddr_in sin; | 97 struct sockaddr_in lsin; |
98 99 result = HOSTNAME_INVALIDADDR; 100 101#ifdef INET6 102 /* IPv4 mapped IPv6 addr consideraton, specified in rfc2373. */ 103 if (addr->sa_family == AF_INET6 && 104 addrlen == sizeof(struct sockaddr_in6) && 105 IN6_IS_ADDR_V4MAPPED(&((struct sockaddr_in6 *)addr)->sin6_addr)) { 106 struct sockaddr_in6 *sin6; 107 108 sin6 = (struct sockaddr_in6 *)addr; 109 | 98 99 result = HOSTNAME_INVALIDADDR; 100 101#ifdef INET6 102 /* IPv4 mapped IPv6 addr consideraton, specified in rfc2373. */ 103 if (addr->sa_family == AF_INET6 && 104 addrlen == sizeof(struct sockaddr_in6) && 105 IN6_IS_ADDR_V4MAPPED(&((struct sockaddr_in6 *)addr)->sin6_addr)) { 106 struct sockaddr_in6 *sin6; 107 108 sin6 = (struct sockaddr_in6 *)addr; 109 |
110 memset(&sin, 0, sizeof(sin)); 111 sin.sin_len = sizeof(struct sockaddr_in); 112 sin.sin_family = AF_INET; 113 sin.sin_port = sin6->sin6_port; 114 memcpy(&sin.sin_addr, &sin6->sin6_addr.s6_addr[12], | 110 memset(&lsin, 0, sizeof(lsin)); 111 lsin.sin_len = sizeof(struct sockaddr_in); 112 lsin.sin_family = AF_INET; 113 lsin.sin_port = sin6->sin6_port; 114 memcpy(&lsin.sin_addr, &sin6->sin6_addr.s6_addr[12], |
115 sizeof(struct in_addr)); | 115 sizeof(struct in_addr)); |
116 addr = (struct sockaddr *)&sin; 117 addrlen = sin.sin_len; | 116 addr = (struct sockaddr *)&lsin; 117 addrlen = lsin.sin_len; |
118 } 119#endif 120 121 error = getnameinfo(addr, addrlen, buf, sizeof(buf), NULL, 0, 122 NI_WITHSCOPEID | NI_NAMEREQD); 123 if (error == 0) { 124 struct addrinfo hints, *res, *ores; 125 struct sockaddr *sa; --- 66 unchanged lines hidden --- | 118 } 119#endif 120 121 error = getnameinfo(addr, addrlen, buf, sizeof(buf), NULL, 0, 122 NI_WITHSCOPEID | NI_NAMEREQD); 123 if (error == 0) { 124 struct addrinfo hints, *res, *ores; 125 struct sockaddr *sa; --- 66 unchanged lines hidden --- |