Skip to contentSkip to conversation

net: Make sure IPaddr_t is 32 bits in size

PATCH Superseded Matthias Weisser 3 participants 5 messages Dec 2, 2011 – Dec 6, 2011 Networking

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 net: Make sure IPaddr_t is 32 bits in size

When building u-boot as 64 bit application (e.g. sandbox) ulong might be 64 bits in size. This breaks network code as IPaddr_t is 64 bytes in size then. This patch makes sure that IPaddr_t is always 32 bits in size. Also some warnings introduced by this patch are fixed.

---
 include/net.h |    2 +-
 net/net.c     |    6 +++---
 net/nfs.c     |    2 +-
 net/tftp.c    |    2 +-
 4 files changed, 6 insertions(+), 6 deletions(-)
include/net.h +1 -1
index ad9afbf..9d878e5 100644
@@ -33,7 +33,7 @@
 
 #define PKTALIGN	32
 
-typedef ulong		IPaddr_t;
+typedef u32		IPaddr_t;
 
 
 /**
net/net.c +3 -3
index d0fe1c4..045405b 100644
@@ -728,7 +728,7 @@ NetSendUDPPacket(uchar *ether, IPaddr_t dest, int dport, int sport, int len)
 	 */
 	if (memcmp(ether, NetEtherNullAddr, 6) == 0) {
 
-		debug("sending ARP for %08lx\n", dest);
+		debug("sending ARP for %08x\n", dest);
 
 		NetArpWaitPacketIP = dest;
 		NetArpWaitPacketMAC = ether;
@@ -751,7 +751,7 @@ NetSendUDPPacket(uchar *ether, IPaddr_t dest, int dport, int sport, int len)
 		return 1;	/* waiting */
 	}
 
-	debug("sending UDP to %08lx/%pM\n", dest, ether);
+	debug("sending UDP to %08x/%pM\n", dest, ether);
 
 	pkt = (uchar *)NetTxPacket;
 	pkt += NetSetEther(pkt, ether, PROT_IP);
@@ -775,7 +775,7 @@ int PingSend(void)
 
 	memcpy(mac, NetEtherNullAddr, 6);
 
-	debug("sending ARP for %08lx\n", NetPingIP);
+	debug("sending ARP for %08x\n", NetPingIP);
 
 	NetArpWaitPacketIP = NetPingIP;
 	NetArpWaitPacketMAC = mac;
net/nfs.c +1 -1
index 5e717e3..b5b482c 100644
@@ -688,7 +688,7 @@ NfsStart (void)
 	}
 
 	if (BootFile[0] == '\0') {
-		sprintf (default_filename, "/nfsroot/%02lX%02lX%02lX%02lX.img",
+		sprintf(default_filename, "/nfsroot/%02X%02X%02X%02X.img",
 			NetOurIP & 0xFF,
 			(NetOurIP >>  8) & 0xFF,
 			(NetOurIP >> 16) & 0xFF,
net/tftp.c +1 -1
index 4999707..7aa3e23 100644
@@ -708,7 +708,7 @@ void TftpStart(enum proto_t protocol)
 
 	TftpRemoteIP = NetServerIP;
 	if (BootFile[0] == '\0') {
-		sprintf(default_filename, "%02lX%02lX%02lX%02lX.img",
+		sprintf(default_filename, "%02X%02X%02X%02X.img",
 			NetOurIP & 0xFF,
 			(NetOurIP >>  8) & 0xFF,
 			(NetOurIP >> 16) & 0xFF,
Signature · 1 line
1.7.5.4
#1 lore raw

PATCH 1/1 net: Make sure IPaddr_t is 32 bits in size

Quoted 4 lines · On Friday 02 December 2011 11:26:12 Matthias Weisser wrote:

When building u-boot as 64 bit application (e.g. sandbox) ulong might be 64 bits in size. This breaks network code as IPaddr_t is 64 bytes in size then. This patch makes sure that IPaddr_t is always 32 bits in size. Also some warnings introduced by this patch are fixed.

-mike
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 836 bytes
Desc: This is a digitally signed message part.
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20111202/88ff5f67/attachment.pgp>

#2 lore raw

PATCH 1/1 net: Make sure IPaddr_t is 32 bits in size

In reply to Matthias Weisser
Quoted 4 lines · On Friday 02 December 2011 11:26:12 Matthias Weisser wrote:

When building u-boot as 64 bit application (e.g. sandbox) ulong might be 64 bits in size. This breaks network code as IPaddr_t is 64 bytes in size then. This patch makes sure that IPaddr_t is always 32 bits in size. Also some warnings introduced by this patch are fixed.

on 2nd thought, could you clarify why we want it to be 32bits ? it's because that's the size of the address field in an IPv4 packet ...

include/net.h line 36

Quoted 5 lines
include/net.h +1 -1
 
-typedef ulong		IPaddr_t;
+typedef u32		IPaddr_t;

and add a comment here too ...
-mike
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 836 bytes
Desc: This is a digitally signed message part.
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20111202/63b3aa26/attachment.pgp>

#3 lore raw

PATCH v2 1/1 net: Make sure IPaddr_t is 32 bits in size

In reply to Matthias Weisser

When building u-boot as 64 bit application (e.g. sandbox) ulong might be 64 bits in size. This breaks network code as IPaddr_t is 64 bytes in size then and an IPv4 address is 32 bits in size. This patch makes sure that IPaddr_t is always 32 bits in size. Also some warnings introduced by this patch are fixed.

---
Changes in v2:
Added explicit information about 32 bit size of IPv4 addresses in commit message and source comment.

 include/net.h |    3 ++-
 net/net.c     |    6 +++---
 net/nfs.c     |    2 +-
 net/tftp.c    |    2 +-
 4 files changed, 7 insertions(+), 6 deletions(-)
include/net.h +2 -1
index ad9afbf..fa5d525 100644
@@ -33,7 +33,8 @@
 
 #define PKTALIGN	32
 
-typedef ulong		IPaddr_t;
+/* IPv4 addresses are always 32 bits in size */
+typedef u32		IPaddr_t;
 
 
 /**
net/net.c +3 -3
index d0fe1c4..045405b 100644
@@ -728,7 +728,7 @@ NetSendUDPPacket(uchar *ether, IPaddr_t dest, int dport, int sport, int len)
 	 */
 	if (memcmp(ether, NetEtherNullAddr, 6) == 0) {
 
-		debug("sending ARP for %08lx\n", dest);
+		debug("sending ARP for %08x\n", dest);
 
 		NetArpWaitPacketIP = dest;
 		NetArpWaitPacketMAC = ether;
@@ -751,7 +751,7 @@ NetSendUDPPacket(uchar *ether, IPaddr_t dest, int dport, int sport, int len)
 		return 1;	/* waiting */
 	}
 
-	debug("sending UDP to %08lx/%pM\n", dest, ether);
+	debug("sending UDP to %08x/%pM\n", dest, ether);
 
 	pkt = (uchar *)NetTxPacket;
 	pkt += NetSetEther(pkt, ether, PROT_IP);
@@ -775,7 +775,7 @@ int PingSend(void)
 
 	memcpy(mac, NetEtherNullAddr, 6);
 
-	debug("sending ARP for %08lx\n", NetPingIP);
+	debug("sending ARP for %08x\n", NetPingIP);
 
 	NetArpWaitPacketIP = NetPingIP;
 	NetArpWaitPacketMAC = mac;
net/nfs.c +1 -1
index 5e717e3..b5b482c 100644
@@ -688,7 +688,7 @@ NfsStart (void)
 	}
 
 	if (BootFile[0] == '\0') {
-		sprintf (default_filename, "/nfsroot/%02lX%02lX%02lX%02lX.img",
+		sprintf(default_filename, "/nfsroot/%02X%02X%02X%02X.img",
 			NetOurIP & 0xFF,
 			(NetOurIP >>  8) & 0xFF,
 			(NetOurIP >> 16) & 0xFF,
net/tftp.c +1 -1
index 4999707..7aa3e23 100644
@@ -708,7 +708,7 @@ void TftpStart(enum proto_t protocol)
 
 	TftpRemoteIP = NetServerIP;
 	if (BootFile[0] == '\0') {
-		sprintf(default_filename, "%02lX%02lX%02lX%02lX.img",
+		sprintf(default_filename, "%02X%02X%02X%02X.img",
 			NetOurIP & 0xFF,
 			(NetOurIP >>  8) & 0xFF,
 			(NetOurIP >> 16) & 0xFF,
Signature · 1 line
1.7.5.4
#4 lore raw

PATCH v2 1/1 net: Make sure IPaddr_t is 32 bits in size

Dear Matthias Weisser,

Quoted 13 lines · In message <[email protected]> you wrote:

When building u-boot as 64 bit application (e.g. sandbox) ulong might be 64 bits in size. This breaks network code as IPaddr_t is 64 bytes in size then and an IPv4 address is 32 bits in size. This patch makes sure that IPaddr_t is always 32 bits in size. Also some warnings introduced by this patch are fixed.

---
Changes in v2:
Added explicit information about 32 bit size of IPv4 addresses in commit message and source comment.

Quoted 5 lines
 include/net.h |    3 ++-
 net/net.c     |    6 +++---
 net/nfs.c     |    2 +-
 net/tftp.c    |    2 +-
 4 files changed, 7 insertions(+), 6 deletions(-)

Applied, thanks.

Best regards,

Wolfgang Denk

Signature · 5 lines
DENX Software Engineering GmbH,     MD: Wolfgang Denk & Detlev Zundel
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd at denx.de
The one who says it cannot be done should never interrupt the one who
is doing it.