gods

a simple blocklist for ssh
Log | Files | Refs | README | LICENSE

ip.c (545B)


      1 #include <string.h>
      2 
      3 #include "util.h"
      4 
      5 int
      6 isip(char *s)
      7 {
      8 	char ip[16];
      9 	char *o;
     10 	int n, t;
     11 
     12 	if ((n = strlen(s)) < 7 || n > 15)
     13 		return 0;
     14 
     15 	strcpy(ip, s);
     16 
     17 	o = strtok(ip, ".");
     18 	if (!o)
     19 		return 0;
     20 	if ((t = range(o, 0, 255)) == -1)
     21 		return 0;
     22 
     23 	o = strtok(NULL, ".");
     24 	if (!o)
     25 		return 0;
     26 	if ((t = range(o, 0, 255)) == -1)
     27 		return 0;
     28 
     29 	o = strtok(NULL, ".");
     30 	if (!o)
     31 		return 0;
     32 	if ((t = range(o, 0, 255)) == -1)
     33 		return 0;
     34 
     35 	o = strtok(NULL, ".");
     36 	if (!o)
     37 		return 0;
     38 	if ((t = range(o, 0, 255)) == -1)
     39 		return 0;
     40 
     41 	return 1;
     42 }