9
0
Fork 0

eth: check for valid parameters for ethaddr, ipaddr, ...

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
This commit is contained in:
Sascha Hauer 2008-08-20 13:21:55 +02:00
parent c0d02ffc3d
commit 51b4de421e
1 changed files with 32 additions and 0 deletions

View File

@ -28,6 +28,7 @@
#include <net.h>
#include <miiphy.h>
#include <errno.h>
#include <malloc.h>
static struct eth_device *eth_current;
@ -83,6 +84,32 @@ int eth_rx(void)
return eth_current->recv(eth_current);
}
static int eth_set_ethaddr(struct device_d *dev, struct param_d *param, const char *val)
{
char ethaddr[sizeof("xx:xx:xx:xx:xx:xx")];
if (string_to_ethaddr(val, ethaddr) < 0)
return -EINVAL;
free(param->value);
param->value = strdup(val);
return 0;
}
static int eth_set_ipaddr(struct device_d *dev, struct param_d *param, const char *val)
{
IPaddr_t ip;
if (string_to_ip(val, &ip))
return -EINVAL;
free(param->value);
param->value = strdup(val);
return 0;
}
int eth_register(struct eth_device *edev)
{
struct device_d *dev = edev->dev;
@ -95,10 +122,15 @@ int eth_register(struct eth_device *edev)
}
edev->param_ip.name = "ipaddr";
edev->param_ip.set = &eth_set_ipaddr;
edev->param_ethaddr.name = "ethaddr";
edev->param_ethaddr.set = &eth_set_ethaddr;
edev->param_gateway.name = "gateway";
edev->param_gateway.set = &eth_set_ipaddr;
edev->param_netmask.name = "netmask";
edev->param_netmask.set = &eth_set_ipaddr;
edev->param_serverip.name = "serverip";
edev->param_serverip.set = &eth_set_ipaddr;
dev_add_param(dev, &edev->param_ip);
dev_add_param(dev, &edev->param_ethaddr);
dev_add_param(dev, &edev->param_gateway);