

#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"

// #define RESOLV_DEBUG

char * resolvename_sk(char * backdata, char *name, int timeout, unsigned long * ret, char * dns_ip, int * stat, char type)
{

// char * scan_dns_connect(int, char *, char *, char *, int, int *);
// backdata = scan_dns_connect(53, dns_ip, name, backdata, timeout, stat);
backdata = scan_dns_connect(53, dns_ip, name, backdata, timeout, stat, type);
swap_mem(backdata, '\n', 0x00);

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

if(* stat < 0){
   #ifdef RESOLV_DEBUG
   fprintf(stderr,"RESOLV_DEBUG: resolvname(3): %s %s\n", SOCK_10, name);
   #endif
   * ret = 0;
   }
else{
   //  ちゃんと引けた場合
   inet_pton(AF_INET, backdata, ret);
   backdata = safe_memcpy(backdata, SOCK_11, BUF_MAX);
   #ifdef RESOLV_DEBUG
   fprintf(stderr,"RESOLV_DEBUG: resolvname(5): %s %s\n", SOCK_11, name);
   #endif
   }

#ifdef RESOLV_DEBUG
fprintf(stderr,"RESOLV_DEBUG: resolvname(6): name = %s, backdata = %s\n", name, backdata);
#endif


return(backdata);
}



