Page Menu
Home
FreeBSD
Search
Configure Global Search
Log In
Files
F142276555
D45601.id139883.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Flag For Later
Award Token
Size
6 KB
Referenced Files
None
Subscribers
None
D45601.id139883.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,28 @@
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, *p;
+ 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) {
+ for (p = res; p != NULL; p = p->ai_next) {
+ if (p->ai_family == AF_INET) {
+ memcpy(&ipaddr, &((struct sockaddr_in *)p->ai_addr)->sin_addr,
+ sizeof(struct in_addr));
+ break;
+ }
+ }
+ freeaddrinfo(res);
+ if (p == NULL)
+ ipaddr.s_addr = INADDR_NONE;
+ }
+ 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, *p;
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,20 @@
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) {
+ for (p = res; p != NULL; p = p->ai_next) {
+ if (p->ai_family == AF_INET) {
+ memcpy(&host.s_addr, &((struct sockaddr_in *)p->ai_addr)->sin_addr.s_addr,
+ sizeof host.s_addr);
+ break;
+ }
+ }
+ 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
@@ -894,12 +894,12 @@
const char *key, int klen, const char *nchallenge,
int nclen)
{
+ struct addrinfo hints, *res, *p;
char hostname[MAXHOSTNAMELEN];
struct timeval tv;
const char *what = "questionable"; /* silence warnings! */
char *mac_addr;
int got;
- struct hostent *hp;
struct in_addr hostaddr;
#ifndef NODES
struct mschap_response msresp;
@@ -1022,10 +1022,19 @@
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;
- if (rad_put_addr(r->cx.rad, RAD_NAS_IP_ADDRESS, hostaddr) != 0) {
+ getaddrinfo(hostname, NULL, &hints, &res) == 0) {
+ for (p = res; p != NULL; p = p->ai_next) {
+ if (p->ai_family == AF_INET) {
+ hostaddr.s_addr = ((struct sockaddr_in *)p->ai_addr)->sin_addr.s_addr;
+ break;
+ }
+ }
+ freeaddrinfo(res);
+ if (p != NULL && 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));
rad_close(r->cx.rad);
@@ -1096,11 +1105,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,10 +1216,19 @@
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;
- if (rad_put_addr(r->cx.rad, RAD_NAS_IP_ADDRESS, hostaddr) != 0) {
+ getaddrinfo(hostname, NULL, &hints, &res) == 0) {
+ for (p = res; p != NULL; p = p->ai_next) {
+ if (p->ai_family == AF_INET) {
+ hostaddr.s_addr = ((struct sockaddr_in *)p->ai_addr)->sin_addr.s_addr;
+ break;
+ }
+ }
+ freeaddrinfo(res);
+ if (p != NULL && 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));
rad_close(r->cx.rad);
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Mon, Jan 19, 2:14 AM (6 h, 2 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
27727368
Default Alt Text
D45601.id139883.diff (6 KB)
Attached To
Mode
D45601: ppp: remove gethostby*() calls
Attached
Detach File
Event Timeline
Log In to Comment