diff options
author | Andrew Tridgell <tridge@samba.org> | 2006-01-09 02:43:38 +0000 |
---|---|---|
committer | Gerald (Jerry) Carter <jerry@samba.org> | 2007-10-10 13:49:55 -0500 |
commit | 374da729dd88507e4408f083294db3d2012d5cef (patch) | |
tree | d864892cb44c2409affaa94b26e10be7063751f9 /source4 | |
parent | 15ffd2c8b344a01e776aa4f3eb6a4c18ecf2eecc (diff) | |
download | samba-374da729dd88507e4408f083294db3d2012d5cef.tar.gz samba-374da729dd88507e4408f083294db3d2012d5cef.tar.bz2 samba-374da729dd88507e4408f083294db3d2012d5cef.zip |
r12785: make the iface_*() functions return strings which do not get
overwritten by another call (due to the implied static in
iface_ntoa()). This should save abartlet some pain
(This used to be commit 2244f298ace9f8832695cafd17c54324c11416f1)
Diffstat (limited to 'source4')
-rw-r--r-- | source4/lib/netif/interface.c | 22 |
1 files changed, 15 insertions, 7 deletions
diff --git a/source4/lib/netif/interface.c b/source4/lib/netif/interface.c index efb7ecce33..1135bbf868 100644 --- a/source4/lib/netif/interface.c +++ b/source4/lib/netif/interface.c @@ -31,6 +31,9 @@ struct interface { struct ipv4_addr ip; struct ipv4_addr bcast; struct ipv4_addr nmask; + const char *ip_s; + const char *bcast_s; + const char *nmask_s; }; static struct interface *local_interfaces; @@ -88,11 +91,16 @@ static void add_interface(struct in_addr ip, struct in_addr nmask) iface->nmask = tov4(nmask); iface->bcast.addr = MKBCADDR(iface->ip.addr, iface->nmask.addr); + /* keep string versions too, to avoid people tripping over the implied + static in sys_inet_ntoa() */ + iface->ip_s = talloc_strdup(iface, sys_inet_ntoa(iface->ip)); + iface->bcast_s = talloc_strdup(iface, sys_inet_ntoa(iface->bcast)); + iface->nmask_s = talloc_strdup(iface, sys_inet_ntoa(iface->nmask)); + DLIST_ADD_END(local_interfaces, iface, struct interface *); - DEBUG(2,("added interface ip=%s ",sys_inet_ntoa(iface->ip))); - DEBUG(2,("bcast=%s ",sys_inet_ntoa(iface->bcast))); - DEBUG(2,("nmask=%s\n",sys_inet_ntoa(iface->nmask))); + DEBUG(2,("added interface ip=%s bcast=%s nmask=%s\n", + iface->ip_s, iface->bcast_s, iface->nmask_s)); } @@ -261,7 +269,7 @@ const char *iface_n_ip(int n) n--; if (i) { - return sys_inet_ntoa(i->ip); + return i->ip_s; } return NULL; } @@ -279,7 +287,7 @@ const char *iface_n_bcast(int n) n--; if (i) { - return sys_inet_ntoa(i->bcast); + return i->bcast_s; } return NULL; } @@ -297,7 +305,7 @@ const char *iface_n_netmask(int n) n--; if (i) { - return sys_inet_ntoa(i->nmask); + return i->nmask_s; } return NULL; } @@ -316,7 +324,7 @@ const char *iface_best_ip(const char *dest) ip.s_addr = interpret_addr(dest); iface = iface_find(ip, True); if (iface) { - return sys_inet_ntoa(iface->ip); + return iface->ip_s; } return iface_n_ip(0); } |