Deleted Added
full compact
socket.c (123895) socket.c (146187)
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 *
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
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
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),
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);
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),
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);
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),
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);
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 ---
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 ---