[syslinux:master] pxe: fix ip_ok()

syslinux-bot for H. Peter Anvin hpa at zytor.com
Thu Jun 24 20:57:02 PDT 2010


Commit-ID:  1b1d3fa2adac6215bd0fbe3d7a5ba5ecb8ba8eac
Gitweb:     http://syslinux.zytor.com/commit/1b1d3fa2adac6215bd0fbe3d7a5ba5ecb8ba8eac
Author:     H. Peter Anvin <hpa at zytor.com>
AuthorDate: Thu, 24 Jun 2010 20:55:43 -0700
Committer:  H. Peter Anvin <hpa at zytor.com>
CommitDate: Thu, 24 Jun 2010 20:55:43 -0700

pxe: fix ip_ok()

Make it easier to read, but fix the address for the loopback network
(127, not 255).

Signed-off-by: H. Peter Anvin <hpa at zytor.com>


---
 core/fs/pxe/pxe.c |   16 +++++++++-------
 core/fs/pxe/pxe.h |    2 +-
 2 files changed, 10 insertions(+), 8 deletions(-)

diff --git a/core/fs/pxe/pxe.c b/core/fs/pxe/pxe.c
index e2bd29c..231c4e5 100644
--- a/core/fs/pxe/pxe.c
+++ b/core/fs/pxe/pxe.c
@@ -172,15 +172,17 @@ static int hexbyte(const char *p)
  * assignable unicast addresses in the near future.
  *
  */
-int ip_ok(uint32_t ip)
+bool ip_ok(uint32_t ip)
 {
-    if (ip == -1 ||            /* Refuse the all-one address */
-        (ip & 0xff) == 0 ||    /* Refuse network zero */
-        (ip & 0xff) == 0xff || /* Refuse loopback */
-        (ip & 0xf0) == 0xe0 )  /* Refuse class D */
-        return 0;
+    uint8_t ip_hi = (uint8_t)ip; /* First octet of the ip address */
+
+    if (ip == 0xffffffff ||	/* Refuse the all-ones address */
+	ip_hi == 0 ||		/* Refuse network zero */
+	ip_hi == 127 ||		/* Refuse the loopback network */
+	(ip_hi & 240) == 224)	/* Refuse class D */
+	return false;
 
-    return 1;
+    return true;
 }
 
 
diff --git a/core/fs/pxe/pxe.h b/core/fs/pxe/pxe.h
index cad6350..0541bf0 100644
--- a/core/fs/pxe/pxe.h
+++ b/core/fs/pxe/pxe.h
@@ -232,7 +232,7 @@ static inline uint32_t gateway(uint32_t ip)
  */
 
 /* pxe.c */
-int ip_ok(uint32_t);
+bool ip_ok(uint32_t);
 int pxe_call(int, void *);
 
 /* dhcp_options.c */



More information about the Syslinux-commits mailing list