summaryrefslogtreecommitdiff
path: root/canohost.c
diff options
context:
space:
mode:
authorBen Lindstrom <mouring@eviladmin.org>2001-04-12 23:34:34 +0000
committerBen Lindstrom <mouring@eviladmin.org>2001-04-12 23:34:34 +0000
commit5eabda303aa26c77e4c383230db9ce9d9175e580 (patch)
treea084d793ff9789b41920bb259c7ff309d21eba24 /canohost.c
parent0998872972ec9a059204344cf0bec64123b3e28c (diff)
- markus@cvs.openbsd.org 2001/04/12 19:15:26
[auth-rhosts.c auth.h auth2.c buffer.c canohost.c canohost.h compat.c compat.h hostfile.c pathnames.h readconf.c readconf.h servconf.c servconf.h ssh.c sshconnect.c sshconnect.h sshconnect1.c sshconnect2.c sshd_config] implement HostbasedAuthentication (= RhostRSAAuthentication for ssh v2) similar to RhostRSAAuthentication unless you enable (the experimental) HostbasedUsesNameFromPacketOnly option. please test. :)
Diffstat (limited to 'canohost.c')
-rw-r--r--canohost.c57
1 files changed, 43 insertions, 14 deletions
diff --git a/canohost.c b/canohost.c
index 927508f58..823545d4c 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.24 2001/04/05 15:48:19 stevesk Exp $"); 15RCSID("$OpenBSD: canohost.c,v 1.25 2001/04/12 19:15:24 markus Exp $");
16 16
17#include "packet.h" 17#include "packet.h"
18#include "xmalloc.h" 18#include "xmalloc.h"
@@ -202,30 +202,59 @@ get_canonical_hostname(int reverse_mapping_check)
202 * Returns the remote IP-address of socket as a string. The returned 202 * Returns the remote IP-address of socket as a string. The returned
203 * string must be freed. 203 * string must be freed.
204 */ 204 */
205
206char * 205char *
207get_peer_ipaddr(int socket) 206get_socket_address(int socket, int remote, int flags)
208{ 207{
209 struct sockaddr_storage from; 208 struct sockaddr_storage addr;
210 socklen_t fromlen; 209 socklen_t addrlen;
211 char ntop[NI_MAXHOST]; 210 char ntop[NI_MAXHOST];
212 211
213 /* Get IP address of client. */ 212 /* Get IP address of client. */
214 fromlen = sizeof(from); 213 addrlen = sizeof(addr);
215 memset(&from, 0, sizeof(from)); 214 memset(&addr, 0, sizeof(addr));
216 if (getpeername(socket, (struct sockaddr *) & from, &fromlen) < 0) { 215
217 debug("get_peer_ipaddr: getpeername failed: %.100s", strerror(errno)); 216 if (remote) {
218 return NULL; 217 if (getpeername(socket, (struct sockaddr *)&addr, &addrlen)
218 < 0) {
219 debug("get_socket_ipaddr: getpeername failed: %.100s",
220 strerror(errno));
221 return NULL;
222 }
223 } else {
224 if (getsockname(socket, (struct sockaddr *)&addr, &addrlen)
225 < 0) {
226 debug("get_socket_ipaddr: getsockname failed: %.100s",
227 strerror(errno));
228 return NULL;
229 }
219 } 230 }
220 /* Get the IP address in ascii. */ 231 /* Get the address in ascii. */
221 if (getnameinfo((struct sockaddr *)&from, fromlen, ntop, sizeof(ntop), 232 if (getnameinfo((struct sockaddr *)&addr, addrlen, ntop, sizeof(ntop),
222 NULL, 0, NI_NUMERICHOST) != 0) { 233 NULL, 0, flags) != 0) {
223 error("get_peer_ipaddr: getnameinfo NI_NUMERICHOST failed"); 234 error("get_socket_ipaddr: getnameinfo %d failed", flags);
224 return NULL; 235 return NULL;
225 } 236 }
226 return xstrdup(ntop); 237 return xstrdup(ntop);
227} 238}
228 239
240char *
241get_peer_ipaddr(int socket)
242{
243 return get_socket_address(socket, 1, NI_NUMERICHOST);
244}
245
246char *
247get_local_ipaddr(int socket)
248{
249 return get_socket_address(socket, 0, NI_NUMERICHOST);
250}
251
252char *
253get_local_name(int socket)
254{
255 return get_socket_address(socket, 0, NI_NAMEREQD);
256}
257
229/* 258/*
230 * Returns the IP-address of the remote host as a string. The returned 259 * Returns the IP-address of the remote host as a string. The returned
231 * string must not be freed. 260 * string must not be freed.