#include <openssl/x509.h>
#include <openssl/x509v3.h>
#include <sys/socket.h>
+#include <ifaddrs.h>
#include <netdb.h>
#include <poll.h>
#include <signal.h>
*/
/********************************************************/
/* */
-/* Procedure to parse an the SMTPPORTS env variable*/
+/* Procedure to the system interrace and build */
+/* a list of local IPV4 interface available */
/* and build the LISTYP structure. */
/* */
/********************************************************/
{
#define OPEP "unitls.c,buildafns,"
-#define DIP "0.0.0.0" //listening on all PORT
-#define DPORT "25" //Default SMTP port
-char *data;
+char *localip;
+struct ifaddrs *ifaddr;
int phase;
_Bool proceed;
-data=(char *)0;
+localip=strdup("");
+afns=(AFNTYP **)0;
+ifaddr=(struct ifaddrs *)0;
phase=0;
proceed=true;
while (proceed==true) {
switch (phase) {
- case 0 : //Getting the SMTPPORTS variable
- if ((data=getenv("SMTPPORTS"))==(char *)0)
- data="smtp:0.0.0.0:25:2"; //default configuration
- data=strdup(data);
- break;
- case 1 : //scanning sequence
- char *ips;
- char *seq;
-
- ips=strdup("");
- seq=data;
- while (seq!=(char *)0) {
- char *ptr;
-
- if ((ptr=strchr(seq,','))!=(char *)0) {
- *ptr='\000';
- ptr++;
- }
- for (int j=0;(j<3)&&(seq!=(char *)0);j++) {
- char *sofar;
-
- if ((sofar=strchr(seq,':'))!=(char *)0) {
- *sofar='\000';
- sofar++;
- }
- switch (j) {
- case 0 : //extracting protocol
- //forget about protocol
- break;
- case 1 :
- int taille;
- char *ip;
- char *newips;
-
- ip=seq;
- if (strlen(ip)==0)
- ip=DIP;
- taille=strlen(ips)+strlen(ip)+2;
- newips=(char *)calloc(taille,sizeof(char));
- (void) strcpy(newips,ips);
- ips=rou_freestr(ips);
- ips=newips;
- if (strlen(ip)>0)
- (void) strcat(ips,",");
- (void) strcat(ips,ip);
- break;
- case 2 :
- //forget about port and itreations
- break;
- }
- seq=sofar;
+ case 0 : //Get the interface list
+ if (getifaddrs(&ifaddr)<0) {
+ (void) rou_alert(0,"%s Unable to get local IP (error=<%s> system?)",
+ OPEP,strerror(errno));
+ phase=999; //no need to go further
+ }
+ break;
+ case 1 : //Scan interface lis
+ for (struct ifaddrs *ifa=ifaddr;ifa!=(struct ifaddrs *)0;ifa=ifa->ifa_next) {
+ int family;
+ int taille;
+ int er;
+ char *newloc;
+ char host[NI_MAXHOST];
+
+ if (ifa->ifa_addr==(struct sockaddr *)0)
+ continue;
+ family=ifa->ifa_addr->sa_family;
+ switch (family) {
+ case AF_INET :
+ taille=sizeof(struct sockaddr_in);
+ break;
+ case AF_INET6 :
+ taille=sizeof(struct sockaddr_in6);
+ continue; //No scanning for IPV6 Number (Jun 2025)
+ break;
+ default :
+ continue;
+ break;
+ }
+ er=getnameinfo(ifa->ifa_addr,taille,host,NI_MAXHOST,NULL,0,NI_NUMERICHOST);
+ if (er!=0) {
+ (void) rou_alert(0,"%s etnameinfo() failed: (error=<%s> system?)",
+ OPEP,strerror(errno));
+ continue;
+ }
+ newloc=(char *)calloc(strlen(localip)+strlen(host)+3,sizeof(char));
+ if (strlen(localip)>0) {
+ (void) strcpy(newloc,localip);
+ (void) strcat(newloc,",");
}
- seq=ptr;
+ (void) rou_alert(0,"JMPDBG adding local IP <%s>",host);
+ (void) strcat(newloc,host);
+ (void) free(localip);
+ localip=newloc;
}
- afns=afn_getipnum(ips);
- ips=rou_freestr(ips);
+ break;
+ case 2 : //converting interface IP list to AFNTYP list
+ afns=afn_getipnum(localip);
break;
default : //SAFE Guard
- (void) free(data);
proceed=false;
break;
}
phase++;
}
-
-#undef DPORT
-#undef DIP
+localip=rou_freestr(localip);
#undef OPEP
}
/*