Skip to content

Commit

Permalink
Subscribe to bytecount message from management interface
Browse files Browse the repository at this point in the history
Signed-off-by: Selva Nair <[email protected]>
  • Loading branch information
selvanair authored and mattock committed Jan 30, 2018
1 parent dd8c4df commit 105e022
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 0 deletions.
1 change: 1 addition & 0 deletions main.c
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,7 @@ int WINAPI _tWinMain (HINSTANCE hThisInstance,
{ needok, OnNeedOk },
{ needstr, OnNeedStr },
{ echo, OnEcho },
{ bytecount,OnByteCount },
{ 0, NULL }
};
InitManagement(handler);
Expand Down
5 changes: 5 additions & 0 deletions manage.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down
11 changes: 11 additions & 0 deletions openvpn.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}


Expand Down Expand Up @@ -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
*/
Expand Down
1 change: 1 addition & 0 deletions openvpn.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 *);

Expand Down
2 changes: 2 additions & 0 deletions options.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down

0 comments on commit 105e022

Please sign in to comment.