summaryrefslogtreecommitdiff
path: root/source3/lib
diff options
context:
space:
mode:
authorJeremy Allison <jra@samba.org>2007-11-03 22:34:46 -0700
committerJeremy Allison <jra@samba.org>2007-11-03 22:34:46 -0700
commit51a0354d751f48a2542984c81e218da33669bbeb (patch)
tree27e620eb5d4e72e2a07591645680e6776491702b /source3/lib
parent56aa420195f4bf8007fbbbe362dbaf961a97f423 (diff)
downloadsamba-51a0354d751f48a2542984c81e218da33669bbeb.tar.gz
samba-51a0354d751f48a2542984c81e218da33669bbeb.tar.bz2
samba-51a0354d751f48a2542984c81e218da33669bbeb.zip
Remove more static data from lib/util_sock.c and
callers. Jeremy. (This used to be commit 35aaa36f82c70964cee5d0778eb04547b226dd3f)
Diffstat (limited to 'source3/lib')
-rw-r--r--source3/lib/substitute.c6
-rw-r--r--source3/lib/util_sock.c58
-rw-r--r--source3/lib/wins_srv.c8
3 files changed, 33 insertions, 39 deletions
diff --git a/source3/lib/substitute.c b/source3/lib/substitute.c
index d4c7cd6467..bd15399b13 100644
--- a/source3/lib/substitute.c
+++ b/source3/lib/substitute.c
@@ -41,6 +41,7 @@ void set_local_machine_name(const char* local_name, bool perm)
{
static bool already_perm = False;
fstring tmp_local_machine;
+ char addr[INET6_ADDRSTRLEN];
fstrcpy(tmp_local_machine,local_name);
trim_char(tmp_local_machine,' ',' ');
@@ -51,7 +52,7 @@ void set_local_machine_name(const char* local_name, bool perm)
*/
if ( strequal(tmp_local_machine, "*SMBSERVER") || strequal(tmp_local_machine, "*SMBSERV") ) {
- fstrcpy( local_machine, client_socket_addr() );
+ fstrcpy( local_machine, client_socket_addr(addr, sizeof(addr)) );
return;
}
@@ -499,7 +500,8 @@ char *alloc_sub_basic(const char *smb_name, const char *domain_name,
client_addr(addr, sizeof(addr)));
break;
case 'i':
- a_string = realloc_string_sub( a_string, "%i", client_socket_addr() );
+ a_string = realloc_string_sub( a_string, "%i",
+ client_socket_addr(addr, sizeof(addr)) );
break;
case 'L' :
if ( StrnCaseCmp(p, "%LOGONSERVER%", strlen("%LOGONSERVER%")) == 0 ) {
diff --git a/source3/lib/util_sock.c b/source3/lib/util_sock.c
index 3cce12381c..b31736430e 100644
--- a/source3/lib/util_sock.c
+++ b/source3/lib/util_sock.c
@@ -199,12 +199,11 @@ uint32 interpret_addr(const char *str)
A convenient addition to interpret_addr().
******************************************************************/
-struct in_addr *interpret_addr2(const char *str)
+struct in_addr *interpret_addr2(struct in_addr *ip, const char *str)
{
- static struct in_addr ret;
uint32 a = interpret_addr(str);
- ret.s_addr = a;
- return(&ret);
+ ip->s_addr = a;
+ return ip;
}
/*******************************************************************
@@ -331,15 +330,7 @@ bool is_zero_addr(const struct sockaddr_storage *pss)
void zero_ip_v4(struct in_addr *ip)
{
- static bool init;
- static struct in_addr ipzero;
-
- if (!init) {
- ipzero = *interpret_addr2("0.0.0.0");
- init = true;
- }
-
- *ip = ipzero;
+ memset(ip, '\0', sizeof(struct in_addr));
}
/*******************************************************************
@@ -595,21 +586,20 @@ void client_setfd(int fd)
}
/****************************************************************************
- Return a static string of an IP address (IPv4 or IPv6).
+ Return the string of an IP address (IPv4 or IPv6).
****************************************************************************/
-static const char *get_socket_addr(int fd)
+static const char *get_socket_addr(int fd, char *addr_buf, size_t addr_len)
{
struct sockaddr_storage sa;
socklen_t length = sizeof(sa);
- static char addr_buf[INET6_ADDRSTRLEN];
/* Ok, returning a hard coded IPv4 address
* is bogus, but it's just as bogus as a
* zero IPv6 address. No good choice here.
*/
- safe_strcpy(addr_buf, "0.0.0.0", sizeof(addr_buf)-1);
+ safe_strcpy(addr_buf, "0.0.0.0", addr_len-1);
if (fd == -1) {
return addr_buf;
@@ -621,7 +611,7 @@ static const char *get_socket_addr(int fd)
return addr_buf;
}
- return print_sockaddr_len(addr_buf, sizeof(addr_buf), &sa, length);
+ return print_sockaddr_len(addr_buf, addr_len, &sa, length);
}
/****************************************************************************
@@ -664,9 +654,9 @@ const char *client_addr(char *addr, size_t addrlen)
return get_peer_addr(client_fd,addr,addrlen);
}
-const char *client_socket_addr(void)
+const char *client_socket_addr(char *addr, size_t addr_len)
{
- return get_socket_addr(client_fd);
+ return get_socket_addr(client_fd, addr, addr_len);
}
int client_socket_port(void)
@@ -1672,9 +1662,9 @@ int open_udp_socket(const char *host, int port)
int type = SOCK_DGRAM;
struct sockaddr_in sock_out;
int res;
- struct in_addr *addr;
+ struct in_addr addr;
- addr = interpret_addr2(host);
+ (void)interpret_addr2(&addr, host);
res = socket(PF_INET, type, 0);
if (res == -1) {
@@ -1682,7 +1672,7 @@ int open_udp_socket(const char *host, int port)
}
memset((char *)&sock_out,'\0',sizeof(sock_out));
- putip((char *)&sock_out.sin_addr,(char *)addr);
+ putip((char *)&sock_out.sin_addr,(char *)&addr);
sock_out.sin_port = htons(port);
sock_out.sin_family = PF_INET;
@@ -1987,32 +1977,32 @@ out_umask:
Get my own canonical name, including domain.
****************************************************************************/
+static fstring dnshostname_cache;
+
bool get_mydnsfullname(fstring my_dnsname)
{
- static fstring dnshostname;
-
- if (!*dnshostname) {
+ if (!*dnshostname_cache) {
struct addrinfo *res = NULL;
bool ret;
/* get my host name */
- if (gethostname(dnshostname, sizeof(dnshostname)) == -1) {
- *dnshostname = '\0';
+ if (gethostname(dnshostname_cache, sizeof(dnshostname_cache)) == -1) {
+ *dnshostname_cache = '\0';
DEBUG(0,("get_mydnsfullname: gethostname failed\n"));
return false;
}
/* Ensure null termination. */
- dnshostname[sizeof(dnshostname)-1] = '\0';
+ dnshostname_cache[sizeof(dnshostname_cache)-1] = '\0';
ret = interpret_string_addr_internal(&res,
- dnshostname,
+ dnshostname_cache,
AI_ADDRCONFIG|AI_CANONNAME);
if (!ret || res == NULL) {
DEBUG(3,("get_mydnsfullname: getaddrinfo failed for "
"name %s [%s]\n",
- dnshostname,
+ dnshostname_cache,
gai_strerror(ret) ));
return false;
}
@@ -2024,16 +2014,16 @@ bool get_mydnsfullname(fstring my_dnsname)
if (res->ai_canonname == NULL) {
DEBUG(3,("get_mydnsfullname: failed to get "
"canonical name for %s\n",
- dnshostname));
+ dnshostname_cache));
freeaddrinfo(res);
return false;
}
- fstrcpy(dnshostname, res->ai_canonname);
+ fstrcpy(dnshostname_cache, res->ai_canonname);
freeaddrinfo(res);
}
- fstrcpy(my_dnsname, dnshostname);
+ fstrcpy(my_dnsname, dnshostname_cache);
return true;
}
diff --git a/source3/lib/wins_srv.c b/source3/lib/wins_srv.c
index 0fb0648fec..0e184a6b7c 100644
--- a/source3/lib/wins_srv.c
+++ b/source3/lib/wins_srv.c
@@ -183,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);
+ (void)interpret_addr2(&ip->ip,str);
return;
}
- ip->ip = *interpret_addr2(s+1);
+ (void)interpret_addr2(&ip->ip,s+1);
fstrcpy(ip->tag, str);
s = strchr(ip->tag, ':');
- if (s) *s = 0;
+ if (s) {
+ *s = 0;
+ }
}