forked from Imagelibrary/rtems
Patch from Eric Norum <eric@skatter.usask.ca> to improve parsing of
network interface names. This change does not introduce any compatibility problems.
This commit is contained in:
@@ -116,6 +116,7 @@ struct file;
|
||||
struct buf;
|
||||
struct tty;
|
||||
struct uio;
|
||||
struct rtems_bsdnet_ifconfig;
|
||||
|
||||
/*
|
||||
* Redo kernel memory allocation
|
||||
@@ -130,6 +131,7 @@ void rtems_bsdnet_free (void *addr, int type);
|
||||
void rtems_bsdnet_semaphore_obtain (void);
|
||||
void rtems_bsdnet_semaphore_release (void);
|
||||
void rtems_bsdnet_schednetisr (int n);
|
||||
int rtems_bsdnet_parse_driver_name (const struct rtems_bsdnet_ifconfig *config, char **namep);
|
||||
|
||||
unsigned long rtems_bsdnet_seconds_since_boot (void);
|
||||
unsigned long rtems_bsdnet_random (void);
|
||||
|
||||
@@ -882,3 +882,46 @@ rtems_bsdnet_initialize_network (void)
|
||||
(*rtems_bsdnet_config.bootp)();
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* Parse a network driver name into a name and a unit number
|
||||
*/
|
||||
int
|
||||
rtems_bsdnet_parse_driver_name (const struct rtems_bsdnet_ifconfig *config, char **namep)
|
||||
{
|
||||
const char *cp = config->name;
|
||||
char c;
|
||||
int unitNumber = 0;
|
||||
|
||||
if (cp == NULL) {
|
||||
printf ("No network driver name");
|
||||
return -1;
|
||||
}
|
||||
while ((c = *cp++) != '\0') {
|
||||
if ((c >= '0') && (c <= '9')) {
|
||||
int len = cp - config->name - 1;
|
||||
if ((len < 2) || (len > 50))
|
||||
break;
|
||||
for (;;) {
|
||||
unitNumber = (unitNumber * 10) + (c - '0');
|
||||
c = *cp++;
|
||||
if (c == '\0') {
|
||||
char *unitName = malloc (len);
|
||||
if (unitName == NULL) {
|
||||
printf ("No memory");
|
||||
return -1;
|
||||
}
|
||||
strncpy (unitName, config->name, len - 1);
|
||||
unitName[len-1] = '\0';
|
||||
*namep = unitName;
|
||||
return unitNumber;
|
||||
}
|
||||
if ((c < '0') || (c > '9'))
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
printf ("Bad network driver name `%s'", config->name);
|
||||
return -1;
|
||||
}
|
||||
|
||||
@@ -852,19 +852,26 @@ rtems_scc1_driver_attach (struct rtems_bsdnet_ifconfig *config)
|
||||
struct scc_softc *sc;
|
||||
struct ifnet *ifp;
|
||||
int mtu;
|
||||
int i;
|
||||
int unitNumber;
|
||||
char *unitName;
|
||||
|
||||
/*
|
||||
* Find a free driver
|
||||
* Parse driver name
|
||||
*/
|
||||
for (i = 0 ; i < NSCCDRIVER ; i++) {
|
||||
sc = &scc_softc[i];
|
||||
ifp = &sc->arpcom.ac_if;
|
||||
if (ifp->if_softc == NULL)
|
||||
break;
|
||||
if ((unitNumber = rtems_bsdnet_parse_driver_name (config, &unitName)) < 0)
|
||||
return 0;
|
||||
|
||||
/*
|
||||
* Is driver free?
|
||||
*/
|
||||
if ((unitNumber <= 0) || (unitNumber > NSCCDRIVER)) {
|
||||
printf ("Bad SCC unit number.\n");
|
||||
return 0;
|
||||
}
|
||||
if (i >= NSCCDRIVER) {
|
||||
printf ("Too many SCC drivers.\n");
|
||||
sc = &scc_softc[unitNumber - 1];
|
||||
ifp = &sc->arpcom.ac_if;
|
||||
if (ifp->if_softc != NULL) {
|
||||
printf ("Driver already in use.\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -930,8 +937,8 @@ rtems_scc1_driver_attach (struct rtems_bsdnet_ifconfig *config)
|
||||
* Set up network interface values
|
||||
*/
|
||||
ifp->if_softc = sc;
|
||||
ifp->if_unit = i + 1;
|
||||
ifp->if_name = "scc";
|
||||
ifp->if_unit = unitNumber;
|
||||
ifp->if_name = unitName;
|
||||
ifp->if_mtu = mtu;
|
||||
ifp->if_init = scc_init;
|
||||
ifp->if_ioctl = scc_ioctl;
|
||||
|
||||
@@ -116,6 +116,7 @@ struct file;
|
||||
struct buf;
|
||||
struct tty;
|
||||
struct uio;
|
||||
struct rtems_bsdnet_ifconfig;
|
||||
|
||||
/*
|
||||
* Redo kernel memory allocation
|
||||
@@ -130,6 +131,7 @@ void rtems_bsdnet_free (void *addr, int type);
|
||||
void rtems_bsdnet_semaphore_obtain (void);
|
||||
void rtems_bsdnet_semaphore_release (void);
|
||||
void rtems_bsdnet_schednetisr (int n);
|
||||
int rtems_bsdnet_parse_driver_name (const struct rtems_bsdnet_ifconfig *config, char **namep);
|
||||
|
||||
unsigned long rtems_bsdnet_seconds_since_boot (void);
|
||||
unsigned long rtems_bsdnet_random (void);
|
||||
|
||||
@@ -882,3 +882,46 @@ rtems_bsdnet_initialize_network (void)
|
||||
(*rtems_bsdnet_config.bootp)();
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* Parse a network driver name into a name and a unit number
|
||||
*/
|
||||
int
|
||||
rtems_bsdnet_parse_driver_name (const struct rtems_bsdnet_ifconfig *config, char **namep)
|
||||
{
|
||||
const char *cp = config->name;
|
||||
char c;
|
||||
int unitNumber = 0;
|
||||
|
||||
if (cp == NULL) {
|
||||
printf ("No network driver name");
|
||||
return -1;
|
||||
}
|
||||
while ((c = *cp++) != '\0') {
|
||||
if ((c >= '0') && (c <= '9')) {
|
||||
int len = cp - config->name - 1;
|
||||
if ((len < 2) || (len > 50))
|
||||
break;
|
||||
for (;;) {
|
||||
unitNumber = (unitNumber * 10) + (c - '0');
|
||||
c = *cp++;
|
||||
if (c == '\0') {
|
||||
char *unitName = malloc (len);
|
||||
if (unitName == NULL) {
|
||||
printf ("No memory");
|
||||
return -1;
|
||||
}
|
||||
strncpy (unitName, config->name, len - 1);
|
||||
unitName[len-1] = '\0';
|
||||
*namep = unitName;
|
||||
return unitNumber;
|
||||
}
|
||||
if ((c < '0') || (c > '9'))
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
printf ("Bad network driver name `%s'", config->name);
|
||||
return -1;
|
||||
}
|
||||
|
||||
@@ -116,6 +116,7 @@ struct file;
|
||||
struct buf;
|
||||
struct tty;
|
||||
struct uio;
|
||||
struct rtems_bsdnet_ifconfig;
|
||||
|
||||
/*
|
||||
* Redo kernel memory allocation
|
||||
@@ -130,6 +131,7 @@ void rtems_bsdnet_free (void *addr, int type);
|
||||
void rtems_bsdnet_semaphore_obtain (void);
|
||||
void rtems_bsdnet_semaphore_release (void);
|
||||
void rtems_bsdnet_schednetisr (int n);
|
||||
int rtems_bsdnet_parse_driver_name (const struct rtems_bsdnet_ifconfig *config, char **namep);
|
||||
|
||||
unsigned long rtems_bsdnet_seconds_since_boot (void);
|
||||
unsigned long rtems_bsdnet_random (void);
|
||||
|
||||
@@ -882,3 +882,46 @@ rtems_bsdnet_initialize_network (void)
|
||||
(*rtems_bsdnet_config.bootp)();
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* Parse a network driver name into a name and a unit number
|
||||
*/
|
||||
int
|
||||
rtems_bsdnet_parse_driver_name (const struct rtems_bsdnet_ifconfig *config, char **namep)
|
||||
{
|
||||
const char *cp = config->name;
|
||||
char c;
|
||||
int unitNumber = 0;
|
||||
|
||||
if (cp == NULL) {
|
||||
printf ("No network driver name");
|
||||
return -1;
|
||||
}
|
||||
while ((c = *cp++) != '\0') {
|
||||
if ((c >= '0') && (c <= '9')) {
|
||||
int len = cp - config->name - 1;
|
||||
if ((len < 2) || (len > 50))
|
||||
break;
|
||||
for (;;) {
|
||||
unitNumber = (unitNumber * 10) + (c - '0');
|
||||
c = *cp++;
|
||||
if (c == '\0') {
|
||||
char *unitName = malloc (len);
|
||||
if (unitName == NULL) {
|
||||
printf ("No memory");
|
||||
return -1;
|
||||
}
|
||||
strncpy (unitName, config->name, len - 1);
|
||||
unitName[len-1] = '\0';
|
||||
*namep = unitName;
|
||||
return unitNumber;
|
||||
}
|
||||
if ((c < '0') || (c > '9'))
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
printf ("Bad network driver name `%s'", config->name);
|
||||
return -1;
|
||||
}
|
||||
|
||||
@@ -116,6 +116,7 @@ struct file;
|
||||
struct buf;
|
||||
struct tty;
|
||||
struct uio;
|
||||
struct rtems_bsdnet_ifconfig;
|
||||
|
||||
/*
|
||||
* Redo kernel memory allocation
|
||||
@@ -130,6 +131,7 @@ void rtems_bsdnet_free (void *addr, int type);
|
||||
void rtems_bsdnet_semaphore_obtain (void);
|
||||
void rtems_bsdnet_semaphore_release (void);
|
||||
void rtems_bsdnet_schednetisr (int n);
|
||||
int rtems_bsdnet_parse_driver_name (const struct rtems_bsdnet_ifconfig *config, char **namep);
|
||||
|
||||
unsigned long rtems_bsdnet_seconds_since_boot (void);
|
||||
unsigned long rtems_bsdnet_random (void);
|
||||
|
||||
@@ -882,3 +882,46 @@ rtems_bsdnet_initialize_network (void)
|
||||
(*rtems_bsdnet_config.bootp)();
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* Parse a network driver name into a name and a unit number
|
||||
*/
|
||||
int
|
||||
rtems_bsdnet_parse_driver_name (const struct rtems_bsdnet_ifconfig *config, char **namep)
|
||||
{
|
||||
const char *cp = config->name;
|
||||
char c;
|
||||
int unitNumber = 0;
|
||||
|
||||
if (cp == NULL) {
|
||||
printf ("No network driver name");
|
||||
return -1;
|
||||
}
|
||||
while ((c = *cp++) != '\0') {
|
||||
if ((c >= '0') && (c <= '9')) {
|
||||
int len = cp - config->name - 1;
|
||||
if ((len < 2) || (len > 50))
|
||||
break;
|
||||
for (;;) {
|
||||
unitNumber = (unitNumber * 10) + (c - '0');
|
||||
c = *cp++;
|
||||
if (c == '\0') {
|
||||
char *unitName = malloc (len);
|
||||
if (unitName == NULL) {
|
||||
printf ("No memory");
|
||||
return -1;
|
||||
}
|
||||
strncpy (unitName, config->name, len - 1);
|
||||
unitName[len-1] = '\0';
|
||||
*namep = unitName;
|
||||
return unitNumber;
|
||||
}
|
||||
if ((c < '0') || (c > '9'))
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
printf ("Bad network driver name `%s'", config->name);
|
||||
return -1;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user