summaryrefslogtreecommitdiff
path: root/net
diff options
context:
space:
mode:
Diffstat (limited to 'net')
-rw-r--r--net/bootp.c29
-rw-r--r--net/eth.c69
-rw-r--r--net/net.c30
-rw-r--r--net/nfs.c10
-rw-r--r--net/tftp.c10
5 files changed, 58 insertions, 90 deletions
diff --git a/net/bootp.c b/net/bootp.c
index 83465e4..3dea70aa 100644
--- a/net/bootp.c
+++ b/net/bootp.c
@@ -271,17 +271,11 @@ static void BootpVendorProcess (u8 * ext, int size)
#ifdef DEBUG_BOOTP_EXT
puts ("[BOOTP] Received fields: \n");
- if (NetOurSubnetMask) {
- puts ("NetOurSubnetMask : ");
- print_IPaddr (NetOurSubnetMask);
- putc ('\n');
- }
+ if (NetOurSubnetMask)
+ printf ("NetOurSubnetMask : %pI4\n", &NetOurSubnetMask);
- if (NetOurGatewayIP) {
- puts ("NetOurGatewayIP : ");
- print_IPaddr (NetOurGatewayIP);
- putc ('\n');
- }
+ if (NetOurGatewayIP)
+ printf ("NetOurGatewayIP : %pI4", &NetOurGatewayIP);
if (NetBootFileSize) {
printf ("NetBootFileSize : %d\n", NetBootFileSize);
@@ -579,21 +573,12 @@ BootpRequest (void)
#ifdef CONFIG_BOOTP_RANDOM_DELAY /* Random BOOTP delay */
unsigned char bi_enetaddr[6];
int reg;
- char *e,*s;
- char tmp[64];
ulong tst1, tst2, sum, m_mask, m_value = 0;
if (BootpTry ==0) {
/* get our mac */
- reg = getenv_r ("ethaddr", tmp, sizeof(tmp));
- s = (reg > 0) ? tmp : NULL;
+ eth_getenv_enetaddr("ethaddr", bi_enetaddr);
- for (reg=0; reg<6; ++reg) {
- bi_enetaddr[reg] = s ? simple_strtoul(s, &e, 16) : 0;
- if (s) {
- s = (*e) ? e+1 : e;
- }
- }
#ifdef DEBUG
puts ("BootpRequest => Our Mac: ");
for (reg=0; reg<6; reg++) {
@@ -942,9 +927,7 @@ DhcpHandler(uchar * pkt, unsigned dest, unsigned src, unsigned len)
DhcpOptionsProcess((u8 *)&bp->bp_vend[4], bp);
BootpCopyNetParams(bp); /* Store net params from reply */
dhcp_state = BOUND;
- puts ("DHCP client bound to address ");
- print_IPaddr(NetOurIP);
- putc ('\n');
+ printf ("DHCP client bound to address %pI4\n", &NetOurIP);
/* Obey the 'autoload' setting */
if ((s = getenv("autoload")) != NULL) {
diff --git a/net/eth.c b/net/eth.c
index 217e885..4bbf84b 100644
--- a/net/eth.c
+++ b/net/eth.c
@@ -26,6 +26,35 @@
#include <net.h>
#include <miiphy.h>
+#ifdef CONFIG_CMD_NET
+void eth_parse_enetaddr(const char *addr, uchar *enetaddr)
+{
+ char *end;
+ int i;
+
+ for (i = 0; i < 6; ++i) {
+ enetaddr[i] = addr ? simple_strtoul(addr, &end, 16) : 0;
+ if (addr)
+ addr = (*end) ? end + 1 : end;
+ }
+}
+
+int eth_getenv_enetaddr(char *name, uchar *enetaddr)
+{
+ eth_parse_enetaddr(getenv(name), enetaddr);
+ return is_valid_ether_addr(enetaddr);
+}
+
+int eth_setenv_enetaddr(char *name, const uchar *enetaddr)
+{
+ char buf[20];
+
+ sprintf(buf, "%pM", enetaddr);
+
+ return setenv(name, buf);
+}
+#endif
+
#if defined(CONFIG_CMD_NET) && defined(CONFIG_NET_MULTI)
static char *act = NULL;
@@ -156,8 +185,7 @@ int eth_initialize(bd_t *bis)
{
char enetvar[32];
unsigned char env_enetaddr[6];
- int i, eth_number = 0;
- char *tmp, *end;
+ int eth_number = 0;
eth_devices = NULL;
eth_current = NULL;
@@ -197,13 +225,7 @@ int eth_initialize(bd_t *bis)
}
sprintf(enetvar, eth_number ? "eth%daddr" : "ethaddr", eth_number);
- tmp = getenv (enetvar);
-
- for (i=0; i<6; i++) {
- env_enetaddr[i] = tmp ? simple_strtoul(tmp, &end, 16) : 0;
- if (tmp)
- tmp = (*end) ? end+1 : end;
- }
+ eth_getenv_enetaddr(enetvar, env_enetaddr);
if (memcmp(env_enetaddr, "\0\0\0\0\0\0", 6)) {
if (memcmp(dev->enetaddr, "\0\0\0\0\0\0", 6) &&
@@ -211,16 +233,10 @@ int eth_initialize(bd_t *bis)
{
printf ("\nWarning: %s MAC addresses don't match:\n",
dev->name);
- printf ("Address in SROM is "
- "%02X:%02X:%02X:%02X:%02X:%02X\n",
- dev->enetaddr[0], dev->enetaddr[1],
- dev->enetaddr[2], dev->enetaddr[3],
- dev->enetaddr[4], dev->enetaddr[5]);
- printf ("Address in environment is "
- "%02X:%02X:%02X:%02X:%02X:%02X\n",
- env_enetaddr[0], env_enetaddr[1],
- env_enetaddr[2], env_enetaddr[3],
- env_enetaddr[4], env_enetaddr[5]);
+ printf ("Address in SROM is %pM\n",
+ dev->enetaddr);
+ printf ("Address in environment is %pM\n",
+ env_enetaddr);
}
memcpy(dev->enetaddr, env_enetaddr, 6);
@@ -249,19 +265,13 @@ int eth_initialize(bd_t *bis)
void eth_set_enetaddr(int num, char *addr) {
struct eth_device *dev;
unsigned char enetaddr[6];
- char *end;
- int i;
debug ("eth_set_enetaddr(num=%d, addr=%s)\n", num, addr);
if (!eth_devices)
return;
- for (i=0; i<6; i++) {
- enetaddr[i] = addr ? simple_strtoul(addr, &end, 16) : 0;
- if (addr)
- addr = (*end) ? end+1 : end;
- }
+ eth_parse_enetaddr(addr, enetaddr);
dev = eth_devices;
while(num-- > 0) {
@@ -272,11 +282,8 @@ void eth_set_enetaddr(int num, char *addr) {
}
debug ( "Setting new HW address on %s\n"
- "New Address is %02X:%02X:%02X:%02X:%02X:%02X\n",
- dev->name,
- enetaddr[0], enetaddr[1],
- enetaddr[2], enetaddr[3],
- enetaddr[4], enetaddr[5]);
+ "New Address is %pM\n",
+ dev->name, enetaddr);
memcpy(dev->enetaddr, enetaddr, 6);
}
diff --git a/net/net.c b/net/net.c
index a55f4d3..a89f6a0 100644
--- a/net/net.c
+++ b/net/net.c
@@ -404,7 +404,7 @@ restart:
#ifdef CONFIG_NET_MULTI
memcpy (NetOurEther, eth_get_dev()->enetaddr, 6);
#else
- memcpy (NetOurEther, bd->bi_enetaddr, 6);
+ eth_getenv_enetaddr("ethaddr", NetOurEther);
#endif
NetState = NETLOOP_CONTINUE;
@@ -709,8 +709,7 @@ NetSendUDPPacket(uchar *ether, IPaddr_t dest, int dport, int sport, int len)
}
#ifdef ET_DEBUG
- printf("sending UDP to %08lx/%02x:%02x:%02x:%02x:%02x:%02x\n",
- dest, ether[0], ether[1], ether[2], ether[3], ether[4], ether[5]);
+ printf("sending UDP to %08lx/%pM\n", dest, ether);
#endif
pkt = (uchar *)NetTxPacket;
@@ -931,11 +930,7 @@ int CDPSendTrigger(void)
#ifdef CONFIG_CDP_DEVICE_ID
*s++ = htons(CDP_DEVICE_ID_TLV);
*s++ = htons(CONFIG_CDP_DEVICE_ID);
- memset(buf, 0, sizeof(buf));
- sprintf(buf, CONFIG_CDP_DEVICE_ID_PREFIX "%02X%02X%02X%02X%02X%02X",
- NetOurEther[0] & 0xff, NetOurEther[1] & 0xff,
- NetOurEther[2] & 0xff, NetOurEther[3] & 0xff,
- NetOurEther[4] & 0xff, NetOurEther[5] & 0xff);
+ sprintf(buf, CONFIG_CDP_DEVICE_ID_PREFIX "%pm", NetOurEther);
memcpy((uchar *)s, buf, 16);
s += 16 / 2;
#endif
@@ -1335,10 +1330,8 @@ NetReceive(volatile uchar * inpkt, int len)
if (!NetArpWaitPacketIP || !NetArpWaitPacketMAC)
break;
#ifdef ET_DEBUG
- printf("Got ARP REPLY, set server/gtwy eth addr (%02x:%02x:%02x:%02x:%02x:%02x)\n",
- arp->ar_data[0], arp->ar_data[1],
- arp->ar_data[2], arp->ar_data[3],
- arp->ar_data[4], arp->ar_data[5]);
+ printf("Got ARP REPLY, set server/gtwy eth addr (%pM)\n",
+ arp->ar_data);
#endif
tmp = NetReadIP(&arp->ar_data[6]);
@@ -1461,9 +1454,7 @@ NetReceive(volatile uchar * inpkt, int len)
case ICMP_REDIRECT:
if (icmph->code != ICMP_REDIR_HOST)
return;
- puts (" ICMP Host Redirect to ");
- print_IPaddr(icmph->un.gateway);
- putc(' ');
+ printf (" ICMP Host Redirect to %pI4 ", &icmph->un.gateway);
return;
#if defined(CONFIG_CMD_PING)
case ICMP_ECHO_REPLY:
@@ -1805,15 +1796,6 @@ ushort string_to_VLAN(char *s)
return htons(id);
}
-void print_IPaddr (IPaddr_t x)
-{
- char tmp[16];
-
- ip_to_string (x, tmp);
-
- puts (tmp);
-}
-
IPaddr_t getenv_IPaddr (char *var)
{
return (string_to_ip(getenv(var)));
diff --git a/net/nfs.c b/net/nfs.c
index f290014..0101629 100644
--- a/net/nfs.c
+++ b/net/nfs.c
@@ -741,18 +741,16 @@ NfsStart (void)
printf ("Using %s device\n", eth_get_name());
#endif
- puts ("File transfer via NFS from server "); print_IPaddr (NfsServerIP);
- puts ("; our IP address is "); print_IPaddr (NetOurIP);
+ printf("File transfer via NFS from server %pI4"
+ "; our IP address is %pI4", &NfsServerIP, &NetOurIP);
/* Check if we need to send across this subnet */
if (NetOurGatewayIP && NetOurSubnetMask) {
IPaddr_t OurNet = NetOurIP & NetOurSubnetMask;
IPaddr_t ServerNet = NetServerIP & NetOurSubnetMask;
- if (OurNet != ServerNet) {
- puts ("; sending through gateway ");
- print_IPaddr (NetOurGatewayIP) ;
- }
+ if (OurNet != ServerNet)
+ printf("; sending through gateway %pI4", &NetOurGatewayIP);
}
printf ("\nFilename '%s/%s'.", nfs_path, nfs_filename);
diff --git a/net/tftp.c b/net/tftp.c
index 3dac3d8..b0f1cca 100644
--- a/net/tftp.c
+++ b/net/tftp.c
@@ -508,18 +508,16 @@ TftpStart (void)
#if defined(CONFIG_NET_MULTI)
printf ("Using %s device\n", eth_get_name());
#endif
- puts ("TFTP from server "); print_IPaddr (TftpServerIP);
- puts ("; our IP address is "); print_IPaddr (NetOurIP);
+ printf("TFTP from server %pI4"
+ "; our IP address is %pI4", &TftpServerIP, &NetOurIP);
/* Check if we need to send across this subnet */
if (NetOurGatewayIP && NetOurSubnetMask) {
IPaddr_t OurNet = NetOurIP & NetOurSubnetMask;
IPaddr_t ServerNet = TftpServerIP & NetOurSubnetMask;
- if (OurNet != ServerNet) {
- puts ("; sending through gateway ");
- print_IPaddr (NetOurGatewayIP) ;
- }
+ if (OurNet != ServerNet)
+ printf("; sending through gateway %pI4", &NetOurGatewayIP);
}
putc ('\n');