浏览代码

netbios_ns: remove discover/entry_at/entry_count/clear

Thomas Guillem 10 年之前
父节点
当前提交
a3c55fd628
共有 2 个文件被更改,包括 16 次插入134 次删除
  1. 0 43
      include/bdsm/netbios_ns.h
  2. 16 91
      src/netbios_ns.c

+ 0 - 43
include/bdsm/netbios_ns.h

@@ -92,42 +92,6 @@ int           netbios_ns_resolve(netbios_ns *ns, const char *name,
                                  char type, uint32_t *addr);
 
 /**
- * @brief Try to discover all the Netbios/SMB speaking machine on the LAN.
- * @details This functions sends a message to '*' Netbios name, and waits for
- * the machine on the LAN to answer. It then performs a reverse lookup on all
- * the ip he received packet from. It stores the results inside of the name
- * service, allowing you to list them
- *
- *
- * @param ns The name service object.
- * @return It returns 0 in case of error.
- */
-int           netbios_ns_discover(netbios_ns *ns);
-
-/**
- * @brief Get the list of entries (know machine) for this name service object
- * @details You might want to call discover before-hand if you don't want
- * the lit to be empty
- *
- * @return The list of entries in the name service.
- */
-int           netbios_ns_entry_count(netbios_ns *ns);
-
-/**
- * @brief Get the entry at a certain position in the entry list
- * @details You might want to call discover before-hand if you don't want
- * the lit to be empty. The entry list contains all the record known to the
- * name service (including resolved, reverse resolved and discovered) since the
- * creation of the name service object or the last call to clear
- *
- * @param ns The nameservice object.
- * @param pos The index/position of the item to access in the list. Must be <
- * netbios_ns_entry_count(ns) or the pointer returned will be NULL.
- * @return A pointer to a opaque netbios_ns_entry structure
- */
-netbios_ns_entry *netbios_ns_entry_at(netbios_ns *ns, int pos);
-
-/**
  * @brief Perform an inverse netbios lookup (get name from ip)
  * @details This function does a NBSTAT and stores all the returned entry in
  * the internal list of entries. It returns one of the name found. (Normally
@@ -142,13 +106,6 @@ netbios_ns_entry *netbios_ns_entry_at(netbios_ns *ns, int pos);
 const char          *netbios_ns_inverse(netbios_ns *ns, uint32_t ip);
 
 /**
- * @brief Clear all the existing entries from the name service
- *
- * @param ns The nameservice object
- */
-void                netbios_ns_clear(netbios_ns *ns);
-
-/**
  * @brief abort any pending netbios_ns_* operations
  *
  *

+ 16 - 91
src/netbios_ns.c

@@ -495,6 +495,21 @@ static netbios_ns_entry *netbios_ns_entry_find(netbios_ns *ns, const char *by_na
     return NULL;
 }
 
+static void netbios_ns_entry_clear(netbios_ns *ns)
+{
+    netbios_ns_entry  *entry, *entry_next;
+
+    assert(ns != NULL);
+
+    for (entry = TAILQ_FIRST(&ns->entry_queue);
+         entry != NULL; entry = entry_next)
+    {
+        entry_next = TAILQ_NEXT(entry, next);
+        TAILQ_REMOVE(&ns->entry_queue, entry, next);
+        free(entry);
+    }
+}
+
 netbios_ns  *netbios_ns_new()
 {
     netbios_ns  *ns;
@@ -521,7 +536,7 @@ void          netbios_ns_destroy(netbios_ns *ns)
     if (!ns)
         return;
 
-    netbios_ns_clear(ns);
+    netbios_ns_entry_clear(ns);
 
     close(ns->socket);
 
@@ -579,48 +594,6 @@ int      netbios_ns_resolve(netbios_ns *ns, const char *name, char type, uint32_
     return (0);
 }
 
-// We have a small recursive function for discovery, to stack received reply
-// when descending, and performing reverse lookup when ascending
-static void netbios_ns_discover_rec(netbios_ns *ns, struct timeval *timeout )
-{
-    struct sockaddr_in  recv_addr;
-    int                 res;
-
-    res = netbios_ns_recv(ns, timeout, &recv_addr, true, 0, NULL);
-    if (res > 0 && timeout->tv_sec && timeout->tv_usec)
-    {
-        netbios_ns_discover_rec(ns, timeout);
-
-        BDSM_dbg("Discover: received a reply from %s\n",
-                 inet_ntoa(recv_addr.sin_addr));
-        netbios_ns_inverse_internal(ns, recv_addr.sin_addr.s_addr);
-    }
-}
-
-int           netbios_ns_discover(netbios_ns *ns)
-{
-    struct timeval      timeout;
-
-    assert(ns != NULL);
-
-    //
-    // First step, we broadcast a packet to receive a message from every
-    // NETBIOS nodes on the local network
-    //
-    if (netbios_ns_send_name_query(ns, 0, NAME_QUERY_TYPE_NB,
-                                   name_query_broadcast, 0) == -1)
-        return (0);
-
-    //
-    // Second step, we list every IP that answered to our broadcast.
-    //
-    timeout.tv_sec = 2;
-    timeout.tv_usec = 420;
-    netbios_ns_discover_rec(ns, &timeout);
-
-    return (1);
-}
-
 static int    netbios_ns_is_aborted(netbios_ns *ns)
 {
     fd_set        read_fds;
@@ -713,54 +686,6 @@ char netbios_ns_entry_type(netbios_ns_entry *entry)
     return entry ? entry->type : -1;
 }
 
-void netbios_ns_clear(netbios_ns *ns)
-{
-    netbios_ns_entry  *entry, *entry_next;
-
-    assert(ns != NULL);
-
-    for (entry = TAILQ_FIRST(&ns->entry_queue);
-         entry != NULL; entry = entry_next)
-    {
-        entry_next = TAILQ_NEXT(entry, next);
-        TAILQ_REMOVE(&ns->entry_queue, entry, next);
-        free(entry);
-    }
-}
-
-int             netbios_ns_entry_count(netbios_ns *ns)
-{
-    netbios_ns_entry  *iter;
-    int                 res;
-
-    assert(ns != NULL);
-
-    res   = 0;
-    TAILQ_FOREACH(iter, &ns->entry_queue, next)
-    {
-        res++;
-    }
-
-    return (res);
-}
-
-netbios_ns_entry  *netbios_ns_entry_at(netbios_ns *ns, int pos)
-{
-    netbios_ns_entry  *iter = NULL;
-    int                 i = 0;
-
-    assert(ns != NULL);
-
-    iter = TAILQ_FIRST(&ns->entry_queue);
-    while (i < pos && iter != NULL)
-    {
-        i++;
-        iter = TAILQ_NEXT(iter, next);
-    }
-
-    return (iter);
-}
-
 static void *netbios_ns_discover_thread(void *opaque)
 {
     netbios_ns *ns = (netbios_ns *) opaque;