[U-Boot] [PATCH] net: Fix endianness bug in link-local

The ip is stored in network order, so we can't test it in host order.
Signed-off-by: Joe Hershberger joe.hershberger@ni.com --- net/link_local.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/net/link_local.c b/net/link_local.c index d52f13a..8a8f605 100644 --- a/net/link_local.c +++ b/net/link_local.c @@ -103,7 +103,7 @@ static void configure_wait(void) void link_local_start(void) { ip = getenv_IPaddr("llipaddr"); - if (ip != 0 && (ip & IN_CLASSB_NET) != LINKLOCAL_ADDR) { + if (ip != 0 && (htonl(ip) & IN_CLASSB_NET) != LINKLOCAL_ADDR) { puts("invalid link address"); net_set_state(NETLOOP_FAIL); return;

On Thu, 1 Nov 2012 22:05:54 -0500 Joe Hershberger joe.hershberger@ni.com wrote:
The ip is stored in network order, so we can't test it in host order.
Signed-off-by: Joe Hershberger joe.hershberger@ni.com
net/link_local.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/net/link_local.c b/net/link_local.c index d52f13a..8a8f605 100644 --- a/net/link_local.c +++ b/net/link_local.c @@ -103,7 +103,7 @@ static void configure_wait(void) void link_local_start(void) { ip = getenv_IPaddr("llipaddr");
- if (ip != 0 && (ip & IN_CLASSB_NET) != LINKLOCAL_ADDR) {
- if (ip != 0 && (htonl(ip) & IN_CLASSB_NET) != LINKLOCAL_ADDR) {
those constants are in host order, so don't you mean to use ntohl?
Kim

Hi Kim,
On Fri, Nov 2, 2012 at 2:58 PM, Kim Phillips kim.phillips@freescale.com wrote:
On Thu, 1 Nov 2012 22:05:54 -0500 Joe Hershberger joe.hershberger@ni.com wrote:
The ip is stored in network order, so we can't test it in host order.
Signed-off-by: Joe Hershberger joe.hershberger@ni.com
net/link_local.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/net/link_local.c b/net/link_local.c index d52f13a..8a8f605 100644 --- a/net/link_local.c +++ b/net/link_local.c @@ -103,7 +103,7 @@ static void configure_wait(void) void link_local_start(void) { ip = getenv_IPaddr("llipaddr");
if (ip != 0 && (ip & IN_CLASSB_NET) != LINKLOCAL_ADDR) {
if (ip != 0 && (htonl(ip) & IN_CLASSB_NET) != LINKLOCAL_ADDR) {
those constants are in host order, so don't you mean to use ntohl?
Yes, you are correct. I'll update the patch.
-Joe

The ip is stored in network order, so we can't test it in host order.
Signed-off-by: Joe Hershberger joe.hershberger@ni.com --- Changes in v2: - Changed htonl() to ntohl()
net/link_local.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/net/link_local.c b/net/link_local.c index d52f13a..1ba796e 100644 --- a/net/link_local.c +++ b/net/link_local.c @@ -103,7 +103,7 @@ static void configure_wait(void) void link_local_start(void) { ip = getenv_IPaddr("llipaddr"); - if (ip != 0 && (ip & IN_CLASSB_NET) != LINKLOCAL_ADDR) { + if (ip != 0 && (ntohl(ip) & IN_CLASSB_NET) != LINKLOCAL_ADDR) { puts("invalid link address"); net_set_state(NETLOOP_FAIL); return;

On Mon, 5 Nov 2012 10:13:45 -0600 Joe Hershberger joe.hershberger@ni.com wrote:
The ip is stored in network order, so we can't test it in host order.
Signed-off-by: Joe Hershberger joe.hershberger@ni.com
Changes in v2:
- Changed htonl() to ntohl()
Reviewed-by: Kim Phillips kim.phillips@freescale.com
Kim
participants (3)
-
Joe Hershberger
-
Joe Hershberger
-
Kim Phillips