Deleted Added
sdiff udiff text old ( 123895 ) new ( 146187 )
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 $
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
40extern char *inet_ntoa();
41#endif
42
43/* Local stuff. */
44
45#include "tcpd.h"
46
47/* Forward declarations. */

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

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

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

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

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

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

--- 103 unchanged lines hidden ---