Changeset b6f5f93 in rtems


Ignore:
Timestamp:
03/23/99 22:39:13 (24 years ago)
Author:
Joel Sherrill <joel.sherrill@…>
Branches:
4.10, 4.11, 4.8, 4.9, 5, master
Children:
f1f42b4
Parents:
ca3fec49
Message:

Patch from Eric Norum <eric@…> to improve parsing of
network interface names. This change does not introduce any
compatibility problems.

Files:
9 edited

Legend:

Unmodified
Added
Removed
  • c/src/exec/libnetworking/rtems/rtems_bsdnet_internal.h

    rca3fec49 rb6f5f93  
    117117struct  tty;
    118118struct  uio;
     119struct  rtems_bsdnet_ifconfig;
    119120
    120121/*
     
    131132void rtems_bsdnet_semaphore_release (void);
    132133void rtems_bsdnet_schednetisr (int n);
     134int rtems_bsdnet_parse_driver_name (const struct rtems_bsdnet_ifconfig *config, char **namep);
    133135
    134136unsigned long rtems_bsdnet_seconds_since_boot (void);
  • c/src/exec/libnetworking/rtems/rtems_glue.c

    rca3fec49 rb6f5f93  
    883883        return 0;
    884884}
     885
     886/*
     887 * Parse a network driver name into a name and a unit number
     888 */
     889int
     890rtems_bsdnet_parse_driver_name (const struct rtems_bsdnet_ifconfig *config, char **namep)
     891{
     892        const char *cp = config->name;
     893        char c;
     894        int unitNumber = 0;
     895
     896        if (cp == NULL) {
     897                printf ("No network driver name");
     898                return -1;
     899        }
     900        while ((c = *cp++) != '\0') {
     901                if ((c >= '0') && (c <= '9')) {
     902                        int len = cp - config->name - 1;
     903                        if ((len < 2) || (len > 50))
     904                                break;
     905                        for (;;) {
     906                                unitNumber = (unitNumber * 10) + (c - '0');
     907                                c = *cp++;
     908                                if (c == '\0') {
     909                                        char *unitName = malloc (len);
     910                                        if (unitName == NULL) {
     911                                                printf ("No memory");
     912                                                return -1;
     913                                        }
     914                                        strncpy (unitName, config->name, len - 1);
     915                                        unitName[len-1] = '\0';
     916                                        *namep = unitName;
     917                                        return unitNumber;
     918                                }
     919                                if ((c < '0') || (c > '9'))
     920                                        break;
     921                        }
     922                        break;
     923                }
     924        }
     925        printf ("Bad network driver name `%s'", config->name);
     926        return -1;
     927}
  • c/src/lib/libbsp/m68k/gen68360/network/network.c

    rca3fec49 rb6f5f93  
    853853        struct ifnet *ifp;
    854854        int mtu;
    855         int i;
    856 
    857         /*
    858          * Find a free driver
    859          */
    860         for (i = 0 ; i < NSCCDRIVER ; i++) {
    861                 sc = &scc_softc[i];
    862                 ifp = &sc->arpcom.ac_if;
    863                 if (ifp->if_softc == NULL)
    864                         break;
    865         }
    866         if (i >= NSCCDRIVER) {
    867                 printf ("Too many SCC drivers.\n");
     855        int unitNumber;
     856        char *unitName;
     857
     858        /*
     859         * Parse driver name
     860         */
     861        if ((unitNumber = rtems_bsdnet_parse_driver_name (config, &unitName)) < 0)
     862                return 0;
     863       
     864        /*
     865         * Is driver free?
     866         */
     867        if ((unitNumber <= 0) || (unitNumber > NSCCDRIVER)) {
     868                printf ("Bad SCC unit number.\n");
     869                return 0;
     870        }
     871        sc = &scc_softc[unitNumber - 1];
     872        ifp = &sc->arpcom.ac_if;
     873        if (ifp->if_softc != NULL) {
     874                printf ("Driver already in use.\n");
    868875                return 0;
    869876        }
     
    931938         */
    932939        ifp->if_softc = sc;
    933         ifp->if_unit = i + 1;
    934         ifp->if_name = "scc";
     940        ifp->if_unit = unitNumber;
     941        ifp->if_name = unitName;
    935942        ifp->if_mtu = mtu;
    936943        ifp->if_init = scc_init;
  • c/src/lib/libnetworking/rtems/rtems_bsdnet_internal.h

    rca3fec49 rb6f5f93  
    117117struct  tty;
    118118struct  uio;
     119struct  rtems_bsdnet_ifconfig;
    119120
    120121/*
     
    131132void rtems_bsdnet_semaphore_release (void);
    132133void rtems_bsdnet_schednetisr (int n);
     134int rtems_bsdnet_parse_driver_name (const struct rtems_bsdnet_ifconfig *config, char **namep);
    133135
    134136unsigned long rtems_bsdnet_seconds_since_boot (void);
  • c/src/lib/libnetworking/rtems/rtems_glue.c

    rca3fec49 rb6f5f93  
    883883        return 0;
    884884}
     885
     886/*
     887 * Parse a network driver name into a name and a unit number
     888 */
     889int
     890rtems_bsdnet_parse_driver_name (const struct rtems_bsdnet_ifconfig *config, char **namep)
     891{
     892        const char *cp = config->name;
     893        char c;
     894        int unitNumber = 0;
     895
     896        if (cp == NULL) {
     897                printf ("No network driver name");
     898                return -1;
     899        }
     900        while ((c = *cp++) != '\0') {
     901                if ((c >= '0') && (c <= '9')) {
     902                        int len = cp - config->name - 1;
     903                        if ((len < 2) || (len > 50))
     904                                break;
     905                        for (;;) {
     906                                unitNumber = (unitNumber * 10) + (c - '0');
     907                                c = *cp++;
     908                                if (c == '\0') {
     909                                        char *unitName = malloc (len);
     910                                        if (unitName == NULL) {
     911                                                printf ("No memory");
     912                                                return -1;
     913                                        }
     914                                        strncpy (unitName, config->name, len - 1);
     915                                        unitName[len-1] = '\0';
     916                                        *namep = unitName;
     917                                        return unitNumber;
     918                                }
     919                                if ((c < '0') || (c > '9'))
     920                                        break;
     921                        }
     922                        break;
     923                }
     924        }
     925        printf ("Bad network driver name `%s'", config->name);
     926        return -1;
     927}
  • c/src/libnetworking/rtems/rtems_bsdnet_internal.h

    rca3fec49 rb6f5f93  
    117117struct  tty;
    118118struct  uio;
     119struct  rtems_bsdnet_ifconfig;
    119120
    120121/*
     
    131132void rtems_bsdnet_semaphore_release (void);
    132133void rtems_bsdnet_schednetisr (int n);
     134int rtems_bsdnet_parse_driver_name (const struct rtems_bsdnet_ifconfig *config, char **namep);
    133135
    134136unsigned long rtems_bsdnet_seconds_since_boot (void);
  • c/src/libnetworking/rtems/rtems_glue.c

    rca3fec49 rb6f5f93  
    883883        return 0;
    884884}
     885
     886/*
     887 * Parse a network driver name into a name and a unit number
     888 */
     889int
     890rtems_bsdnet_parse_driver_name (const struct rtems_bsdnet_ifconfig *config, char **namep)
     891{
     892        const char *cp = config->name;
     893        char c;
     894        int unitNumber = 0;
     895
     896        if (cp == NULL) {
     897                printf ("No network driver name");
     898                return -1;
     899        }
     900        while ((c = *cp++) != '\0') {
     901                if ((c >= '0') && (c <= '9')) {
     902                        int len = cp - config->name - 1;
     903                        if ((len < 2) || (len > 50))
     904                                break;
     905                        for (;;) {
     906                                unitNumber = (unitNumber * 10) + (c - '0');
     907                                c = *cp++;
     908                                if (c == '\0') {
     909                                        char *unitName = malloc (len);
     910                                        if (unitName == NULL) {
     911                                                printf ("No memory");
     912                                                return -1;
     913                                        }
     914                                        strncpy (unitName, config->name, len - 1);
     915                                        unitName[len-1] = '\0';
     916                                        *namep = unitName;
     917                                        return unitNumber;
     918                                }
     919                                if ((c < '0') || (c > '9'))
     920                                        break;
     921                        }
     922                        break;
     923                }
     924        }
     925        printf ("Bad network driver name `%s'", config->name);
     926        return -1;
     927}
  • cpukit/libnetworking/rtems/rtems_bsdnet_internal.h

    rca3fec49 rb6f5f93  
    117117struct  tty;
    118118struct  uio;
     119struct  rtems_bsdnet_ifconfig;
    119120
    120121/*
     
    131132void rtems_bsdnet_semaphore_release (void);
    132133void rtems_bsdnet_schednetisr (int n);
     134int rtems_bsdnet_parse_driver_name (const struct rtems_bsdnet_ifconfig *config, char **namep);
    133135
    134136unsigned long rtems_bsdnet_seconds_since_boot (void);
  • cpukit/libnetworking/rtems/rtems_glue.c

    rca3fec49 rb6f5f93  
    883883        return 0;
    884884}
     885
     886/*
     887 * Parse a network driver name into a name and a unit number
     888 */
     889int
     890rtems_bsdnet_parse_driver_name (const struct rtems_bsdnet_ifconfig *config, char **namep)
     891{
     892        const char *cp = config->name;
     893        char c;
     894        int unitNumber = 0;
     895
     896        if (cp == NULL) {
     897                printf ("No network driver name");
     898                return -1;
     899        }
     900        while ((c = *cp++) != '\0') {
     901                if ((c >= '0') && (c <= '9')) {
     902                        int len = cp - config->name - 1;
     903                        if ((len < 2) || (len > 50))
     904                                break;
     905                        for (;;) {
     906                                unitNumber = (unitNumber * 10) + (c - '0');
     907                                c = *cp++;
     908                                if (c == '\0') {
     909                                        char *unitName = malloc (len);
     910                                        if (unitName == NULL) {
     911                                                printf ("No memory");
     912                                                return -1;
     913                                        }
     914                                        strncpy (unitName, config->name, len - 1);
     915                                        unitName[len-1] = '\0';
     916                                        *namep = unitName;
     917                                        return unitNumber;
     918                                }
     919                                if ((c < '0') || (c > '9'))
     920                                        break;
     921                        }
     922                        break;
     923                }
     924        }
     925        printf ("Bad network driver name `%s'", config->name);
     926        return -1;
     927}
Note: See TracChangeset for help on using the changeset viewer.