return status;
}
-/*******************************************************************
- Return the IP addr of the remote end of a socket as a string.
- Optionally return the struct sockaddr_storage.
- ******************************************************************/
-
-static const char *get_peer_addr_internal(int fd,
- char *addr_buf,
- size_t addr_buf_len,
- struct sockaddr *pss,
- socklen_t *plength)
-{
- struct sockaddr_storage ss;
- socklen_t length = sizeof(ss);
-
- strlcpy(addr_buf,"0.0.0.0",addr_buf_len);
-
- if (fd == -1) {
- return addr_buf;
- }
-
- if (pss == NULL) {
- pss = (struct sockaddr *)&ss;
- plength = &length;
- }
-
- if (getpeername(fd, (struct sockaddr *)pss, plength) < 0) {
- int level = (errno == ENOTCONN) ? 2 : 0;
- DEBUG(level, ("getpeername failed. Error was %s\n",
- strerror(errno)));
- return addr_buf;
- }
-
- print_sockaddr_len(addr_buf,
- addr_buf_len,
- pss,
- *plength);
- return addr_buf;
-}
-
/*******************************************************************
Matchname - determine if host name matches IP address. Used to
confirm a hostname lookup to prevent spoof attacks.
Return the IP addr of the remote end of a socket as a string.
******************************************************************/
-const char *get_peer_addr(int fd, char *addr, size_t addr_len)
+const char *get_peer_addr(int fd, struct ssaddr_buf *buf)
{
- return get_peer_addr_internal(fd, addr, addr_len, NULL, NULL);
+ struct samba_sockaddr addr = {
+ .sa_socklen = sizeof(struct sockaddr_storage),
+ };
+ int ret;
+
+ (void)strlcpy(buf->buf, "0.0.0.0", sizeof(buf->buf));
+
+ if (fd == -1) {
+ return buf->buf;
+ }
+
+ ret = getpeername(fd, &addr.u.sa, &addr.sa_socklen);
+ if (ret == -1) {
+ int level = (errno == ENOTCONN) ? 2 : 0;
+ DEBUG(level, ("getpeername failed. Error was %s\n",
+ strerror(errno)));
+ return buf->buf;
+ }
+
+ return ssaddr_str_buf(&addr, buf);
}
int get_remote_hostname(const struct tsocket_address *remote_address,
status = read_smb_length_return_keepalive(fd, inbuf, timeout,
len);
if (!NT_STATUS_IS_OK(status)) {
- char addr[INET6_ADDRSTRLEN];
+ struct ssaddr_buf buf;
/* Try and give an error message
* saying what client failed. */
- DEBUG(0, ("read_smb_length_return_keepalive failed for "
- "client %s read error = %s.\n",
- get_peer_addr(fd,addr,sizeof(addr)),
- nt_errstr(status)));
+ DBG_ERR("read_smb_length_return_keepalive failed for "
+ "client %s read error = %s.\n",
+ get_peer_addr(fd, &buf),
+ nt_errstr(status));
return status;
}
status = read_fd_with_timeout(fd, buffer, len, len, timeout, NULL);
if (!NT_STATUS_IS_OK(status)) {
- char addr[INET6_ADDRSTRLEN];
- DEBUG(0, ("read_fd_with_timeout failed for client %s read "
- "error = %s.\n",
- get_peer_addr(fd, addr, sizeof(addr)),
- nt_errstr(status)));
+ struct ssaddr_buf buf;
+ DBG_ERR("read_fd_with_timeout failed for client %s read "
+ "error = %s.\n",
+ get_peer_addr(fd, &buf),
+ nt_errstr(status));
}
return status;
}