diff options
Diffstat (limited to 'canohost.c')
-rw-r--r-- | canohost.c | 30 |
1 files changed, 26 insertions, 4 deletions
diff --git a/canohost.c b/canohost.c index 4209b6ab8..e61628b77 100644 --- a/canohost.c +++ b/canohost.c | |||
@@ -14,7 +14,7 @@ | |||
14 | */ | 14 | */ |
15 | 15 | ||
16 | #include "includes.h" | 16 | #include "includes.h" |
17 | RCSID("$Id: canohost.c,v 1.4 1999/11/25 00:54:58 damien Exp $"); | 17 | RCSID("$Id: canohost.c,v 1.5 1999/12/13 23:47:15 damien Exp $"); |
18 | 18 | ||
19 | #include "packet.h" | 19 | #include "packet.h" |
20 | #include "xmalloc.h" | 20 | #include "xmalloc.h" |
@@ -143,6 +143,28 @@ check_ip_options: | |||
143 | static char *canonical_host_name = NULL; | 143 | static char *canonical_host_name = NULL; |
144 | static char *canonical_host_ip = NULL; | 144 | static char *canonical_host_ip = NULL; |
145 | 145 | ||
146 | /* Returns 1 if remote host is connected via socket, 0 if not. */ | ||
147 | |||
148 | int | ||
149 | peer_connection_is_on_socket() | ||
150 | { | ||
151 | struct sockaddr_in from; | ||
152 | int fromlen; | ||
153 | int in = packet_get_connection_in(); | ||
154 | int out = packet_get_connection_out(); | ||
155 | |||
156 | /* filedescriptors in and out are the same, so it's a socket */ | ||
157 | if (in == out) | ||
158 | return 1; | ||
159 | fromlen = sizeof(from); | ||
160 | memset(&from, 0, sizeof(from)); | ||
161 | if (getpeername(in, (struct sockaddr *) & from, &fromlen) < 0) | ||
162 | return 0; | ||
163 | if (from.sin_family != AF_INET && from.sin_family != AF_INET6) | ||
164 | return 0; | ||
165 | return 1; | ||
166 | } | ||
167 | |||
146 | /* | 168 | /* |
147 | * Return the canonical name of the host in the other side of the current | 169 | * Return the canonical name of the host in the other side of the current |
148 | * connection. The host name is cached, so it is efficient to call this | 170 | * connection. The host name is cached, so it is efficient to call this |
@@ -157,7 +179,7 @@ get_canonical_hostname() | |||
157 | return canonical_host_name; | 179 | return canonical_host_name; |
158 | 180 | ||
159 | /* Get the real hostname if socket; otherwise return UNKNOWN. */ | 181 | /* Get the real hostname if socket; otherwise return UNKNOWN. */ |
160 | if (packet_get_connection_in() == packet_get_connection_out()) | 182 | if (peer_connection_is_on_socket()) |
161 | canonical_host_name = get_remote_hostname(packet_get_connection_in()); | 183 | canonical_host_name = get_remote_hostname(packet_get_connection_in()); |
162 | else | 184 | else |
163 | canonical_host_name = xstrdup("UNKNOWN"); | 185 | canonical_host_name = xstrdup("UNKNOWN"); |
@@ -181,7 +203,7 @@ get_remote_ipaddr() | |||
181 | return canonical_host_ip; | 203 | return canonical_host_ip; |
182 | 204 | ||
183 | /* If not a socket, return UNKNOWN. */ | 205 | /* If not a socket, return UNKNOWN. */ |
184 | if (packet_get_connection_in() != packet_get_connection_out()) { | 206 | if (!peer_connection_is_on_socket()) { |
185 | canonical_host_ip = xstrdup("UNKNOWN"); | 207 | canonical_host_ip = xstrdup("UNKNOWN"); |
186 | return canonical_host_ip; | 208 | return canonical_host_ip; |
187 | } | 209 | } |
@@ -232,7 +254,7 @@ get_remote_port() | |||
232 | * If the connection is not a socket, return 65535. This is | 254 | * If the connection is not a socket, return 65535. This is |
233 | * intentionally chosen to be an unprivileged port number. | 255 | * intentionally chosen to be an unprivileged port number. |
234 | */ | 256 | */ |
235 | if (packet_get_connection_in() != packet_get_connection_out()) | 257 | if (!peer_connection_is_on_socket()) |
236 | return 65535; | 258 | return 65535; |
237 | 259 | ||
238 | /* Get client socket. */ | 260 | /* Get client socket. */ |