+ }
+
+ oldlen = cl->buflen;
+ cl->buflen += lenin;
+
+ for(;;)
+ {
+ cl->reqlen = 0;
+
+ for(i = oldlen; i < cl->buflen; i++)
+ {
+ if(cl->buffer[i] == '\n')
+ {
+ cl->buffer[i] = 0; /* replace end-of-line by end-of-string so we can use sscanf */
+ cl->reqlen = i + 1;
+ break;
+ }
+ }
+
+ if(cl->reqlen)
+ {
+ if(debug_lvl > 2)
+ syslog(LOG_DEBUG, _("Got request from %s (%s): %s"),
+ cl->vpn_hostname, cl->real_hostname, cl->buffer);
+ if(sscanf(cl->buffer, "%d", &request) == 1)
+ {
+ if((request < 0) || (request > 255) || (request_handlers[request] == NULL))
+ {
+ syslog(LOG_ERR, _("Unknown request from %s (%s)"),
+ cl->vpn_hostname, cl->real_hostname);
+ return -1;
+ }
+
+ if(request_handlers[request](cl)) /* Something went wrong. Probably scriptkiddies. Terminate. */
+ {
+ syslog(LOG_ERR, _("Error while processing request from %s (%s)"),
+ cl->vpn_hostname, cl->real_hostname);
+ return -1;
+ }
+ }
+ else
+ {
+ syslog(LOG_ERR, _("Bogus data received from %s (%s)"),
+ cl->vpn_hostname, cl->real_hostname);
+ return -1;
+ }
+
+ cl->buflen -= cl->reqlen;
+ memmove(cl->buffer, cl->buffer + cl->reqlen, cl->buflen);
+ oldlen = 0;
+ }
+ else
+ {
+ break;
+ }
+ }
+
+ cl->last_ping_time = time(NULL);
+ cl->want_ping = 0;