Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/neutrinolabs/xrdp.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBLINDAUER Emmanuel <e.blindauer@gmail.com>2017-11-12 13:27:52 +0300
committerKoichiro IWAO <meta@vmeta.jp>2018-08-02 03:02:07 +0300
commitc61ea8df9e9690b59fd42846f112a7a03f1946fe (patch)
tree1db03d41169b743429a71c6c2755cfda64696842
parent8fc741ea455e0a91d693eaca6a9d47a42eb90647 (diff)
Extract the exact ip from the client_ip
-rw-r--r--sesman/sessionrecord.c22
1 files changed, 21 insertions, 1 deletions
diff --git a/sesman/sessionrecord.c b/sesman/sessionrecord.c
index 4336994f..22dbd3d8 100644
--- a/sesman/sessionrecord.c
+++ b/sesman/sessionrecord.c
@@ -50,6 +50,26 @@ add_xtmp_entry(int pid, const char *line, const char *user, const char *rhostnam
{
_utmp ut;
struct timeval tv;
+ char *hostname = 0;
+
+ /* The string rhostname containt too much data, only get the ip
+ * the format is
+ * "2001:123:12:1234:1234:1234:1234:1234:53194 - socket: 12"
+ * "::ffff:99.99.9.999:51165 - socket: 12"
+ * "99.99.9.999:51165 - socket: 12"
+ *
+ * So the IP is the string up the two last colons
+ */
+ int i = strlen(rhostname) - 1;
+ while ((i>0) && (rhostname[i] != ':')) {
+ i--;
+ }
+ i--;
+ while ((i>0) && (rhostname[i] != ':')) {
+ i--;
+ }
+
+ hostname = strndup(rhostname, i);
memset(&ut, 0, sizeof(ut));
@@ -60,7 +80,7 @@ add_xtmp_entry(int pid, const char *line, const char *user, const char *rhostnam
ut.ut_tv.tv_usec = tv.tv_usec;
strncpy(ut.ut_line, line , sizeof(ut.ut_line));
strncpy(ut.ut_user, user , sizeof(ut.ut_user));
- strncpy(ut.ut_host, rhostname, sizeof(ut.ut_host));
+ strncpy(ut.ut_host, hostname, sizeof(ut.ut_host));
/* utmp */
setutxent();