This makes it multi-threaded safe.
Changed a number of other functions which call ip_hostname(),
to update them for this change.
Also changed the print function in lib/print.c, to call ip_hostname,
instead of ip_ntoa.
/*
* Several handy miscellaneous functions.
*/
-char * ip_hostname (uint32_t);
+char * ip_hostname (char *buf, size_t buflen, uint32_t ipaddr);
uint32_t ip_getaddr (const char *);
char * ip_ntoa(char *, uint32_t);
uint32_t ip_addr(const char *);
* Return a printable host name (or IP address in dot notation)
* for the supplied IP address.
*/
-char * ip_hostname(uint32_t ipaddr)
+char * ip_hostname(char *buf, size_t buflen, uint32_t ipaddr)
{
struct hostent *hp;
- static char hstname[128];
/*
* No DNS: don't look up host names
*/
if (!librad_dodns) {
- ip_ntoa(hstname, ipaddr);
- return(hstname);
+ ip_ntoa(buf, ipaddr);
+ return buf;
}
hp = gethostbyaddr((char *)&ipaddr, sizeof (struct in_addr), AF_INET);
- if (hp == 0) {
- ip_ntoa(hstname, ipaddr);
- return(hstname);
+ if ((hp == 0) ||
+ (strlen((char *)hp->h_name) >= buflen)) {
+ ip_ntoa(buf, ipaddr);
+ return buf;
}
- return (char *)hp->h_name;
+
+ strNcpy(buf, (char *)hp->h_name, buflen);
+ return buf;
}
if (vp->strvalue[0])
a = vp->strvalue;
else
- a = ip_ntoa(NULL, vp->lvalue);
+ a = ip_hostname(vp->strvalue,
+ sizeof(vp->strvalue),
+ vp->lvalue);
break;
case PW_TYPE_ABINARY:
#ifdef ASCEND_BINARY
}
strcpy(c->secret, secret);
strcpy(c->shortname, shortnm);
- strcpy(c->longname, ip_hostname(c->ipaddr));
+ ip_hostname(c->longname, sizeof(c->longname), c->ipaddr);
c->next = clients;
clients = c;
else
return cl->longname;
}
- return ip_hostname(ipaddr);
+
+ /*
+ * FIXME!
+ *
+ * We should NEVER reach this piece of code, as we should
+ * NEVER be looking up client names for clients we don't know!
+ */
+ return NULL;
}
#ifndef BUILDDBM /* HACK HACK */
strcpy(c->longname, hostnm);
} else {
c->ipaddr = ip_getaddr(hostnm);
- strcpy(c->longname, ip_hostname(c->ipaddr));
+ ip_hostname(c->longname, sizeof(c->longname),
+ c->ipaddr);
}
c->next = naslist;
char *nas_name(uint32_t ipaddr)
{
NAS *cl;
+ char buf[256];
if ((cl = nas_find(ipaddr)) != NULL) {
if (cl->shortname[0])
else
return cl->longname;
}
- return ip_hostname(ipaddr);
+
+ /*
+ * FIXME!
+ *
+ * This isn't multi-threaded safe!
+ */
+ return ip_hostname(buf, sizeof(buf), ipaddr);
}
/*
uint32_t ipaddr;
NAS *cl;
VALUE_PAIR *pair;
+ char buf[256];
if ((pair = pairfind(packet->vps, PW_NAS_IP_ADDRESS)) != NULL)
ipaddr = pair->lvalue;
else
return cl->longname;
}
- return ip_hostname(ipaddr);
+
+ /*
+ * FIXME!!!
+ *
+ * This isn't multi-threaded safe!
+ */
+ return ip_hostname(buf, sizeof(buf), ipaddr);
}
c->ipaddr = ip_getaddr(hostnm);
strNcpy(c->nastype, nastype, sizeof(c->nastype));
strNcpy(c->shortname, shortnm, sizeof(c->shortname));
- strNcpy(c->longname, ip_hostname(c->ipaddr),
- sizeof(c->longname));
-
+ ip_hostname(c->longname, sizeof(c->longname), c->ipaddr);
c->next = cl;
cl = c;
}
/*
* Print address of NAS.
*/
-static const char *hostname(uint32_t ipaddr)
+static const char *hostname(char *buf, size_t buflen, uint32_t ipaddr)
{
if (ipaddr == 0 || ipaddr == (uint32_t)-1 || ipaddr == (uint32_t)-2)
return "";
- return ip_hostname(ipaddr);
+ return ip_hostname(buf, buflen, ipaddr);
}
int hdrdone = 0;
char inbuf[128];
char myname[128];
+ char othername[256];
char session_id[16];
int fingerd = 0;
int showlocal = 0;
portind, portno,
dotime(rt.time),
nasname(rt.nas_address),
- hostname(rt.framed_address), eol);
+ hostname(othername, sizeof(othername), rt.framed_address), eol);
else
printf((rawoutput == 0? rfmt2: rfmt2r),
rt.login,
proto(rt.proto, rt.porttype),
dotime(rt.time),
nasname(rt.nas_address),
- hostname(rt.framed_address), eol);
+ hostname(othername, sizeof(othername), rt.framed_address), eol);
}
}
fflush(stdout);
if (nas) ip = nas->ipaddr;
printf("radzap: zapping termserver %s, port %d",
- ip_hostname(ip), nas_port);
+ ip_hostname(buf, sizeof(buf), ip), nas_port);
if (user) printf(", user %s", user);
printf("\n");
FILE *outfd;
char nasname[128];
char buffer[512];
- char *s;
VALUE_PAIR *pair;
uint32_t nas;
NAS *cl;
}
if (cl == NULL) {
- s = ip_hostname(nas);
- if (strlen(s) >= sizeof(nasname) || strchr(s, '/'))
- return -1;
- strcpy(nasname, s);
+ ip_hostname(nasname, sizeof(nasname), nas);
}
/*