Browse Source

Fix ns_resolve documentation/code consistency

Julien 'Lta' BALLET 11 years ago
parent
commit
afb7d72484
2 changed files with 8 additions and 5 deletions
  1. 1 1
      include/bdsm/netbios_ns.h
  2. 7 4
      src/netbios_ns.c

+ 1 - 1
include/bdsm/netbios_ns.h

@@ -109,7 +109,7 @@ void          netbios_ns_destroy(netbios_ns *ns);
  * longer than 15 chars, it'll be truncated.
  * @param type The type of the name to look for. @see netbios_defs.h
  * @param[out] addr The IP address in network byte order of the machine if found.
- * @return the ipv4 address in network byte-order or 0 if it wasn't successfull.
+ * @return a value > 0 if successfull, or 0 otherwise
  */
 int           netbios_ns_resolve(netbios_ns *ns, const char *name,
                                  char type, uint32_t *addr);

+ 7 - 4
src/netbios_ns.c

@@ -161,9 +161,9 @@ error:
 
 int      netbios_ns_resolve(netbios_ns *ns, const char *name, char type, uint32_t *addr)
 {
-    netbios_ns_entry  *cached;
+    netbios_ns_entry    *cached;
     struct timeval      timeout;
-    netbios_query     *q;
+    netbios_query       *q;
     char                *encoded_name;
     char                footer[4] = { 0x00, 0x20, 0x00, 0x01 };
     char                recv_buffer[512]; // Hu ?
@@ -175,10 +175,13 @@ int      netbios_ns_resolve(netbios_ns *ns, const char *name, char type, uint32_
 
 
     if ((cached = netbios_ns_entry_find(ns, name, 0)) != NULL)
-        return (cached->address.s_addr);
+    {
+        *addr = cached->address.s_addr;
+        return (1);
+    }
 
     if ((encoded_name = netbios_name_encode(name, 0, type)) == NULL)
-        return (-1);
+        return (0);
 
     // Prepare packet
     q = netbios_query_new(34 + 4, 1, NETBIOS_OP_NAME_QUERY);