Deleted Added
full compact
1 /*
2 * This module determines the type of socket (datagram, stream), the client
3 * socket address and port, the server socket address and port. In addition,
4 * it provides methods to map a transport address to a printable host name
5 * or address. Socket address information results are in static memory.
6 *
7 * The result from the hostname lookup method is STRING_PARANOID when a host
8 * pretends to have someone elses name, or when a host name is available but
9 * could not be verified.
10 *
11 * When lookup or conversion fails the result is set to STRING_UNKNOWN.
12 *
13 * Diagnostics are reported through syslog(3).
14 *
15 * Author: Wietse Venema, Eindhoven University of Technology, The Netherlands.
16 *
17 * $FreeBSD: head/contrib/tcp_wrappers/socket.c 123895 2003-12-27 14:58:00Z ceri $
17 * $FreeBSD: head/contrib/tcp_wrappers/socket.c 146187 2005-05-13 16:31:11Z ume $
18 */
19
20#ifndef lint
21static char sccsid[] = "@(#) socket.c 1.15 97/03/21 19:27:24";
22#endif
23
24/* System libraries. */
25
26#include <sys/types.h>
27#include <sys/param.h>
28#include <sys/socket.h>
29#include <netinet/in.h>
30#include <netdb.h>
31#include <stdio.h>
32#include <syslog.h>
33#include <string.h>
34
35#ifdef INET6
36#ifndef NI_WITHSCOPEID
37#define NI_WITHSCOPEID 0
38#endif
39#else
35#ifndef INET6
36extern char *inet_ntoa();
37#endif
38
39/* Local stuff. */
40
41#include "tcpd.h"
42
43/* Forward declarations. */

--- 106 unchanged lines hidden (view full) ---

150 return;
151#ifdef SIN6_LEN
152 salen = sin->sa_len;
153#else
154 salen = (sin->sa_family == AF_INET) ? sizeof(struct sockaddr_in)
155 : sizeof(struct sockaddr_in6);
156#endif
157 getnameinfo(sin, salen, host->addr, sizeof(host->addr),
162 NULL, 0, NI_NUMERICHOST | NI_WITHSCOPEID);
158 NULL, 0, NI_NUMERICHOST);
159#else
160 struct sockaddr_in *sin = host->sin;
161
162 if (sin != 0)
163 STRN_CPY(host->addr, inet_ntoa(sin->sin_addr), sizeof(host->addr));
164#endif
165}
166

--- 35 unchanged lines hidden (view full) ---

202 alen = sizeof(struct in6_addr);
203 salen = sizeof(struct sockaddr_in6);
204 break;
205 default:
206 break;
207 }
208 if (ap)
209 err = getnameinfo(sin, salen, hname, sizeof(hname),
214 NULL, 0, NI_WITHSCOPEID | NI_NAMEREQD);
210 NULL, 0, NI_NAMEREQD);
211 }
212 if (!err) {
213
214 STRN_CPY(host->name, hname, sizeof(host->name));
215
216 /* reject numeric addresses */
217 memset(&hints, 0, sizeof(hints));
218 hints.ai_family = sin->sa_family;

--- 88 unchanged lines hidden (view full) ---

307
308 /*
309 * The host name does not map to the initial address. Perhaps
310 * someone has messed up. Perhaps someone compromised a name
311 * server.
312 */
313
314 getnameinfo(sin, salen, hname, sizeof(hname),
319 NULL, 0, NI_NUMERICHOST | NI_WITHSCOPEID);
315 NULL, 0, NI_NUMERICHOST);
316 tcpd_warn("host name/address mismatch: %s != %.*s",
317 hname, STRING_LENGTH,
318 (res0->ai_canonname == NULL) ? "" : res0->ai_canonname);
319 }
320 strcpy(host->name, paranoid); /* name is bad, clobber it */
321 if (res0)
322 freeaddrinfo(res0);
323 }

--- 103 unchanged lines hidden ---