Page Menu
Home
FreeBSD
Search
Configure Global Search
Log In
Files
F148800034
D45601.1788721888.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Size
5 KB
Referenced Files
None
Subscribers
None
D45601.1788721888.diff
View Options
diff --git a/usr.sbin/ppp/defs.c b/usr.sbin/ppp/defs.c
--- a/usr.sbin/ppp/defs.c
+++ b/usr.sbin/ppp/defs.c
@@ -144,13 +144,21 @@
break;
if (*ptr == '\0') {
- struct hostent *hp;
-
- hp = gethostbyname(cp);
- if (hp && hp->h_addrtype == AF_INET)
- memcpy(&ipaddr, hp->h_addr, hp->h_length);
- else
+ struct addrinfo hints, *res;
+ int status;
+
+ memset(&hints, 0, sizeof(hints));
+ hints.ai_family = AF_INET;
+ hints.ai_socktype = 0;
+ status = getaddrinfo(cp, NULL, &hints, &res);
+ if (status == 0) {
+ memcpy(&ipaddr, &((struct sockaddr_in *)res->ai_addr)->sin_addr,
+ sizeof(struct in_addr));
+ freeaddrinfo(res);
+ }
+ else {
ipaddr.s_addr = INADDR_NONE;
+ }
} else
ipaddr.s_addr = INADDR_NONE;
}
diff --git a/usr.sbin/ppp/ipcp.c b/usr.sbin/ppp/ipcp.c
--- a/usr.sbin/ppp/ipcp.c
+++ b/usr.sbin/ppp/ipcp.c
@@ -447,11 +447,12 @@
ipcp_Init(struct ipcp *ipcp, struct bundle *bundle, struct link *l,
const struct fsm_parent *parent)
{
- struct hostent *hp;
+ struct addrinfo hints, *res;
struct in_addr host;
char name[MAXHOSTNAMELEN];
static const char * const timer_names[] =
{"IPCP restart", "IPCP openmode", "IPCP stopped"};
+ int status;
fsm_Init(&ipcp->fsm, "IPCP", PROTO_IPCP, 1, IPCP_MAXCODE, LogIPCP,
bundle, l, parent, &ipcp_Callbacks, timer_names);
@@ -463,9 +464,15 @@
host.s_addr = htonl(INADDR_LOOPBACK);
ipcp->cfg.netmask.s_addr = INADDR_ANY;
if (gethostname(name, sizeof name) == 0) {
- hp = gethostbyname(name);
- if (hp && hp->h_addrtype == AF_INET && hp->h_length == sizeof host.s_addr)
- memcpy(&host.s_addr, hp->h_addr, sizeof host.s_addr);
+ memset(&hints, 0, sizeof(hints));
+ hints.ai_family = AF_INET;
+ hints.ai_socktype = 0;
+ status = getaddrinfo(name, NULL, &hints, &res);
+ if (status == 0) {
+ memcpy(&host.s_addr, &((struct sockaddr_in *)res->ai_addr)->sin_addr.s_addr,
+ sizeof host.s_addr);
+ freeaddrinfo(res);
+ }
}
ncprange_setip4(&ipcp->cfg.my_range, host, ipcp->cfg.netmask);
ncprange_setip4(&ipcp->cfg.peer_range, ipcp->cfg.netmask, ipcp->cfg.netmask);
diff --git a/usr.sbin/ppp/nat_cmd.c b/usr.sbin/ppp/nat_cmd.c
--- a/usr.sbin/ppp/nat_cmd.c
+++ b/usr.sbin/ppp/nat_cmd.c
@@ -306,17 +306,31 @@
static int
StrToAddr(const char *str, struct in_addr *addr)
{
- struct hostent *hp;
+ struct addrinfo hints, *res, *p;
+ int status;
if (inet_aton(str, addr))
return 0;
- hp = gethostbyname(str);
- if (!hp) {
+ memset(&hints, 0, sizeof hints);
+ hints.ai_family = AF_INET;
+ hints.ai_socktype = 0;
+ status = getaddrinfo(str, NULL, &hints, &res);
+ if (status != 0 ){
log_Printf(LogWARN, "StrToAddr: Unknown host %s.\n", str);
return -1;
}
- *addr = *((struct in_addr *) hp->h_addr);
+ for (p = res; p != NULL; p = p->ai_next) {
+ if (p->ai_family == AF_INET) {
+ *addr = ((struct sockaddr_in *)p->ai_addr)->sin_addr;
+ break;
+ }
+ }
+ freeaddrinfo(res);
+ if (p == NULL) {
+ log_Printf(LogWARN, "StrToAddr: No valid ipv4 address %s.\n", str);
+ return -1;
+ }
return 0;
}
diff --git a/usr.sbin/ppp/radius.c b/usr.sbin/ppp/radius.c
--- a/usr.sbin/ppp/radius.c
+++ b/usr.sbin/ppp/radius.c
@@ -899,7 +899,7 @@
const char *what = "questionable"; /* silence warnings! */
char *mac_addr;
int got;
- struct hostent *hp;
+ struct addrinfo hints, *res;
struct in_addr hostaddr;
#ifndef NODES
struct mschap_response msresp;
@@ -1022,9 +1022,13 @@
if (gethostname(hostname, sizeof hostname) != 0)
log_Printf(LogERROR, "rad_put: gethostname(): %s\n", strerror(errno));
else {
+ memset(&hints, 0, sizeof(hints));
+ hints.ai_family = AF_INET;
+ hints.ai_socktype = 0;
if (Enabled(authp->physical->dl->bundle, OPT_NAS_IP_ADDRESS) &&
- (hp = gethostbyname(hostname)) != NULL) {
- hostaddr.s_addr = *(u_long *)hp->h_addr;
+ getaddrinfo(hostname, NULL, &hints, &res) == 0) {
+ hostaddr.s_addr = ((struct sockaddr_in *)res->ai_addr)->sin_addr.s_addr;
+ freeaddrinfo(res);
if (rad_put_addr(r->cx.rad, RAD_NAS_IP_ADDRESS, hostaddr) != 0) {
log_Printf(LogERROR, "rad_put: rad_put_string: %s\n",
rad_strerror(r->cx.rad));
@@ -1096,11 +1100,11 @@
radius_Account(struct radius *r, struct radacct *ac, struct datalink *dl,
int acct_type, struct pppThroughput *stats)
{
+ struct addrinfo hints, *res, *p;
struct timeval tv;
int got;
char hostname[MAXHOSTNAMELEN];
char *mac_addr;
- struct hostent *hp;
struct in_addr hostaddr;
if (!*r->cfg.file)
@@ -1207,9 +1211,13 @@
if (gethostname(hostname, sizeof hostname) != 0)
log_Printf(LogERROR, "rad_put: gethostname(): %s\n", strerror(errno));
else {
+ memset(&hints, 0, sizeof(hints));
+ hints.ai_family = AF_INET;
+ hints.ai_socktype = 0;
if (Enabled(dl->bundle, OPT_NAS_IP_ADDRESS) &&
- (hp = gethostbyname(hostname)) != NULL) {
- hostaddr.s_addr = *(u_long *)hp->h_addr;
+ getaddrinfo(hostname, NULL, &hints, &res) == 0) {
+ hostaddr.s_addr = ((struct sockaddr_in *)p->ai_addr)->sin_addr.s_addr;
+ freeaddrinfo(res);
if (rad_put_addr(r->cx.rad, RAD_NAS_IP_ADDRESS, hostaddr) != 0) {
log_Printf(LogERROR, "rad_put: rad_put_string: %s\n",
rad_strerror(r->cx.rad));
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Sun, Sep 6, 7:11 PM (18 h, 1 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
29515560
Default Alt Text
D45601.1788721888.diff (5 KB)
Attached To
Mode
D45601: ppp: remove gethostby*() calls
Attached
Detach File
Event Timeline
Log In to Comment