diff options
Diffstat (limited to 'canohost.c')
-rw-r--r-- | canohost.c | 20 |
1 files changed, 17 insertions, 3 deletions
diff --git a/canohost.c b/canohost.c index 22b19bb9f..ef94d9155 100644 --- a/canohost.c +++ b/canohost.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: canohost.c,v 1.65 2009/05/27 06:31:25 andreas Exp $ */ | 1 | /* $OpenBSD: canohost.c,v 1.66 2010/01/13 01:20:20 dtucker Exp $ */ |
2 | /* | 2 | /* |
3 | * Author: Tatu Ylonen <ylo@cs.hut.fi> | 3 | * Author: Tatu Ylonen <ylo@cs.hut.fi> |
4 | * Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland | 4 | * Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland |
@@ -27,6 +27,7 @@ | |||
27 | #include <stdlib.h> | 27 | #include <stdlib.h> |
28 | #include <string.h> | 28 | #include <string.h> |
29 | #include <stdarg.h> | 29 | #include <stdarg.h> |
30 | #include <unistd.h> | ||
30 | 31 | ||
31 | #include "xmalloc.h" | 32 | #include "xmalloc.h" |
32 | #include "packet.h" | 33 | #include "packet.h" |
@@ -301,9 +302,22 @@ get_local_ipaddr(int sock) | |||
301 | } | 302 | } |
302 | 303 | ||
303 | char * | 304 | char * |
304 | get_local_name(int sock) | 305 | get_local_name(int fd) |
305 | { | 306 | { |
306 | return get_socket_address(sock, 0, NI_NAMEREQD); | 307 | char *host, myname[NI_MAXHOST]; |
308 | |||
309 | /* Assume we were passed a socket */ | ||
310 | if ((host = get_socket_address(fd, 0, NI_NAMEREQD)) != NULL) | ||
311 | return host; | ||
312 | |||
313 | /* Handle the case where we were passed a pipe */ | ||
314 | if (gethostname(myname, sizeof(myname)) == -1) { | ||
315 | verbose("get_local_name: gethostname: %s", strerror(errno)); | ||
316 | } else { | ||
317 | host = xstrdup(myname); | ||
318 | } | ||
319 | |||
320 | return host; | ||
307 | } | 321 | } |
308 | 322 | ||
309 | void | 323 | void |