summaryrefslogtreecommitdiff
path: root/canohost.c
diff options
context:
space:
mode:
Diffstat (limited to 'canohost.c')
-rw-r--r--canohost.c41
1 files changed, 20 insertions, 21 deletions
diff --git a/canohost.c b/canohost.c
index c27086bfd..6ca60e6b4 100644
--- a/canohost.c
+++ b/canohost.c
@@ -12,7 +12,7 @@
12 */ 12 */
13 13
14#include "includes.h" 14#include "includes.h"
15RCSID("$OpenBSD: canohost.c,v 1.44 2005/06/17 02:44:32 djm Exp $"); 15RCSID("$OpenBSD: canohost.c,v 1.48 2005/12/28 22:46:06 stevesk Exp $");
16 16
17#include "packet.h" 17#include "packet.h"
18#include "xmalloc.h" 18#include "xmalloc.h"
@@ -43,9 +43,6 @@ get_remote_hostname(int sock, int use_dns)
43 cleanup_exit(255); 43 cleanup_exit(255);
44 } 44 }
45 45
46 if (from.ss_family == AF_INET)
47 check_ip_options(sock, ntop);
48
49 ipv64_normalise_mapped(&from, &fromlen); 46 ipv64_normalise_mapped(&from, &fromlen);
50 47
51 if (from.ss_family == AF_INET6) 48 if (from.ss_family == AF_INET6)
@@ -55,6 +52,9 @@ get_remote_hostname(int sock, int use_dns)
55 NULL, 0, NI_NUMERICHOST) != 0) 52 NULL, 0, NI_NUMERICHOST) != 0)
56 fatal("get_remote_hostname: getnameinfo NI_NUMERICHOST failed"); 53 fatal("get_remote_hostname: getnameinfo NI_NUMERICHOST failed");
57 54
55 if (from.ss_family == AF_INET)
56 check_ip_options(sock, ntop);
57
58 if (!use_dns) 58 if (!use_dns)
59 return xstrdup(ntop); 59 return xstrdup(ntop);
60 60
@@ -102,7 +102,7 @@ get_remote_hostname(int sock, int use_dns)
102 hints.ai_socktype = SOCK_STREAM; 102 hints.ai_socktype = SOCK_STREAM;
103 if (getaddrinfo(name, NULL, &hints, &aitop) != 0) { 103 if (getaddrinfo(name, NULL, &hints, &aitop) != 0) {
104 logit("reverse mapping checking getaddrinfo for %.700s " 104 logit("reverse mapping checking getaddrinfo for %.700s "
105 "failed - POSSIBLE BREAKIN ATTEMPT!", name); 105 "failed - POSSIBLE BREAK-IN ATTEMPT!", name);
106 return xstrdup(ntop); 106 return xstrdup(ntop);
107 } 107 }
108 /* Look for the address from the list of addresses. */ 108 /* Look for the address from the list of addresses. */
@@ -117,7 +117,7 @@ get_remote_hostname(int sock, int use_dns)
117 if (!ai) { 117 if (!ai) {
118 /* Address not found for the host name. */ 118 /* Address not found for the host name. */
119 logit("Address %.100s maps to %.600s, but this does not " 119 logit("Address %.100s maps to %.600s, but this does not "
120 "map back to the address - POSSIBLE BREAKIN ATTEMPT!", 120 "map back to the address - POSSIBLE BREAK-IN ATTEMPT!",
121 ntop, name); 121 ntop, name);
122 return xstrdup(ntop); 122 return xstrdup(ntop);
123 } 123 }
@@ -158,9 +158,7 @@ check_ip_options(int sock, char *ipaddr)
158 for (i = 0; i < option_size; i++) 158 for (i = 0; i < option_size; i++)
159 snprintf(text + i*3, sizeof(text) - i*3, 159 snprintf(text + i*3, sizeof(text) - i*3,
160 " %2.2x", options[i]); 160 " %2.2x", options[i]);
161 logit("Connection from %.100s with IP options:%.800s", 161 fatal("Connection from %.100s with IP options:%.800s",
162 ipaddr, text);
163 packet_disconnect("Connection from %.100s with IP options:%.800s",
164 ipaddr, text); 162 ipaddr, text);
165 } 163 }
166#endif /* IP_OPTIONS */ 164#endif /* IP_OPTIONS */
@@ -200,26 +198,27 @@ ipv64_normalise_mapped(struct sockaddr_storage *addr, socklen_t *len)
200const char * 198const char *
201get_canonical_hostname(int use_dns) 199get_canonical_hostname(int use_dns)
202{ 200{
201 char *host;
203 static char *canonical_host_name = NULL; 202 static char *canonical_host_name = NULL;
204 static int use_dns_done = 0; 203 static char *remote_ip = NULL;
205 204
206 /* Check if we have previously retrieved name with same option. */ 205 /* Check if we have previously retrieved name with same option. */
207 if (canonical_host_name != NULL) { 206 if (use_dns && canonical_host_name != NULL)
208 if (use_dns_done != use_dns) 207 return canonical_host_name;
209 xfree(canonical_host_name); 208 if (!use_dns && remote_ip != NULL)
210 else 209 return remote_ip;
211 return canonical_host_name;
212 }
213 210
214 /* Get the real hostname if socket; otherwise return UNKNOWN. */ 211 /* Get the real hostname if socket; otherwise return UNKNOWN. */
215 if (packet_connection_is_on_socket()) 212 if (packet_connection_is_on_socket())
216 canonical_host_name = get_remote_hostname( 213 host = get_remote_hostname(packet_get_connection_in(), use_dns);
217 packet_get_connection_in(), use_dns);
218 else 214 else
219 canonical_host_name = xstrdup("UNKNOWN"); 215 host = "UNKNOWN";
220 216
221 use_dns_done = use_dns; 217 if (use_dns)
222 return canonical_host_name; 218 canonical_host_name = host;
219 else
220 remote_ip = host;
221 return host;
223} 222}
224 223
225/* 224/*