MCPcopy Index your code
hub / github.com/RsyncProject/rsync / client_addr

Function client_addr

clientname.c:55–84  ·  view source on GitHub ↗

Return the IP addr of the client as a string. */

Source from the content-addressed store, hash-verified

53
54/* Return the IP addr of the client as a string. */
55char *client_addr(int fd)
56{
57 struct sockaddr_storage ss;
58 socklen_t length = sizeof ss;
59
60 if (*ipaddr_buf)
61 return ipaddr_buf;
62
63 if (am_daemon < 0) { /* daemon over --rsh mode */
64 char *env_str;
65 strlcpy(ipaddr_buf, "0.0.0.0", sizeof ipaddr_buf);
66 if ((env_str = getenv("REMOTE_HOST")) != NULL
67 || (env_str = getenv("SSH_CONNECTION")) != NULL
68 || (env_str = getenv("SSH_CLIENT")) != NULL
69 || (env_str = getenv("SSH2_CLIENT")) != NULL) {
70 char *p;
71 strlcpy(ipaddr_buf, env_str, sizeof ipaddr_buf);
72 /* Truncate the value to just the IP address. */
73 if ((p = strchr(ipaddr_buf, ' ')) != NULL)
74 *p = '\0';
75 }
76 if (valid_ipaddr(ipaddr_buf, True))
77 return ipaddr_buf;
78 }
79
80 client_sockaddr(fd, &ss, &length);
81 getnameinfo((struct sockaddr *)&ss, length, ipaddr_buf, sizeof ipaddr_buf, NULL, 0, NI_NUMERICHOST);
82
83 return ipaddr_buf;
84}
85
86
87/**

Callers 3

log_formattedFunction · 0.85
rsync_moduleFunction · 0.85
start_daemonFunction · 0.85

Calls 4

strlcpyFunction · 0.85
valid_ipaddrFunction · 0.85
client_sockaddrFunction · 0.85
getnameinfoFunction · 0.85

Tested by

no test coverage detected