Page Menu
Home
FreeBSD
Search
Configure Global Search
Log In
Files
F142529945
D45601.id140648.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Flag For Later
Award Token
Size
4 KB
Referenced Files
None
Subscribers
None
D45601.id140648.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,20 @@
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 *res;
+ int error;
+
+ error = getaddrinfo(cp, NULL, &(struct addrinfo){
+ .ai_family = AF_INET
+ }, &res);
+ if (error == 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 *res;
struct in_addr host;
char name[MAXHOSTNAMELEN];
static const char * const timer_names[] =
{"IPCP restart", "IPCP openmode", "IPCP stopped"};
+ int error;
fsm_Init(&ipcp->fsm, "IPCP", PROTO_IPCP, 1, IPCP_MAXCODE, LogIPCP,
bundle, l, parent, &ipcp_Callbacks, timer_names);
@@ -463,9 +464,14 @@
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);
+ error = getaddrinfo(name, NULL, &(struct addrinfo){
+ .ai_family = AF_INET
+ }, &res);
+ if (error == 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,21 @@
static int
StrToAddr(const char *str, struct in_addr *addr)
{
- struct hostent *hp;
+ struct addrinfo *res;
+ int error;
if (inet_aton(str, addr))
return 0;
- hp = gethostbyname(str);
- if (!hp) {
+ error = getaddrinfo(str, NULL, &(struct addrinfo){
+ .ai_family = AF_INET
+ }, &res);
+ if (error != 0 ) {
log_Printf(LogWARN, "StrToAddr: Unknown host %s.\n", str);
return -1;
}
- *addr = *((struct in_addr *) hp->h_addr);
+ *addr = ((struct sockaddr_in *)res->ai_addr)->sin_addr;
+ freeaddrinfo(res);
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 *res;
struct in_addr hostaddr;
#ifndef NODES
struct mschap_response msresp;
@@ -1023,8 +1023,11 @@
log_Printf(LogERROR, "rad_put: gethostname(): %s\n", strerror(errno));
else {
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, &(struct addrinfo){
+ .ai_family = AF_INET
+ }, &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 +1099,11 @@
radius_Account(struct radius *r, struct radacct *ac, struct datalink *dl,
int acct_type, struct pppThroughput *stats)
{
+ struct addrinfo *res;
struct timeval tv;
int got;
char hostname[MAXHOSTNAMELEN];
char *mac_addr;
- struct hostent *hp;
struct in_addr hostaddr;
if (!*r->cfg.file)
@@ -1208,8 +1211,11 @@
log_Printf(LogERROR, "rad_put: gethostname(): %s\n", strerror(errno));
else {
if (Enabled(dl->bundle, OPT_NAS_IP_ADDRESS) &&
- (hp = gethostbyname(hostname)) != NULL) {
- hostaddr.s_addr = *(u_long *)hp->h_addr;
+ getaddrinfo(hostname, NULL, &(struct addrinfo){
+ .ai_family = AF_INET
+ }, &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));
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Wed, Jan 21, 4:20 PM (2 h, 13 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
27813273
Default Alt Text
D45601.id140648.diff (4 KB)
Attached To
Mode
D45601: ppp: remove gethostby*() calls
Attached
Detach File
Event Timeline
Log In to Comment