From 396b646123c1aef81c644ae744e65c71b30067d0 Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Sun, 12 Jun 2011 14:07:22 +0200 Subject: [PATCH] s3: Add wins_server_tag_ips() For a given tag, return the list of all wins servers --- source3/include/proto.h | 2 ++ source3/lib/wins_srv.c | 42 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 44 insertions(+) diff --git a/source3/include/proto.h b/source3/include/proto.h index 4a19f74d4c7..815104881dd 100644 --- a/source3/include/proto.h +++ b/source3/include/proto.h @@ -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 */ diff --git a/source3/lib/wins_srv.c b/source3/lib/wins_srv.c index 6676f02e947..f9e8f3b0e1a 100644 --- a/source3/lib/wins_srv.c +++ b/source3/lib/wins_srv.c @@ -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 -- 2.11.4.GIT