/* exchange. */
/* */
/********************************************************/
+#include <arpa/inet.h>
+#include <sys/types.h>
+
+#include <netdb.h>
#include <stdbool.h>
#include <stdlib.h>
#include <stdio.h>
*/
/********************************************************/
/* */
+/* Procedure to override remote IP number, ORGN is */
+/* used in debug mode test ONLY. */
+/* */
+/********************************************************/
+static void doorgn(CONTYP *contact,char *newip)
+
+{
+#define OPEP "lvleml.c:dorgn"
+
+struct addrinfo *res;
+int phase;
+_Bool proceed;
+
+res=(struct addrinfo *)0;
+phase=0;
+proceed=true;
+while (proceed==true) {
+ //(void) rou_alert(0,"JMPDBG %s phase='%d' parm=<%s>",OPEP,phase,newip);
+ switch (phase) {
+ case 0 : //checking if we have a parameter
+ if (strlen(newip)==0) {
+ (void) rou_alert(0,"%s, newip not specified (debug?)",OPEP);
+ phase=999; //No need to go further
+ }
+ break;
+ case 1 : //Getting Override HOST
+ if (strlen(newip)>0) { //always
+ int status;
+ struct addrinfo hints;
+
+ (void) memset(&hints,'\000',sizeof(hints));
+ hints.ai_family=PF_UNSPEC;
+ hints.ai_socktype=SOCK_STREAM;
+ hints.ai_flags=HINTFLG;
+ status=getaddrinfo(newip,"",&hints,&res);
+ if (status!=0) {
+ (void) transmit(contact,"%d 5.5.4 <%s> is not an IP number",BADPAR,newip);
+ phase=999; //no need to go further
+ }
+ }
+ break;
+ case 2 : //setting new remote name
+ if (res!=(struct addrinfo *)0) { //always
+ int namestat;
+ char host[NI_MAXHOST];
+
+ (void) strcpy(host,"No.Reverse");
+ namestat=getnameinfo(res->ai_addr,res->ai_addrlen,
+ host,sizeof(host),(char *)0,0,NI_NAMEREQD);
+ switch (namestat) {
+ case 0 :
+ case EAI_AGAIN :
+ case EAI_NONAME :
+ contact->peerip=rou_freestr(contact->peerip);
+ contact->peername=rou_freestr(contact->peername);
+ contact->peerip=strdup(newip);
+ contact->peername=strdup(host);
+ (void) transmit(contact,"%d 2.9.9 New peer [%s/%s] set",
+ CMDOK,newip,host);
+ break;
+ default :
+ (void) rou_alert(0,"%s, Unexpected namestat='%d' (IP=<%s>) (bug?)",
+ OPEP,namestat,newip);
+ (void) transmit(contact,"%d 5.5.4 Bug! with <%s>",BADPAR,newip);
+ break;
+ }
+ }
+ break;
+ default : //SAFE guard
+ proceed=false;
+ break;
+ }
+ phase++;
+ }
+if (res!=(struct addrinfo *)0)
+ (void) freeaddrinfo(res);
+#undef OPEP
+}
+/*
+^L
+*/
+/********************************************************/
+/* */
/* Procedure to check if helo or ehlo paratmeter */
/* is a correct one */
/* */
CMDOK,contact->mainsesid);
break;
case c_orgn :
- (void) transmit(contact,"%d 2.0.0 ORGN Debug", CMDOK);
+ (void) doorgn(contact,line);
break;
case c_quit : //QUIT SMTP protocol
(void) transmit(contact,"%d 2.0.0 Bye, closing connection %s",