What to do about debugging in a multi-threaded application?
[ira/wip.git] / source3 / lib / wins_srv.c
index 3372f74dcbe967c2730d331a0009a7f46e747b28..b2c0bf8b870613f3ca4876b976beb67bde31b831 100644 (file)
@@ -7,7 +7,7 @@
 
    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
-   the Free Software Foundation; either version 2 of the License, or
+   the Free Software Foundation; either version 3 of the License, or
    (at your option) any later version.
 
    This program is distributed in the hope that it will be useful,
@@ -16,8 +16,7 @@
    GNU General Public License for more details.
 
    You should have received a copy of the GNU General Public License
-   along with this program; if not, write to the Free Software
-   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
 
 #include "includes.h"
 
 static char *wins_srv_keystr(struct in_addr wins_ip, struct in_addr src_ip)
 {
-       char *keystr;
+       char *keystr = NULL, *wins_ip_addr = NULL, *src_ip_addr = NULL;
 
-       if (asprintf(&keystr, WINS_SRV_FMT, inet_ntoa(wins_ip),
-                    inet_ntoa(src_ip)) == -1) {
-               DEBUG(0, ("wins_srv_is_dead: malloc error\n"));
-               return NULL;
+       wins_ip_addr = SMB_STRDUP(inet_ntoa(wins_ip));
+       src_ip_addr = SMB_STRDUP(inet_ntoa(src_ip));
+
+       if ( !wins_ip_addr || !src_ip_addr ) {
+               DEBUG(0,("wins_srv_keystr: malloc error\n"));
+               goto done;
+       }
+
+       if (asprintf(&keystr, WINS_SRV_FMT, wins_ip_addr, src_ip_addr) == -1) {
+               DEBUG(0, (": ns_srv_keystr: malloc error for key string\n"));
        }
 
+done:
+       SAFE_FREE(wins_ip_addr);
+       SAFE_FREE(src_ip_addr);
+
        return keystr;
 }
 
@@ -85,10 +94,10 @@ static char *wins_srv_keystr(struct in_addr wins_ip, struct in_addr src_ip)
   see if an ip is on the dead list
 */
 
-BOOL wins_srv_is_dead(struct in_addr wins_ip, struct in_addr src_ip)
+bool wins_srv_is_dead(struct in_addr wins_ip, struct in_addr src_ip)
 {
        char *keystr = wins_srv_keystr(wins_ip, src_ip);
-       BOOL result;
+       bool result;
 
        /* If the key exists then the WINS server has been marked as dead */
 
@@ -123,7 +132,7 @@ void wins_srv_died(struct in_addr wins_ip, struct in_addr src_ip)
 {
        char *keystr;
 
-       if (is_zero_ip(wins_ip) || wins_srv_is_dead(wins_ip, src_ip))
+       if (is_zero_ip_v4(wins_ip) || wins_srv_is_dead(wins_ip, src_ip))
                return;
 
        keystr = wins_srv_keystr(wins_ip, src_ip);
@@ -174,14 +183,16 @@ static void parse_ip(struct tagged_ip *ip, const char *str)
        char *s = strchr(str, ':');
        if (!s) {
                fstrcpy(ip->tag, "*");
-               ip->ip = *interpret_addr2(str);
+               ip->ip = interpret_addr2(str);
                return;
        } 
 
-       ip->ip = *interpret_addr2(s+1);
+       ip->ip = interpret_addr2(s+1);
        fstrcpy(ip->tag, str);
        s = strchr(ip->tag, ':');
-       if (s) *s = 0;
+       if (s) {
+               *s = 0;
+       }
 }
 
 
@@ -202,9 +213,9 @@ char **wins_srv_tags(void)
        if (lp_wins_support()) {
                /* give the caller something to chew on. This makes
                   the rest of the logic simpler (ie. less special cases) */
-               ret = (char **)malloc(sizeof(char *)*2);
+               ret = SMB_MALLOC_ARRAY(char *, 2);
                if (!ret) return NULL;
-               ret[0] = strdup("*");
+               ret[0] = SMB_STRDUP("*");
                ret[1] = NULL;
                return ret;
        }
@@ -232,8 +243,11 @@ char **wins_srv_tags(void)
                }
 
                /* add it to the list */
-               ret = (char **)Realloc(ret, (count+2) * sizeof(char *));
-               ret[count] = strdup(t_ip.tag);
+               ret = SMB_REALLOC_ARRAY(ret, char *, count+2);
+               if (!ret) {
+                       return NULL;
+               }
+               ret[count] = SMB_STRDUP(t_ip.tag);
                if (!ret[count]) break;
                count++;
        }
@@ -270,14 +284,15 @@ struct in_addr wins_srv_ip_tag(const char *tag, struct in_addr src_ip)
 
        /* if we are a wins server then we always just talk to ourselves */
        if (lp_wins_support()) {
-               extern struct in_addr loopback_ip;
+               struct in_addr loopback_ip;
+               loopback_ip.s_addr = htonl(INADDR_LOOPBACK);
                return loopback_ip;
        }
 
        list = lp_wins_server_list();
        if (!list || !list[0]) {
                struct in_addr ip;
-               zero_ip(&ip);
+               zero_ip_v4(&ip);
                return ip;
        }
 
@@ -309,7 +324,7 @@ struct in_addr wins_srv_ip_tag(const char *tag, struct in_addr src_ip)
        }
 
        /* this can't happen?? */
-       zero_ip(&t_ip.ip);
+       zero_ip_v4(&t_ip.ip);
        return t_ip.ip;
 }