Changeset 61bfc370 in mainline for uspace/srv/net/net/net.c


Ignore:
Timestamp:
2011-01-07T18:57:55Z (14 years ago)
Author:
Martin Decky <martin@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
e08a733
Parents:
7c34b28f
Message:
  • make measured_string and other network-related data types binary-safe
  • fix several network-related routines binary-safe (replace clearly suspicious use of str_lcmp() with bcmp())
  • rename spawn() to net_spawn()
File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/srv/net/net/net.c

    r7c34b28f r61bfc370  
    9090 *
    9191 */
    92 int add_configuration(measured_strings_t *configuration, const char *name,
    93     const char *value)
     92int add_configuration(measured_strings_t *configuration, const uint8_t *name,
     93    const uint8_t *value)
    9494{
    9595        int rc;
     
    119119}
    120120
    121 static int parse_line(measured_strings_t *configuration, char *line)
     121static int parse_line(measured_strings_t *configuration, uint8_t *line)
    122122{
    123123        int rc;
    124124       
    125125        /* From the beginning */
    126         char *name = line;
     126        uint8_t *name = line;
    127127       
    128128        /* Skip comments and blank lines */
     
    135135       
    136136        /* Remember the name start */
    137         char *value = name;
     137        uint8_t *value = name;
    138138       
    139139        /* Skip the name */
     
    186186       
    187187        /* Construct the full filename */
    188         char line[BUFFER_SIZE];
    189         if (snprintf(line, BUFFER_SIZE, "%s/%s", directory, filename) > BUFFER_SIZE)
     188        char fname[BUFFER_SIZE];
     189        if (snprintf(fname, BUFFER_SIZE, "%s/%s", directory, filename) > BUFFER_SIZE)
    190190                return EOVERFLOW;
    191191       
    192192        /* Open the file */
    193         FILE *cfg = fopen(line, "r");
     193        FILE *cfg = fopen(fname, "r");
    194194        if (!cfg)
    195195                return ENOENT;
     
    201201        unsigned int line_number = 0;
    202202        size_t index = 0;
     203        uint8_t line[BUFFER_SIZE];
     204       
    203205        while (!ferror(cfg) && !feof(cfg)) {
    204206                int read = fgetc(cfg);
     
    207209                                line[BUFFER_SIZE - 1] = '\0';
    208210                                fprintf(stderr, "%s: Configuration line %u too "
    209                                     "long: %s\n", NAME, line_number, line);
     211                                    "long: %s\n", NAME, line_number, (char *) line);
    210212                               
    211213                                /* No space left in the line buffer */
     
    213215                        }
    214216                        /* Append the character */
    215                         line[index] = (char) read;
     217                        line[index] = (uint8_t) read;
    216218                        index++;
    217219                } else {
     
    221223                        if (parse_line(configuration, line) != EOK) {
    222224                                fprintf(stderr, "%s: Configuration error on "
    223                                     "line %u: %s\n", NAME, line_number, line);
     225                                    "line %u: %s\n", NAME, line_number, (char *) line);
    224226                        }
    225227                       
     
    282284                return rc;
    283285       
    284         rc = add_module(NULL, &net_globals.modules, LO_NAME, LO_FILENAME,
    285             SERVICE_LO, 0, connect_to_service);
    286         if (rc != EOK)
    287                 return rc;
    288         rc = add_module(NULL, &net_globals.modules, DP8390_NAME,
    289             DP8390_FILENAME, SERVICE_DP8390, 0, connect_to_service);
    290         if (rc != EOK)
    291                 return rc;
    292         rc = add_module(NULL, &net_globals.modules, ETHERNET_NAME,
    293             ETHERNET_FILENAME, SERVICE_ETHERNET, 0, connect_to_service);
    294         if (rc != EOK)
    295                 return rc;
    296         rc = add_module(NULL, &net_globals.modules, NILDUMMY_NAME,
    297             NILDUMMY_FILENAME, SERVICE_NILDUMMY, 0, connect_to_service);
     286        rc = add_module(NULL, &net_globals.modules, (uint8_t *) LO_NAME,
     287            (uint8_t *) LO_FILENAME, SERVICE_LO, 0, connect_to_service);
     288        if (rc != EOK)
     289                return rc;
     290        rc = add_module(NULL, &net_globals.modules, (uint8_t *) DP8390_NAME,
     291            (uint8_t *) DP8390_FILENAME, SERVICE_DP8390, 0, connect_to_service);
     292        if (rc != EOK)
     293                return rc;
     294        rc = add_module(NULL, &net_globals.modules, (uint8_t *) ETHERNET_NAME,
     295            (uint8_t *) ETHERNET_FILENAME, SERVICE_ETHERNET, 0, connect_to_service);
     296        if (rc != EOK)
     297                return rc;
     298        rc = add_module(NULL, &net_globals.modules, (uint8_t *) NILDUMMY_NAME,
     299            (uint8_t *) NILDUMMY_FILENAME, SERVICE_NILDUMMY, 0, connect_to_service);
    298300        if (rc != EOK)
    299301                return rc;
     
    364366 */
    365367static int net_get_conf(measured_strings_t *netif_conf,
    366     measured_string_t *configuration, size_t count, char **data)
     368    measured_string_t *configuration, size_t count, uint8_t **data)
    367369{
    368370        if (data)
     
    390392
    391393int net_get_conf_req(int net_phone, measured_string_t **configuration,
    392     size_t count, char **data)
     394    size_t count, uint8_t **data)
    393395{
    394396        if (!configuration || (count <= 0))
     
    399401
    400402int net_get_device_conf_req(int net_phone, device_id_t device_id,
    401     measured_string_t **configuration, size_t count, char **data)
     403    measured_string_t **configuration, size_t count, uint8_t **data)
    402404{
    403405        if ((!configuration) || (count == 0))
     
    411413}
    412414
    413 void net_free_settings(measured_string_t *settings, char *data)
     415void net_free_settings(measured_string_t *settings, uint8_t *data)
    414416{
    415417}
     
    437439        /* Mandatory netif */
    438440        measured_string_t *setting =
    439             measured_strings_find(&netif->configuration, CONF_NETIF, 0);
     441            measured_strings_find(&netif->configuration, (uint8_t *) CONF_NETIF, 0);
    440442       
    441443        netif->driver = get_running_module(&net_globals.modules, setting->value);
     
    447449       
    448450        /* Optional network interface layer */
    449         setting = measured_strings_find(&netif->configuration, CONF_NIL, 0);
     451        setting = measured_strings_find(&netif->configuration, (uint8_t *) CONF_NIL, 0);
    450452        if (setting) {
    451453                netif->nil = get_running_module(&net_globals.modules, setting->value);
     
    459461       
    460462        /* Mandatory internet layer */
    461         setting = measured_strings_find(&netif->configuration, CONF_IL, 0);
     463        setting = measured_strings_find(&netif->configuration, (uint8_t *) CONF_IL, 0);
    462464        netif->il = get_running_module(&net_globals.modules, setting->value);
    463465        if (!netif->il) {
     
    468470       
    469471        /* Hardware configuration */
    470         setting = measured_strings_find(&netif->configuration, CONF_IRQ, 0);
    471         int irq = setting ? strtol(setting->value, NULL, 10) : 0;
    472        
    473         setting = measured_strings_find(&netif->configuration, CONF_IO, 0);
    474         int io = setting ? strtol(setting->value, NULL, 16) : 0;
     472        setting = measured_strings_find(&netif->configuration, (uint8_t *) CONF_IRQ, 0);
     473        int irq = setting ? strtol((char *) setting->value, NULL, 10) : 0;
     474       
     475        setting = measured_strings_find(&netif->configuration, (uint8_t *) CONF_IO, 0);
     476        int io = setting ? strtol((char *) setting->value, NULL, 16) : 0;
    475477       
    476478        rc = netif_probe_req_remote(netif->driver->phone, netif->id, irq, io);
     
    481483        services_t internet_service;
    482484        if (netif->nil) {
    483                 setting = measured_strings_find(&netif->configuration, CONF_MTU, 0);
     485                setting = measured_strings_find(&netif->configuration, (uint8_t *) CONF_MTU, 0);
    484486                if (!setting)
    485487                        setting = measured_strings_find(&net_globals.configuration,
    486                             CONF_MTU, 0);
    487                
    488                 int mtu = setting ? strtol(setting->value, NULL, 10) : 0;
     488                            (uint8_t *) CONF_MTU, 0);
     489               
     490                int mtu = setting ? strtol((char *) setting->value, NULL, 10) : 0;
    489491               
    490492                rc = nil_device_req(netif->nil->phone, netif->id, mtu,
     
    558560                /* Mandatory name */
    559561                measured_string_t *setting =
    560                     measured_strings_find(&netif->configuration, CONF_NAME, 0);
     562                    measured_strings_find(&netif->configuration, (uint8_t *) CONF_NAME, 0);
    561563                if (!setting) {
    562564                        fprintf(stderr, "%s: Network interface name is missing\n", NAME);
     
    602604                printf("%s: Network interface started (name: %s, id: %d, driver: %s, "
    603605                    "nil: %s, il: %s)\n", NAME, netif->name, netif->id,
    604                     netif->driver->name,  netif->nil ? netif->nil->name : "[none]",
     606                    netif->driver->name, netif->nil ? (char *) netif->nil->name : "[none]",
    605607                    netif->il->name);
    606608        }
     
    628630{
    629631        measured_string_t *strings;
    630         char *data;
     632        uint8_t *data;
    631633        int rc;
    632634       
Note: See TracChangeset for help on using the changeset viewer.