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,
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;
}
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 */
{
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);
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;
+ }
}
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;
}
}
/* 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++;
}
/* 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;
}
}
/* this can't happen?? */
- zero_ip(&t_ip.ip);
+ zero_ip_v4(&t_ip.ip);
return t_ip.ip;
}