Changeset View
Changeset View
Standalone View
Standalone View
canohost.c
/* $OpenBSD: canohost.c,v 1.73 2016/03/07 19:02:43 djm Exp $ */ | /* $OpenBSD: canohost.c,v 1.74 2019/06/28 13:35:04 deraadt Exp $ */ | ||||
/* | /* | ||||
* Author: Tatu Ylonen <ylo@cs.hut.fi> | * Author: Tatu Ylonen <ylo@cs.hut.fi> | ||||
* Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland | * Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland | ||||
* All rights reserved | * All rights reserved | ||||
* Functions for returning the canonical host name of the remote site. | * Functions for returning the canonical host name of the remote site. | ||||
* | * | ||||
* As far as I am concerned, the code I have written for this software | * As far as I am concerned, the code I have written for this software | ||||
* can be used freely for any purpose. Any derived versions of this | * can be used freely for any purpose. Any derived versions of this | ||||
▲ Show 20 Lines • Show All 149 Lines • ▼ Show 20 Lines | get_sock_port(int sock, int local) | ||||
socklen_t fromlen; | socklen_t fromlen; | ||||
char strport[NI_MAXSERV]; | char strport[NI_MAXSERV]; | ||||
int r; | int r; | ||||
/* Get IP address of client. */ | /* Get IP address of client. */ | ||||
fromlen = sizeof(from); | fromlen = sizeof(from); | ||||
memset(&from, 0, sizeof(from)); | memset(&from, 0, sizeof(from)); | ||||
if (local) { | if (local) { | ||||
if (getsockname(sock, (struct sockaddr *)&from, &fromlen) < 0) { | if (getsockname(sock, (struct sockaddr *)&from, &fromlen) == -1) { | ||||
error("getsockname failed: %.100s", strerror(errno)); | error("getsockname failed: %.100s", strerror(errno)); | ||||
return 0; | return 0; | ||||
} | } | ||||
} else { | } else { | ||||
if (getpeername(sock, (struct sockaddr *)&from, &fromlen) < 0) { | if (getpeername(sock, (struct sockaddr *)&from, &fromlen) == -1) { | ||||
debug("getpeername failed: %.100s", strerror(errno)); | debug("getpeername failed: %.100s", strerror(errno)); | ||||
return -1; | return -1; | ||||
} | } | ||||
} | } | ||||
/* Work around Linux IPv6 weirdness */ | /* Work around Linux IPv6 weirdness */ | ||||
if (from.ss_family == AF_INET6) | if (from.ss_family == AF_INET6) | ||||
fromlen = sizeof(struct sockaddr_in6); | fromlen = sizeof(struct sockaddr_in6); | ||||
Show All 24 Lines |