From: Jean-Marc Pigeon (Delson) Date: Sun, 13 Jul 2025 15:05:52 +0000 (-0400) Subject: Calculating the reverss-ip is working X-Git-Tag: tag-0.14~103 X-Git-Url: https://jmp-git.ovh.safe.ca/?a=commitdiff_plain;h=9eaf47bd2be7016dabb3b25de67ad5102c0c6aa1;p=jmp%2Fmailleur Calculating the reverss-ip is working --- diff --git a/app/Makefile b/app/Makefile index c428eb1..1e7fc30 100644 --- a/app/Makefile +++ b/app/Makefile @@ -121,6 +121,7 @@ scarmt.o: scarmt.c \ ../lib/unipar.h \ ../lib/uniprc.h \ ../lib/unisig.h \ + ../lib/subafn.h \ ../lib/subrou.h sender.o: sender.c \ diff --git a/app/scarmt.c b/app/scarmt.c index 9dcbf24..b131a59 100644 --- a/app/scarmt.c +++ b/app/scarmt.c @@ -20,6 +20,7 @@ #include "unipar.h" #include "uniprc.h" #include "unisig.h" +#include "subafn.h" #include "subrou.h" #define SCANNER "scarmt" //application name @@ -38,22 +39,34 @@ static void check_credibility(SQLPTR *sqlptr,char **dnsbls,char *rmtip) #define OPEP "scarmt.c:check_credibilty," SRVTYP *srv; +AFNTYP **afns; +char *reversip; int phase; _Bool proceed; srv=(SRVTYP *)0; +afns=(AFNTYP **)0; +reversip=(char *)0; phase=0; proceed=true; while (proceed==true) { switch (phase) { - case 0 : //loading rmtip record + case 0 : //get the remoteip AFN + if ((afns=afn_getipnum(rmtip))==(AFNTYP **)0) { + (void) rou_alert(0,"%s Unable to get afn data for remote <%s> (WRONG IP?)", + OPEP,rmtip); + phase=999; //Trouble trouble + } + break; + case 1 : //loading rmtip record if (sql_mngremote(sqlptr,sql_select,rmtip,&srv)==false) { (void) rou_alert(0,"%s Unable to get remote <%s> data (database?)", OPEP,rmtip); phase=999; //Trouble trouble } break; - case 1 : //updating record according blacklisting + case 2 : //updating record according blacklisting + reversip=afn_reversipnum(*afns); srv->credit=0; srv->lastscan=time((time_t *)0); if (dnsbls!=(char **)0) { @@ -63,7 +76,7 @@ while (proceed==true) { } } break; - case 2 : //updating record + case 3 : //updating record if (sql_mngremote(sqlptr,sql_update,rmtip,&srv)==false) { (void) rou_alert(0,"%s Unable to update remote <%s> data (database?)", OPEP,rmtip); @@ -76,6 +89,9 @@ while (proceed==true) { phase++; } srv=sql_freesrv(srv); +reversip=rou_freestr(reversip); +afns=(AFNTYP **)rou_freelist((void **)afns,(genfree_t)afn_freeipnum); + #undef OPEP } /* diff --git a/lib/subafn.c b/lib/subafn.c index 0e986a3..a2d2ca9 100644 --- a/lib/subafn.c +++ b/lib/subafn.c @@ -472,6 +472,55 @@ return ipnorm; #undef OPEP } +/* +^L +*/ +/********************************************************/ +/* */ +/* Procedure to return a revers address as */ +/* dynamically alocated memory. */ +/* */ +/********************************************************/ +char *afn_reversipnum(AFNTYP *afnnum) + +{ +char * reversip; + +reversip=(char *)0; +if (afnnum!=(AFNTYP *)0) { + int i; + char revers[200]; + + reversip=strdup(""); + (void) memset(revers,'\000',sizeof(revers)); + switch (afnnum->afntype) { + case AF_INET6 : + for (i=16;i>0;i--) { + char local[20]; + + (void) snprintf(local,sizeof(local),"%x.%x.", + afnnum->ip[i-1]&0xf, + afnnum->ip[i-1]>>4); + (void) strncat(revers,local,sizeof((revers)-1)-strlen(revers)); + } + break; + case AF_INET : + for (i=4;i>0;i--) { + char local[10]; + + (void) snprintf(local,sizeof(local),"%d.",afnnum->ip[i-1]); + (void) strncat(revers,local,(sizeof(revers)-1)-strlen(revers)); + } + break; + default : + (void) snprintf(revers,sizeof(revers),"%d.0.0.0.0.ukn.",afnnum->afntype); + break; + } + reversip=strdup(revers); + } +return reversip; +} + /* ^L */ diff --git a/lib/subafn.h b/lib/subafn.h index e37a49d..bc5a615 100644 --- a/lib/subafn.h +++ b/lib/subafn.h @@ -48,6 +48,9 @@ extern AFNTYP *afn_getaddrinfo(struct addrinfo *rp); //procedure to convert a IP as string to an AFNTYP structure extern AFNTYP **afn_getipnum(char *cleanipstr); +//procedure to 'compute' a reverss-addres from the IP +extern char *afn_reversipnum(AFNTYP *afnnum); + //procedure to compare 2 same class IP according a mask value extern int afn_cmpipnum(AFNTYP *afnnum1,AFNTYP *afnnum2,int mask);