Usermode/libnet - Fix compile errors (silly me)
[tpg/acess2.git] / Usermode / Libraries / libnet.so_src / hostnames.c
index 88093de..99aa328 100644 (file)
@@ -8,7 +8,9 @@
 #include <net.h>
 #include "include/dns.h"
 #include <string.h>
+#include <stdlib.h>    // malloc (for loading config)
 #include <stdbool.h>
+#include <acess/sys.h> // _SysDebug
 
 // === TYPES ===
 struct sDNSServer
@@ -41,7 +43,7 @@ struct sDNSCallbackInfo
 
 // === PROTOTYPES ===
  int   int_lookupany_callback(void *info_v, int AddrType, const void *Addr);
-void   int_DNS_callback(void *info, const char *name, enum eTypes type, enum eClass class, unsigned int ttl, size_t rdlength, const void *rdata);
+ int   int_DNS_callback(void *info, const char *name, enum eTypes type, enum eClass class, unsigned int ttl, size_t rdlength, const void *rdata);
 
 // === GLOBALS ===
  int   giNumDNSServers;
@@ -74,9 +76,16 @@ int int_lookupany_callback(void *info_v, int AddrType, const void *Addr)
 
 int Net_Lookup_Addrs(const char *Name, void *cb_info, tNet_LookupAddrs_Callback *callback)
 {
+       _SysDebug("Net_Lookup_Addrs(Name='%s')", Name);
        // 1. Load (if not loaded) the DNS config from "/Acess/Conf/dns"
        // - "* <ip> <ip>" for DNS server(s)
        // - "127.0.0.1 localhost localhost.localdomain"
+       if( !gaDNSServers )
+       {
+               giNumDNSServers = 1;
+               gaDNSServers = malloc( 1 * sizeof(gaDNSServers[0]) );
+               gaDNSServers[0].AddrType = Net_ParseAddress("192.168.1.1", gaDNSServers[0].AddrData);
+       }
        
        // 2. Check the hosts list
        for( int i = 0; i < giNumHostEntries; i ++ )
@@ -118,21 +127,22 @@ int Net_Lookup_Addrs(const char *Name, void *cb_info, tNet_LookupAddrs_Callback
        return 1;
 }
 
-void int_DNS_callback(void *info_v, const char *name, enum eTypes type, enum eClass class, unsigned int ttl, size_t rdlength, const void *rdata)
+int int_DNS_callback(void *info_v, const char *name, enum eTypes type, enum eClass class, unsigned int ttl, size_t rdlength, const void *rdata)
 {
        struct sDNSCallbackInfo *info = info_v;
+       _SysDebug("int_DNS_callback(name='%s', type=%i, class=%i)", name, type, class);
        
        // Check type matches (if pattern was provided)
        if( info->desired_type != QTYPE_STAR && type != info->desired_type )
-               return ;
+               return 0;
        if( info->desired_class != QCLASS_STAR && class != info->desired_class )
-               return ;
+               return 0;
        
        switch( type )
        {
        case TYPE_A:
                if( rdlength != 4 )
-                       return ;
+                       return 0;
                info->callback( info->cb_info, 4, rdata );
                break;
        //case TYPE_AAAA:
@@ -145,6 +155,7 @@ void int_DNS_callback(void *info_v, const char *name, enum eTypes type, enum eCl
                break;
        }
        info->got_value = true;
+       return 0;
 }
 
 int Net_Lookup_Name(int AddrType, const void *Addr, char *Dest[256])

UCC git Repository :: git.ucc.asn.au