

#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<netdb.h>
#include<unistd.h>
#include<sys/socket.h>
#include<netinet/in_systm.h>
#include<netinet/in.h>
#include<netinet/ip.h>
#include<arpa/inet.h>
#include<fcntl.h>

#include<sys/stat.h>
#include<errno.h>

#include"sitar_scan.h"
#include"sitar_com.h"
#include<almemsys/almemsys.h>
#include"jpreturn.h"


char * out_resolvename(char * backdata, char *name, int timeout, unsigned long * ret)
{
char * recdata;
char * sendcom;

if((recdata = (char *)calloc(BUF_DEFLEN, sizeof(char)))==NULL){ exit(1);}
if((sendcom = (char *)calloc(BUF_DEFLEN, sizeof(char)))==NULL){ exit(1);}

sendcom = safe_sprintf(sendcom, BUF_MAX,"%s %s",
  "/usr/local/zither/bin/resolv", name);

recdata = out_execom(sendcom, recdata, timeout, 1);
swap_mem(recdata, '\n', 0x00);

#ifdef RESOLV_DEBUG
printf("RESOLV: resolvname(2): sendcom %s resolvname %s\n", sendcom, recdata);
#endif

* ret = 0;
if(0 == memcmp(recdata, COM_1, 20)){
   backdata = safe_memcpy(backdata, "SOCK_10", BUF_MAX);
   #ifdef RESOLV_DEBUG
   fprintf(stderr,"RESOLV: resolvname(3): %s %s\n", SOCK_10, name);
   #endif
   * ret = 0;
   }
else if(0 == memcmp(recdata, "0.0.0.0", 7)){
   backdata = safe_memcpy(backdata, "SOCK_2", BUF_MAX);
   #ifdef RESOLV_DEBUG
   fprintf(stderr,"RESOLV: resolvname(4): %s\n", SOCK_2);
   #endif
   * ret = 0;
   }
else{
   backdata = safe_memcpy(backdata, "SOCK_11", BUF_MAX);
   #ifdef RESOLV_DEBUG
   fprintf(stderr,"RESOLV: resolvname(5): %s %s\n", SOCK_11, name);
   #endif
// * ret = (unsigned long)inet_addr(recdata);
   inet_pton(AF_INET, recdata, ret);
   }

free(recdata);
free(sendcom);

return(backdata);
}


