expand_remote_port

Gbp-Pq: Name expand_remote_port
This commit is contained in:
Marco d'Itri 2022-05-14 02:57:49 +08:00 committed by openKylinBot
parent aa8ed4dd41
commit 8eb2bc800a
4 changed files with 31 additions and 0 deletions

22
eval.c
View File

@ -98,6 +98,28 @@ struct host_info *host;
}
}
/* eval_port - return string with the port */
char *eval_port(saddr)
#ifdef INET6
struct sockaddr *saddr;
#else
struct sockaddr_in *saddr;
#endif
{
static char port[16];
if (saddr != 0) {
sprintf(port, "%u",
#ifdef INET6
ntohs(((struct sockaddr_in *)saddr)->sin_port));
#else
ntohs(saddr->sin_port));
#endif
} else {
strcpy(port, "0");
}
return (port);
}
/* eval_client - return string with as much about the client as we know */
char *eval_client(request)

View File

@ -175,6 +175,8 @@ The client (server) host name or address, if the host name is
unavailable.
.IP "%n (%N)"
The client (server) host name (or "unknown" or "paranoid").
.IP "%r (%R)"
The clients (servers) port number (or "0").
.IP %p
The daemon process id.
.IP %s

View File

@ -63,6 +63,8 @@ ABCDEFGHIJKLMNOPQRSTUVWXYZ";
ch == 'n' ? eval_hostname(request->client) :
ch == 'N' ? eval_hostname(request->server) :
ch == 'p' ? eval_pid(request) :
ch == 'r' ? eval_port(request->client->sin) :
ch == 'R' ? eval_port(request->server->sin) :
ch == 's' ? eval_server(request) :
ch == 'u' ? eval_user(request) :
ch == '%' ? "%" : (tcpd_warn("unrecognized %%%c", ch), "");

5
tcpd.h
View File

@ -155,6 +155,11 @@ extern char *eval_hostaddr(struct host_info *); /* printable host address */
extern char *eval_hostinfo(struct host_info *); /* host name or address */
extern char *eval_client(struct request_info *);/* whatever is available */
extern char *eval_server(struct request_info *);/* whatever is available */
#ifdef INET6
extern char *eval_port(struct sockaddr *);
#else
extern char *eval_port(struct sockaddr_in *);
#endif
#define eval_daemon(r) ((r)->daemon) /* daemon process name */
#define eval_pid(r) ((r)->pid) /* process id */