*/
/********************************************************/
/* */
-/* Procedure to transforme ONE clean IP to an AFN */
-/* structure. */
-/* */
-/********************************************************/
-static AFNTYP *getoneafn(char *onecleanipstr)
-
-{
-#define OPEP "subafn.c:getoneanf,"
-#define ZIPV4 "0.0.0.0"
-
-AFNTYP *afnnum;
-int phase;
-int proceed;
-
-afnnum=(AFNTYP *)0;
-phase=0;
-proceed=true;
-while (proceed==true) {
-#ifdef JMPDBG
- (void) fprintf(stderr,"%s DEBUGING phase='%d', onecleanipstr=<%s>\n",
- OPEP,phase,onecleanipstr);
-#endif
- switch (phase) {
- case 0 : /*lets say ip format ok */
- afnnum=(AFNTYP *)calloc(1,sizeof(AFNTYP));
- afnnum->afntype=AF_INET;
- afnnum->afnmask=32;
- if (strchr(onecleanipstr,'|')==(char *)0)
- phase++; //This is an IPV4 number
- break;
- case 1 : //IP is an IPV6 format
- if (strcasestr(onecleanipstr,STRIPV6)==onecleanipstr)
- onecleanipstr+=strlen(STRIPV6);
- afnnum->afntype=AF_INET6;
- afnnum->afnmask=128;
- break;
- case 2 : //lets convert it
- switch (inet_pton(afnnum->afntype,onecleanipstr,afnnum->ip)) {
- case 1 : //success
- break;
- case 0 : //Invalid IP number
- (void) fprintf(stderr,"Unable to convert IP <%s> (Invalid IP number)\n",
- onecleanipstr);
- afnnum=afn_freeipnum(afnnum);
- phase=999; //no need to go further
- break;
- case -1 : //Invalid IP number
- (void) fprintf(stderr,"Unable to convert IP <%s> (error=<%s>)\n",
- onecleanipstr,strerror(errno));
- afnnum=afn_freeipnum(afnnum);
- phase=999; //no need to go further
- break;
- default : //Unexpected Result
- (void) fprintf(stderr,"Unexpected status to convert IP <%s> "
- "(error=<%s> BUG!?)\n",
- onecleanipstr,strerror(errno));
- afnnum=afn_freeipnum(afnnum);
- phase=999; //no need to go further
- }
- break;
- case 3 : //lets convert it
- afnnum->strnumip=afn_getstrip(afnnum);
- //(void) printf("JMPDBG <%s> -> to <%s>\n", onecleanipstr,afnnum->strnumip);
- break;
- default : /*SAFE guard */
- proceed=false;
- break;
- }
- phase++;
- }
-return afnnum;
-
-#undef OPEP
-}
-/*
-\f
-*/
-/********************************************************/
-/* */
/* Routine to fee memory used by an AFNTYP */
/* */
/********************************************************/
*/
/********************************************************/
/* */
-/* Routine to convert clean string to be */
-/* IP number in AFNTYP structure. */
+/* Procedure to transforme ONE clean IP to an AFN */
+/* structure. */
/* */
/********************************************************/
-PUBLIC AFNTYP **afn_getipnum(char *cleanipstr)
+PUBLIC AFNTYP *afn_getoneipnum(char *oneipstr)
{
-#define OPEP "subafn.c:afn_getipnum"
+#define OPEP "subafn.c:afn_getoneipnum,"
+#define ZIPV4 "0.0.0.0"
+
+AFNTYP *afnnum;
+int phase;
+int proceed;
+
+afnnum=(AFNTYP *)0;
+phase=0;
+proceed=true;
+while (proceed==true) {
+ (void) fprintf(stderr,"%s JMPDBG DEBUGING phase='%d', oneipstr=<%s>\n",
+ OPEP,phase,oneipstr);
+ switch (phase) {
+ case 0 : /*lets say ip format ok */
+ afnnum=(AFNTYP *)calloc(1,sizeof(AFNTYP));
+ afnnum->afntype=AF_INET;
+ afnnum->afnmask=32;
+ if (strchr(oneipstr,'|')==(char *)0)
+ phase++; //This is an IPV4 number
+ break;
+ case 1 : //IP is an IPV6 format
+ if (strcasestr(oneipstr,STRIPV6)==oneipstr)
+ oneipstr+=strlen(STRIPV6);
+ afnnum->afntype=AF_INET6;
+ afnnum->afnmask=128;
+ break;
+ case 2 : //lets convert it
+ switch (inet_pton(afnnum->afntype,oneipstr,afnnum->ip)) {
+ case 1 : //success
+ break;
+ case 0 : //Invalid IP number
+ (void) fprintf(stderr,"Unable to convert IP <%s> (Invalid IP number)\n",
+ oneipstr);
+ afnnum=afn_freeipnum(afnnum);
+ phase=999; //no need to go further
+ break;
+ case -1 : //Invalid IP number
+ (void) fprintf(stderr,"Unable to convert IP <%s> (error=<%s>)\n",
+ oneipstr,strerror(errno));
+ afnnum=afn_freeipnum(afnnum);
+ phase=999; //no need to go further
+ break;
+ default : //Unexpected Result
+ (void) fprintf(stderr,"Unexpected status to convert IP <%s> "
+ "(error=<%s> BUG!?)\n",
+ oneipstr,strerror(errno));
+ afnnum=afn_freeipnum(afnnum);
+ phase=999; //no need to go further
+ }
+ break;
+ case 3 : //lets convert it
+ afnnum->strnumip=afn_getstrip(afnnum);
+ //(void) printf("JMPDBG <%s> -> to <%s>\n", onecleanipstr,afnnum->strnumip);
+ break;
+ default : /*SAFE guard */
+ proceed=false;
+ break;
+ }
+ phase++;
+ }
+return afnnum;
+
+#undef OPEP
+}
+/*
+\f
+*/
+/********************************************************/
+/* */
+/* Routine to convert clean string list to an */
+/* IP number in AFNTYP list. */
+/* */
+/********************************************************/
+PUBLIC AFNTYP **afn_getipnums(char *seqipstr)
+
+{
+#define OPEP "subafn.c:afn_getipnums"
#define ZIPV4 "0.0.0.0"
AFNTYP **afnlist;
while (proceed==true) {
switch (phase) {
case 0 : //Do we have an IP string
- if (cleanipstr==(char *)0) {
+ if (seqipstr==(char *)0) {
(void) fprintf(stderr,"%s No ip provided (bug?)\n",OPEP);
phase=999; //No need to go further
}
break;
case 1 : //checking '0' situation
- if (strcmp(cleanipstr,"0")==0)
- cleanipstr=ZIPV4;
+ if (strcmp(seqipstr,"0")==0)
+ seqipstr=ZIPV4;
break;
case 2 : //checking '0' situation
- iplist=strdup(cleanipstr);
+ iplist=strdup(seqipstr);
if (strcmp(iplist,ZIPV4)==0) {
(void) free(iplist);
iplist=getlocalipstr();
*next='\000';
next++;
}
- if ((afnloc=getoneafn(ptr))!=(AFNTYP *)0) {
+ if ((afnloc=afn_getoneipnum(ptr))!=(AFNTYP *)0) {
afnlist=(AFNTYP **)realloc(afnlist,(num+2)*sizeof(AFNTYP *));
afnlist[num]=afnloc;
num++;
afnnum->ip[14],afnnum->ip[15]);
break;
default :
- (void) fprintf(stderr,"%s, unable to fin IP type (bug?)",OPEP);
+ (void) fprintf(stderr,"%s, unable to find IP type (bug?)",OPEP);
}
}
if (strlen(buffer)>0)
}
return areequal;
}
+/*
+^L
+*/
+/********************************************************/
+/* */
+/* Procedure to check if a remote IP is part of */
+/* acceptable to be relayed list. */
+/* */
+/********************************************************/
+PUBLIC _Bool afn_ip_rlylist(char *iptocheck,AFNTYP **list)
+
+{
+#define OPEP "subafn.c:afn_ip_inlist,"
+
+_Bool isok;
+AFNTYP *afn;
+int phase;
+_Bool proceed;
+
+isok=false;
+afn=(AFNTYP *)0;
+phase=0;
+proceed=false;
+while (proceed==true) {
+ switch (phase) {
+ case 0 : //converting IP
+ if ((afn=afn_getoneipnum(iptocheck))==(AFNTYP *)0) {
+ (void) fprintf(stderr,"%s, Unable to convert IP=<%s> (bug?)",
+ OPEP,iptocheck);
+ phase=999;
+ }
+ break;
+ case 1 : //do we have a list
+ if (list==(AFNTYP **)0)
+ phase=999; //No need to go further
+ break;
+ case 2 : //do we have a list
+ while (*list!=(AFNTYP *)0) {
+ list++;
+ }
+ break;
+ default : //SAFE Guard
+ proceed=false;
+ break;
+ }
+ phase++;
+ }
+return isok;
+
+#undef OPEP
+}