diff --git a/main.c b/main.c index be3a63c..21e22bf 100644 --- a/main.c +++ b/main.c @@ -168,6 +168,7 @@ int WINAPI _tWinMain (HINSTANCE hThisInstance, { needok, OnNeedOk }, { needstr, OnNeedStr }, { echo, OnEcho }, + { bytecount,OnByteCount }, { 0, NULL } }; InitManagement(handler); diff --git a/manage.c b/manage.c index 37cbef4..5489258 100644 --- a/manage.c +++ b/manage.c @@ -327,6 +327,11 @@ OnManagement(SOCKET sk, LPARAM lParam) if (rtmsg_handler[echo]) rtmsg_handler[echo](c, pos + 5); } + else if (strncmp(pos, "BYTECOUNT:", 10) == 0) + { + if (rtmsg_handler[bytecount]) + rtmsg_handler[bytecount](c, pos + 10); + } } else if (c->manage.cmd_queue) { diff --git a/openvpn.c b/openvpn.c index 8b8314a..ba12456 100644 --- a/openvpn.c +++ b/openvpn.c @@ -123,6 +123,7 @@ OnReady(connection_t *c, UNUSED char *msg) ManagementCommand(c, "state on", NULL, regular); ManagementCommand(c, "log all on", OnLogLine, combined); ManagementCommand(c, "echo all on", OnEcho, combined); + ManagementCommand(c, "bytecount 5", NULL, regular); } @@ -1157,6 +1158,16 @@ OnStop(connection_t *c, UNUSED char *msg) } } +/* + * Handle bytecount report from OpenVPN + * Expect bytes-in,bytes-out + */ +void OnByteCount(connection_t *c, char *msg) +{ + if (!msg || sscanf(msg, "%I64u,%I64u", &c->bytes_in, &c->bytes_out) != 2) + return; +} + /* * Break a long line into shorter segments */ diff --git a/openvpn.h b/openvpn.h index f1d6860..e39cab7 100644 --- a/openvpn.h +++ b/openvpn.h @@ -39,6 +39,7 @@ void OnStop(connection_t *, char *); void OnNeedOk(connection_t *, char *); void OnNeedStr(connection_t *, char *); void OnEcho(connection_t *, char *); +void OnByteCount(connection_t *, char *); void ResetSavePasswords(connection_t *); diff --git a/options.h b/options.h index 3bb1730..c31250c 100644 --- a/options.h +++ b/options.h @@ -126,6 +126,8 @@ struct connection { HWND hwndStatus; int flags; char *dynamic_cr; /* Pointer to buffer for dynamic challenge string received */ + unsigned long long int bytes_in; + unsigned long long int bytes_out; }; /* All options used within OpenVPN GUI */