#include "subafn.h"
+#define AFT sizeof(struct in6_addr)
/*
\f
*/
*/
/********************************************************/
/* */
+/* Procedure to set IPNUM mask. */
+/* */
+/********************************************************/
+PUBLIC AFNTYP *afn_maskip(AFNTYP *afnnum,int cidr)
+
+{
+if (afnnum!=(AFNTYP *)0) {
+ unsigned int num;
+ int mxcidr;
+
+ mxcidr=32;
+ if (afnnum->afntype==AF_INET6)
+ mxcidr=128;
+ if (cidr>mxcidr)
+ cidr=mxcidr;
+ afnnum->afnmask=cidr;
+ num=cidr/8;
+ cidr%=8;
+ if (cidr!=0) {
+ afnnum->ip[num]&=(~0U<<(8-cidr));
+ num++;
+ }
+ if (num<AFT)
+ (void) memset(afnnum->ip+num,'\000',AFT-num);
+ }
+return afnnum;
+}
+/*
+\f
+*/
+/********************************************************/
+/* */
/* Procedure to return a string with */
/* ipnum address and MASK in clear format */
/* Address need to freed. */
afnnum=(AFNTYP *)calloc(1,sizeof(AFNTYP));
afnnum->afntype=AF_INET;
afnnum->afnmask=32;
- if (strchr(oneipstr,'|')==(char *)0)
+ if (strchr(oneipstr,':')==(char *)0)
phase++; //This is an IPV4 number
break;
case 1 : //IP is an IPV6 format
break;
case 3 : //lets convert it
afnnum->strnumip=afn_getstrip(afnnum);
- //(void) printf("JMPDBG <%s> -> to <%s>\n", onecleanipstr,afnnum->strnumip);
+ //(void) printf("JMPDBG <%s> -> to <%s>\n",oneipstr,afnnum->strnumip);
break;
default : /*SAFE guard */
proceed=false;
//procedure to free memory used by an AFNTYP structure
extern AFNTYP *afn_freeipnum(AFNTYP *afnnum);
+//procedure to set IPNUM mask
+extern AFNTYP *afn_maskip(AFNTYP *afnnum,int cidr);
+
//procedure to convert a AFNTYP structure to an standardised
//IP number
extern char *afn_stripnum(AFNTYP *afnnum);
break;
case 2 : { //scanning relayable contents
int num;
+ char format[40];
+ char ip[80];
char line[300];
num=0;
+ snprintf(format,sizeof(format),"%%%ld[^/]/%%d",sizeof(ip));
while (fgets(line,sizeof(line)-1,relays)!=(char *)0) {
AFNTYP *afn;
+ int mask;
num++;
(void) rou_clean_conf_line(line);
if (strlen(line)==0)
continue;
- if ((afn=afn_getoneipnum(line))==(AFNTYP *)0) {
+ (void) memset(ip,'\000',sizeof(ip));
+ if (sscanf(line,format,ip,&mask)<1)
+ continue;
+ if ((afn=afn_getoneipnum(ip))==(AFNTYP *)0) {
(void) rou_alert(0,"%s line='%03d' <%s> not a valid IP "
"(error=<%s>, config?)",
OPEP,num,line,strerror(errno));
continue;
}
+ (void) afn_maskip(afn,mask);
list=(AFNTYP **)rou_addlist((void **)list,(void *)afn);
}
}