Transforming eth addr string to a sequence of numbers
Here is a function that takes a srting in a form 11:22:33:44:55:66,
or similar (for example 000001:022:3:000000000000000044:5:06) and transform it in a sequence of hex nubers to be stored in the appropriate nvram structure field, which is of type char eth_address[6] (so it really takes number, not string chars and ':' delimiters) :
int i = 0;
char *s = my_eth_addr_string;
char *e = NULL;
for (i = 0; i < 6; i++)
{
nvram.eth_address[i] = s ? strtoul (s, &e, 16) : 0;
if (s)
s = (*e) ? e + 1 : e;
}
or similar (for example 000001:022:3:000000000000000044:5:06) and transform it in a sequence of hex nubers to be stored in the appropriate nvram structure field, which is of type char eth_address[6] (so it really takes number, not string chars and ':' delimiters) :
int i = 0;
char *s = my_eth_addr_string;
char *e = NULL;
for (i = 0; i < 6; i++)
{
nvram.eth_address[i] = s ? strtoul (s, &e, 16) : 0;
if (s)
s = (*e) ? e + 1 : e;
}
0 Comments:
Post a Comment
Subscribe to Post Comments [Atom]
<< Home