s3: Add wins_server_tag_ips()
authorVolker Lendecke <vl@samba.org>
Sun, 12 Jun 2011 12:07:22 +0000 (14:07 +0200)
committerVolker Lendecke <vl@samba.org>
Sun, 12 Jun 2011 15:07:48 +0000 (17:07 +0200)
For a given tag, return the list of all wins servers

source3/include/proto.h
source3/lib/wins_srv.c

index 4a19f74d4c7f76c1661363ba8d8d58dd82820927..815104881dd1c5bcc50cd6ab113f0b0436b28251 100644 (file)
@@ -913,6 +913,8 @@ unsigned wins_srv_count(void);
 char **wins_srv_tags(void);
 void wins_srv_tags_free(char **list);
 struct in_addr wins_srv_ip_tag(const char *tag, struct in_addr src_ip);
+bool wins_server_tag_ips(const char *tag, TALLOC_CTX *mem_ctx,
+                        struct in_addr **pservers, int *pnum_servers);
 unsigned wins_srv_count_tag(const char *tag);
 
 /* The following definitions come from libsmb/clispnego.c  */
index 6676f02e947929d43a8f277c3c141240124a8027..f9e8f3b0e1a52df9cdbd47d065f1b4bb34991290 100644 (file)
@@ -328,6 +328,48 @@ struct in_addr wins_srv_ip_tag(const char *tag, struct in_addr src_ip)
        return t_ip.ip;
 }
 
+bool wins_server_tag_ips(const char *tag, TALLOC_CTX *mem_ctx,
+                        struct in_addr **pservers, int *pnum_servers)
+{
+       const char **list;
+       int i, num_servers;
+       struct in_addr *servers;
+
+       list = lp_wins_server_list();
+       if ((list == NULL) || (list[0] == NULL)) {
+               return false;
+       }
+
+       num_servers = 0;
+
+       for (i=0; list[i] != NULL; i++) {
+               struct tagged_ip t_ip;
+               parse_ip(&t_ip, list[i]);
+               if (strcmp(tag, t_ip.tag) == 0) {
+                       num_servers += 1;
+               }
+       }
+
+       servers = talloc_array(mem_ctx, struct in_addr, num_servers);
+       if (servers == NULL) {
+               return false;
+       }
+
+       num_servers = 0;
+
+       for (i=0; list[i] != NULL; i++) {
+               struct tagged_ip t_ip;
+               parse_ip(&t_ip, list[i]);
+               if (strcmp(tag, t_ip.tag) == 0) {
+                       servers[num_servers] = t_ip.ip;
+                       num_servers += 1;
+               }
+       }
+       *pnum_servers = num_servers;
+       *pservers = servers;
+       return true;
+}
+
 
 /*
   return a count of the number of IPs for a particular tag, including