[PATCH 06/11] net: use a random mac address if the current device does not have one
Sascha Hauer
s.hauer at pengutronix.de
Mon Jun 14 05:48:36 EDT 2010
Signed-off-by: Sascha Hauer <s.hauer at pengutronix.de>
---
net/net.c | 11 ++++++++++-
1 files changed, 10 insertions(+), 1 deletions(-)
diff --git a/net/net.c b/net/net.c
index 4305c72..8d99595 100644
--- a/net/net.c
+++ b/net/net.c
@@ -345,12 +345,21 @@ static LIST_HEAD(connection_list);
static struct net_connection *net_new(IPaddr_t dest, rx_handler_f *handler)
{
+ struct eth_device *edev = eth_get_current();
struct net_connection *con;
int ret;
- if (!is_valid_ether_addr(net_ether))
+ if (!edev)
return ERR_PTR(-ENETDOWN);
+ if (!is_valid_ether_addr(net_ether)) {
+ char str[sizeof("xx:xx:xx:xx:xx:xx")];
+ random_ether_addr(net_ether);
+ ethaddr_to_string(net_ether, str);
+ printf("warning: No MAC address set. Using random address %s\n", str);
+ dev_set_param(&edev->dev, "ethaddr", str);
+ }
+
/* If we don't have an ip only broadcast is allowed */
if (!net_ip && dest != 0xffffffff)
return ERR_PTR(-ENETDOWN);
--
1.7.1
More information about the barebox
mailing list