bb2d391712fb0208347ffc0b88abe146df14dc0a
galt
  Fri Jun 21 18:21:50 2019 -0700
Adding Support for CIDR specification of subnets, e.g. 192.168.1.255/31. It still supports the older subnet format too, e.g. 192.168

diff --git src/weblet/bottleneck/bottleneck.c src/weblet/bottleneck/bottleneck.c
index fab55c6..59df59c 100644
--- src/weblet/bottleneck/bottleneck.c
+++ src/weblet/bottleneck/bottleneck.c
@@ -2,51 +2,52 @@
 #include "common.h"
 #include <sys/wait.h>
 #include "localmem.h"
 #include "linefile.h"
 #include "hash.h"
 #include "options.h"
 #include "portable.h"
 #include "internet.h"
 #include "net.h"
 
 
 int port = 17776;	/* Default bottleneck port. */
 char *host = "localhost";   /* Default host. */
 int penalty = 75;	    /* Penalty in milliseconds per access. */
 int recovery = 10;	    /* Recovery in milliseconds per second. */
-char *subnet = NULL;        /* Subnet as dotted quads. */
+struct cidr *subnet = NULL;        /* Subnet as CIDR struct. */
 
 void usage()
 /* Explain usage and exit. */
 {
 errAbort(
   "bottleneck v2 - A server that helps slow down hyperactive web robots\n"
   "usage:\n"
   "   bottleneck start\n"
   "Start up bottleneck server\n"
   "   bottleneck query ip-address [count] [fraction]\n"
   "Ask bottleneck server how long to wait to service ip-address after imposing\n"
   "the specified fraction of the access penalty (default of 1.0)\n"
   "   bottleneck list\n"
   "List accessing sites\n"
   "   bottleneck set ip-address milliseconds\n"
   "Set current delay for given ip-address\n"
   "options:\n"
   "   -port=XXXX - Use specific tcp/ip port. Default %d.\n"
   "   -host=XXXXX - Use specific host.  Default %s.\n"
-  "   -subnet=WWW.XXX.YYY.ZZZ Restrict access to subnet (example 192.168.255.255)\n"
+  "   -subnet=WWW.XXX.YYY.ZZZ Restrict access to subnet (example 192.168.255.255).\n"
+  "      Also accepts CIDR notation example 192.168.255.255/16\n"
   "   -penalty=N - Penalty (in milliseconds) for each access, default %d\n"
   "   -recovery=N - Amount to recover (in milliseconds) for each second\n"
   "                 between accesses.  Default %d\n"
   "Note: penalty and recovery if moved from defaults should balance\n"
   "At the default settings, an equilibrium will be achieved when queries\n"
   "are spaced 7.5 seconds apart.  At the default decay value, an accumulated\n"
   "delay of 15 seconds will take 25 minutes of idleness to decay back to zero.\n"
   , port, host, penalty, recovery
   );
 }
 
 static struct optionSpec options[] = {
    {"port", OPTION_INT},
    {"host", OPTION_STRING},
    {"subnet", OPTION_STRING},
@@ -137,43 +138,37 @@
 if (fork() == 0)
     {
     returnList(socket);
     exit(0);
     }
 else
     {
     clearZombies();
     }
 }
 
 void startServer()
 /* Start up bottleneck server. */
 {
 int acceptor;
-unsigned char parsedSubnetBuf[4];	/* Buffer for holding parsed subnet. */
-unsigned char *parsedSubnet = NULL;	/* Parsed subnet. */
-if (subnet != NULL)
-    {
-    internetParseDottedQuad(subnet, parsedSubnetBuf);
-    parsedSubnet = parsedSubnetBuf;
-    }
+subnet = internetParseSubnetCidr(optionVal("subnet", NULL));
 trackerHash = newHash(18);
 acceptor = netAcceptingSocket(port, 64);
 for (;;)
     {
     struct tracker *tracker;
-    int socket = netAcceptFrom(acceptor, parsedSubnet);
+    int socket = netAcceptFrom(acceptor, subnet);
     char buf[256], *s;
     s = netGetString(socket, buf);
     if (s != NULL)
 	{
 	now = time(NULL);
 	if (s[0] == '?')
 	    {
 	    if (s[1] == 0)
 		forkOutList(socket);
 	    else
 	        {
 		char *command = nextWord(&s);
 		if (sameString(command, "?set"))
 		    {
 		    char *ip = nextWord(&s);
@@ -268,31 +263,30 @@
     }
 close(socket);
 }
 
 int main(int argc, char *argv[])
 /* Process command line. */
 {
 char *command;
 optionInit(&argc, argv, options);
 if (argc < 2)
     usage();
 port = optionInt("port", port);
 host = optionVal("host", host);
 penalty = optionInt("penalty", penalty);
 recovery = optionInt("recovery", recovery);
-subnet = optionVal("subnet", subnet);
 command = argv[1];
 if (sameString(command, "start"))
     {
     if (argc != 2)
         usage();
     forkOffServer();
     }
 else if (sameString(command, "query"))
     {
     int count = 1;
     if (argc > 3)
 	count = atoi(argv[3]);
     double fraction = 1.0;
     if (argc > 4)
     fraction = atof(argv[4]);