Index | Thread | Search

From:
Florian Obser <florian@openbsd.org>
Subject:
pppd(8): Mechanically change inet_aton to inet_pton.
To:
tech <tech@openbsd.org>
Date:
Wed, 21 Aug 2024 13:13:47 +0200

Download raw body.

Thread
This could use getaddrinfo(3) in places but the code is just too crufty
and my joo janta's turned black immediately. I went with the minimal
change.

Not a user of pppd for decades...

Tests, OKs?

diff --git auth.c auth.c
index 2919a87799c..edadc842d57 100644
--- auth.c
+++ auth.c
@@ -972,7 +972,7 @@ set_allowed_addrs(int unit, struct wordlist *addrs)
 	    hp = gethostbyname(p);
 	    if (hp != NULL && hp->h_addrtype == AF_INET)
 		wo->hisaddr = *(u_int32_t *)hp->h_addr;
-	    else if (inet_aton(p, &ina) == 1)
+	    else if (inet_pton(AF_INET, p, &ina) == 1)
 		wo->hisaddr = ina.s_addr;
 	}
     }
@@ -1038,7 +1038,7 @@ ip_addr_check(u_int32_t addr, struct wordlist *addrs)
 	if (hp != NULL && hp->h_addrtype == AF_INET) {
 	    ina.s_addr = *(u_int32_t *)hp->h_addr;
 	} else {
-	    r = inet_aton (ptr_word, &ina);
+	    r = inet_pton(AF_INET, ptr_word, &ina);
 	    if (ptr_mask == NULL) {
 		/* calculate appropriate mask for net */
 		ah = ntohl(ina.s_addr);
@@ -1054,7 +1054,7 @@ ip_addr_check(u_int32_t addr, struct wordlist *addrs)
 	if (ptr_mask != NULL)
 	    *ptr_mask = '/';
 
-	if (r == 0)
+	if (r != 1)
 	    syslog (LOG_WARNING,
 		    "unknown host %s in auth. address list",
 		    addrs->word);
diff --git options.c options.c
index 0df6215d2bf..d499feb8df7 100644
--- options.c
+++ options.c
@@ -42,6 +42,10 @@
  * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  */
 
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <sys/stat.h>
+
 #include <ctype.h>
 #include <stdio.h>
 #include <errno.h>
@@ -53,8 +57,6 @@
 #include <string.h>
 #include <netdb.h>
 #include <pwd.h>
-#include <sys/types.h>
-#include <sys/stat.h>
 #include <netinet/in.h>
 #include <arpa/inet.h>
 #ifdef PPP_FILTER
@@ -1565,7 +1567,7 @@ setipaddr(char *arg)
      */
     if (colon != arg) {
 	*colon = '\0';
-	if (inet_aton(arg, &ina) == 0) {
+	if (inet_pton(AF_INET, arg, &ina) != 1) {
 	    if ((hp = gethostbyname(arg)) == NULL) {
 		option_error("unknown host: %s", arg);
 		return -1;
@@ -1589,7 +1591,7 @@ setipaddr(char *arg)
      * If colon last character, then no remote addr.
      */
     if (*++colon != '\0') {
-	if (inet_aton(colon, &ina) == 0) {
+	if (inet_pton(AF_INET, colon, &ina) != 1) {
 	    if ((hp = gethostbyname(colon)) == NULL) {
 		option_error("unknown host: %s", colon);
 		return -1;
@@ -1653,7 +1655,7 @@ setnetmask(char **argv)
 {
     struct in_addr ina;
 
-    if (inet_aton(*argv, &ina) == 0 || (netmask & ~ina.s_addr) != 0) {
+    if (inet_pton(AF_INET, *argv, &ina) != 1 || (netmask & ~ina.s_addr) != 0) {
 	option_error("invalid netmask value '%s'", *argv);
 	return (0);
     }
@@ -2112,7 +2114,7 @@ setdnsaddr(char **argv)
     struct in_addr ina;
     struct hostent *hp;
 
-    if (inet_aton(*argv, &ina) == 0) {
+    if (inet_pton(AF_INET, *argv, &ina) != 1) {
 	if ((hp = gethostbyname(*argv)) == NULL) {
 	    option_error("invalid address parameter '%s' for ms-dns option",
 			 *argv);
@@ -2142,7 +2144,7 @@ setwinsaddr(char **argv)
     struct in_addr ina;
     struct hostent *hp;
 
-    if (inet_aton(*argv, &ina) == 0) {
+    if (inet_pton(AF_INET, *argv, &ina) != 1) {
 	if ((hp = gethostbyname(*argv)) == NULL) {
 	    option_error("invalid address parameter '%s' for ms-wins option",
 			 *argv);

-- 
In my defence, I have been left unsupervised.