Changeset 0773396 in mainline for uspace/app


Ignore:
Timestamp:
2013-12-25T13:05:25Z (12 years ago)
Author:
Martin Decky <martin@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
bc54126c
Parents:
f4a47e52 (diff), 6946f23 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

merge mainline changes

Location:
uspace/app
Files:
14 added
1 deleted
25 edited
2 moved

Legend:

Unmodified
Added
Removed
  • uspace/app/bdsh/cmds/modules/mount/mount.c

    rf4a47e52 r0773396  
    7474        get_mtab_list(&mtab_list);
    7575
    76         list_foreach(mtab_list, cur) {
    77                 mtab_ent_t *mtab_ent = list_get_instance(cur, mtab_ent_t,
    78                     link);
    79 
     76        list_foreach(mtab_list, link, mtab_ent_t, mtab_ent) {
    8077                if (old_ent)
    8178                        free(old_ent);
  • uspace/app/corecfg/Makefile

    rf4a47e52 r0773396  
    11#
    2 # Copyright (c) 2013 Antonin Steinhauser
     2# Copyright (c) 2013 Jiri Svoboda
    33# All rights reserved.
    44#
     
    2828
    2929USPACE_PREFIX = ../..
    30 BINARY = ping6
     30BINARY = corecfg
    3131
    3232SOURCES = \
    33         ping6.c
     33        corecfg.c
    3434
    3535include $(USPACE_PREFIX)/Makefile.common
  • uspace/app/devctl/devctl.c

    rf4a47e52 r0773396  
    3535#include <devman.h>
    3636#include <errno.h>
     37#include <stdbool.h>
    3738#include <stdio.h>
    3839#include <stdlib.h>
     
    4445#define MAX_NAME_LENGTH 1024
    4546
    46 char name[MAX_NAME_LENGTH];
    47 char drv_name[MAX_NAME_LENGTH];
     47static char name[MAX_NAME_LENGTH];
     48static char drv_name[MAX_NAME_LENGTH];
     49static bool verbose = false;
     50
     51static const char *drv_state_str(driver_state_t state)
     52{
     53        const char *sstate;
     54
     55        switch (state) {
     56        case DRIVER_NOT_STARTED:
     57                sstate = "not started";
     58                break;
     59        case DRIVER_STARTING:
     60                sstate = "starting";
     61                break;
     62        case DRIVER_RUNNING:
     63                sstate = "running";
     64                break;
     65        default:
     66                sstate = "unknown";
     67        }
     68
     69        return sstate;
     70}
    4871
    4972static int fun_subtree_print(devman_handle_t funh, int lvl)
     
    5275        devman_handle_t *cfuns;
    5376        size_t count, i;
     77        unsigned int score;
    5478        int rc;
    5579        int j;
     
    7498                printf("%s : %s\n", name, drv_name);
    7599
     100        if (verbose) {
     101                for (i = 0; true; i++) {
     102                        rc = devman_fun_get_match_id(funh, i, name, MAX_NAME_LENGTH,
     103                            &score);
     104                        if (rc != EOK)
     105                                break;
     106
     107                        for (j = 0; j < lvl; j++)
     108                                printf("    ");
     109
     110                        printf("    %u %s\n", score, name);
     111                }
     112        }
     113
    76114        rc = devman_fun_get_child(funh, &devh);
    77115        if (rc == ENOENT)
     
    159197}
    160198
     199static int drv_list(void)
     200{
     201        devman_handle_t *devs;
     202        devman_handle_t *drvs;
     203        driver_state_t state;
     204        const char *sstate;
     205        size_t ndrvs;
     206        size_t ndevs;
     207        size_t i;
     208        int rc;
     209
     210        rc = devman_get_drivers(&drvs, &ndrvs);
     211        if (rc != EOK)
     212                return rc;
     213
     214        for (i = 0; i < ndrvs; i++) {
     215                devs = NULL;
     216
     217                rc = devman_driver_get_name(drvs[i], drv_name, MAX_NAME_LENGTH);
     218                if (rc != EOK)
     219                        goto skip;
     220                rc = devman_driver_get_state(drvs[i], &state);
     221                if (rc != EOK)
     222                        goto skip;
     223                rc = devman_driver_get_devices(drvs[i], &devs, &ndevs);
     224                if (rc != EOK)
     225                        goto skip;
     226
     227                sstate = drv_state_str(state);
     228
     229                printf("%-11s %3zu %s\n", sstate, ndevs, drv_name);
     230skip:
     231                free(devs);
     232        }
     233        free(drvs);
     234
     235        return EOK;
     236}
     237
     238static int drv_show(char *drvname)
     239{
     240        devman_handle_t *devs;
     241        devman_handle_t drvh;
     242        devman_handle_t funh;
     243        driver_state_t state;
     244        const char *sstate;
     245        unsigned int score;
     246        size_t ndevs;
     247        size_t i;
     248        int rc;
     249
     250        rc = devman_driver_get_handle(drvname, &drvh);
     251        if (rc != EOK)
     252                return rc;
     253
     254        devs = NULL;
     255
     256        rc = devman_driver_get_name(drvh, drv_name, MAX_NAME_LENGTH);
     257        if (rc != EOK)
     258                return rc;
     259
     260        rc = devman_driver_get_state(drvh, &state);
     261        if (rc != EOK)
     262                return rc;
     263
     264        rc = devman_driver_get_devices(drvh, &devs, &ndevs);
     265        if (rc != EOK)
     266                return rc;
     267
     268        sstate = drv_state_str(state);
     269
     270        printf("Driver: %s\n", drv_name);
     271        printf("State: %s\n", sstate);
     272
     273        printf("Attached devices:\n");
     274
     275        for (i = 0; i < ndevs; i++) {
     276                rc = devman_dev_get_parent(devs[i], &funh);
     277                if (rc != EOK)
     278                        goto error;
     279
     280                rc = devman_fun_get_path(funh, name, MAX_NAME_LENGTH);
     281                if (rc != EOK)
     282                        goto error;
     283                printf("\t%s\n", name);
     284        }
     285
     286        printf("Match IDs:\n");
     287
     288        for (i = 0; true; i++) {
     289                rc = devman_driver_get_match_id(drvh, i, name, MAX_NAME_LENGTH,
     290                    &score);
     291                if (rc != EOK)
     292                        break;
     293
     294                printf("\t%u %s\n", score, name);
     295        }
     296
     297error:
     298        free(devs);
     299
     300        return EOK;
     301}
     302
     303static int drv_load(const char *drvname)
     304{
     305        int rc;
     306        devman_handle_t drvh;
     307
     308        rc = devman_driver_get_handle(drvname, &drvh);
     309        if (rc != EOK) {
     310                printf("Failed resolving driver '%s' (%d).\n", drvname, rc);
     311                return rc;
     312        }
     313
     314        rc = devman_driver_load(drvh);
     315        if (rc != EOK) {
     316                printf("Failed loading driver '%s' (%d).\n", drvname, rc);
     317                return rc;
     318        }
     319
     320        return EOK;
     321}
     322
    161323static void print_syntax(void)
    162324{
    163         printf("syntax: devctl [(online|offline) <function>]\n");
     325        printf("syntax:\n");
     326        printf("\tdevctl\n");
     327        printf("\tdevctl online <function>]\n");
     328        printf("\tdevctl offline <function>]\n");
     329        printf("\tdevctl list-drv\n");
     330        printf("\tdevctl show-drv <driver-name>\n");
     331        printf("\tdevctl load-drv <driver-name>\n");
    164332}
    165333
     
    168336        int rc;
    169337
    170         if (argc == 1) {
     338        if (argc == 1 || argv[1][0] == '-') {
     339                if (argc > 1) {
     340                        if (str_cmp(argv[1], "-v") == 0) {
     341                                verbose = true;
     342                        } else {
     343                                printf(NAME ": Invalid argument '%s'\n", argv[1]);
     344                                print_syntax();
     345                                return 1;
     346                        }
     347                }
    171348                rc = fun_tree_print();
    172349                if (rc != EOK)
     
    194371                        return 2;
    195372                }
     373        } else if (str_cmp(argv[1], "list-drv") == 0) {
     374                rc = drv_list();
     375                if (rc != EOK)
     376                        return 2;
     377        } else if (str_cmp(argv[1], "show-drv") == 0) {
     378                if (argc < 3) {
     379                        printf(NAME ": Argument missing.\n");
     380                        print_syntax();
     381                        return 1;
     382                }
     383
     384                rc = drv_show(argv[2]);
     385                if (rc != EOK) {
     386                        return 2;
     387                }
     388        } else if (str_cmp(argv[1], "load-drv") == 0) {
     389                if (argc < 3) {
     390                        printf(NAME ": Argument missing.\n");
     391                        print_syntax();
     392                        return 1;
     393                }
     394
     395                rc = drv_load(argv[2]);
     396                if (rc != EOK)
     397                        return 2;
    196398        } else {
    197399                printf(NAME ": Invalid argument '%s'.\n", argv[1]);
  • uspace/app/df/Makefile

    rf4a47e52 r0773396  
    11#
    2 # Copyright (c) 2008 Josef Cejka
     2# Copyright (c) 2013 Manuele Conti
    33# All rights reserved.
    44#
     
    2727#
    2828
    29 #include <libarch/context_offset.h>
     29USPACE_PREFIX = ../..
     30BINARY = df
    3031
    31 .text
    32 .global setjmp
    33 .global longjmp
     32SOURCES = \
     33        df.c
    3434
    35 .type setjmp,@function
    36 setjmp:
    37         movl 0(%esp), %eax  # save pc value into eax
    38         movl 4(%esp), %edx  # address of the jmp_buf structure to save context to
    39        
    40         # save registers to the jmp_buf structure
    41         CONTEXT_SAVE_ARCH_CORE %edx %eax
    42        
    43         xorl %eax, %eax     # set_jmp returns 0
    44         ret
    45 
    46 .type longjmp,@function
    47 longjmp:
    48         movl 4(%esp), %ecx  # put address of jmp_buf into ecx
    49         movl 8(%esp), %eax  # put return value into eax
    50        
    51         # restore registers from the jmp_buf structure
    52         CONTEXT_RESTORE_ARCH_CORE %ecx %edx
    53        
    54         movl %edx, 0(%esp)  # put saved pc on stack
    55         ret
     35include $(USPACE_PREFIX)/Makefile.common
  • uspace/app/dnsres/dnsres.c

    rf4a47e52 r0773396  
    3636#include <inet/addr.h>
    3737#include <inet/dnsr.h>
    38 #include <net/socket_codes.h>
    3938#include <stdio.h>
    4039#include <stdlib.h>
     
    5453        }
    5554       
    56         uint16_t af;
     55        uint16_t ver;
    5756        char *hname;
    5857       
     
    6362                }
    6463               
    65                 af = AF_INET;
     64                ver = ip_v4;
    6665                hname = argv[2];
    6766        } else if (str_cmp(argv[1], "-6") == 0) {
     
    7170                }
    7271               
    73                 af = AF_INET6;
     72                ver = ip_v6;
    7473                hname = argv[2];
    7574        } else {
    76                 af = 0;
     75                ver = ip_any;
    7776                hname = argv[1];
    7877        }
    7978       
    8079        dnsr_hostinfo_t *hinfo;
    81         int rc = dnsr_name2host(hname, &hinfo, af);
     80        int rc = dnsr_name2host(hname, &hinfo, ver);
    8281        if (rc != EOK) {
    8382                printf("%s: Error resolving '%s'.\n", NAME, hname);
  • uspace/app/edit/sheet.c

    rf4a47e52 r0773396  
    105105        char *ipp;
    106106        size_t sz;
    107         tag_t *tag;
    108107        char *newp;
    109108
     
    128127        /* Adjust tags. */
    129128
    130         list_foreach(sh->tags, link) {
    131                 tag = list_get_instance(link, tag_t, link);
    132 
     129        list_foreach(sh->tags, link, tag_t, tag) {
    133130                if (tag->b_off > pos->b_off)
    134131                        tag->b_off += sz;
     
    154151        char *spp;
    155152        size_t sz;
    156         tag_t *tag;
    157153        char *newp;
    158154        size_t shrink_size;
     
    165161
    166162        /* Adjust tags. */
    167         list_foreach(sh->tags, link) {
    168                 tag = list_get_instance(link, tag_t, link);
    169 
     163        list_foreach(sh->tags, link, tag_t, tag) {
    170164                if (tag->b_off >= epos->b_off)
    171165                        tag->b_off -= sz;
  • uspace/app/getterm/getterm.c

    rf4a47e52 r0773396  
    112112        reopen(&stderr, 2, term, O_WRONLY, "w");
    113113       
    114         /*
    115          * FIXME: fdopen() should actually detect that we are opening a console
    116          * and it should set line-buffering mode automatically.
    117          */
    118         setvbuf(stdout, NULL, _IOLBF, BUFSIZ);
    119        
    120114        if (stdin == NULL)
    121115                return -2;
     
    126120        if (stderr == NULL)
    127121                return -4;
     122       
     123        /*
     124         * FIXME: fdopen() should actually detect that we are opening a console
     125         * and it should set line-buffering mode automatically.
     126         */
     127        setvbuf(stdout, NULL, _IOLBF, BUFSIZ);
    128128       
    129129        version_print(term);
  • uspace/app/inet/inet.c

    rf4a47e52 r0773396  
    312312}
    313313
     314static int link_list(void)
     315{
     316        sysarg_t *link_list;
     317        inet_link_info_t linfo;
     318
     319        size_t count;
     320        size_t i;
     321        int rc;
     322
     323        rc = inetcfg_get_link_list(&link_list, &count);
     324        if (rc != EOK) {
     325                printf(NAME ": Failed getting link list.\n");
     326                return rc;
     327        }
     328
     329        printf("IP links:\n");
     330        if (count > 0)
     331                printf("    [Link-layer Address] [Link-Name] [Def-MTU]\n");
     332
     333        for (i = 0; i < count; i++) {
     334                rc = inetcfg_link_get(link_list[i], &linfo);
     335                if (rc != EOK) {
     336                        printf("Failed getting properties of link %zu.\n",
     337                            (size_t)link_list[i]);
     338                        continue;
     339                }
     340
     341                printf("    %02x:%02x:%02x:%02x:%02x:%02x %s %zu\n",
     342                    linfo.mac_addr[0], linfo.mac_addr[1],
     343                    linfo.mac_addr[2], linfo.mac_addr[3],
     344                    linfo.mac_addr[4], linfo.mac_addr[5],
     345                    linfo.name, linfo.def_mtu);
     346
     347                free(linfo.name);
     348
     349                linfo.name = NULL;
     350        }
     351
     352        if (count == 0)
     353                printf("    None\n");
     354
     355        free(link_list);
     356
     357        return EOK;
     358}
     359
    314360static int sroute_list(void)
    315361{
     
    404450                if (rc != EOK)
    405451                        return 1;
     452                rc = link_list();
     453                if (rc != EOK)
     454                        return 1;
    406455                return 0;
    407456        }
  • uspace/app/init/init.c

    rf4a47e52 r0773396  
    360360        srv_start("/srv/udp");
    361361        srv_start("/srv/dnsrsrv");
     362        srv_start("/srv/dhcp");
     363        srv_start("/srv/nconfsrv");
    362364       
    363365        srv_start("/srv/clipboard");
     
    384386        srv_start("/srv/input", HID_INPUT);
    385387        srv_start("/srv/output", HID_OUTPUT);
     388        srv_start("/srv/hound");
    386389       
    387390        int rc = compositor(HID_INPUT, HID_COMPOSITOR_SERVER);
  • uspace/app/klog/klog.c

    rf4a47e52 r0773396  
    206206        klog_length = size / sizeof(wchar_t);
    207207       
    208         rc = physmem_map((void *) faddr, pages,
    209             AS_AREA_READ | AS_AREA_CACHEABLE, (void *) &klog);
     208        rc = physmem_map(faddr, pages, AS_AREA_READ | AS_AREA_CACHEABLE,
     209            (void *) &klog);
    210210        if (rc != EOK) {
    211211                fprintf(stderr, "%s: Unable to map klog\n", NAME);
  • uspace/app/nettest1/nettest1.c

    rf4a47e52 r0773396  
    3838#include "print_error.h"
    3939
     40#include <assert.h>
    4041#include <malloc.h>
    4142#include <stdio.h>
     
    5960#define NETTEST1_TEXT  "Networking test 1 - sockets"
    6061
    61 static uint16_t family = AF_INET;
     62static uint16_t family = AF_NONE;
    6263static sock_type_t type = SOCK_DGRAM;
    6364static size_t size = 27;
     
    326327        }
    327328       
    328         char *addr_s = argv[argc - 1];
     329        char *host = argv[argc - 1];
    329330       
    330331        /* Interpret as address */
    331         inet_addr_t addr_addr;
    332         rc = inet_addr_parse(addr_s, &addr_addr);
     332        inet_addr_t iaddr;
     333        rc = inet_addr_parse(host, &iaddr);
    333334       
    334335        if (rc != EOK) {
    335336                /* Interpret as a host name */
    336337                dnsr_hostinfo_t *hinfo = NULL;
    337                 rc = dnsr_name2host(addr_s, &hinfo, family);
     338                rc = dnsr_name2host(host, &hinfo, ipver_from_af(family));
    338339               
    339340                if (rc != EOK) {
    340                         printf("Error resolving host '%s'.\n", addr_s);
     341                        printf("Error resolving host '%s'.\n", host);
    341342                        return EINVAL;
    342343                }
    343344               
    344                 addr_addr = hinfo->addr;
    345         }
    346        
    347         struct sockaddr_in addr;
    348         struct sockaddr_in6 addr6;
    349         uint16_t af = inet_addr_sockaddr_in(&addr_addr, &addr, &addr6);
    350        
    351         if (af != family) {
     345                iaddr = hinfo->addr;
     346        }
     347       
     348        rc = inet_addr_sockaddr(&iaddr, port, &address, &addrlen);
     349        if (rc != EOK) {
     350                assert(rc == ENOMEM);
     351                printf("Out of memory.\n");
     352                return ENOMEM;
     353        }
     354       
     355        if (family == AF_NONE)
     356                family = address->sa_family;
     357       
     358        if (address->sa_family != family) {
    352359                printf("Address family does not match explicitly set family.\n");
    353360                return EINVAL;
    354         }
    355        
    356         /* Prepare the address buffer */
    357        
    358         switch (af) {
    359         case AF_INET:
    360                 addr.sin_port = htons(port);
    361                 address = (struct sockaddr *) &addr;
    362                 addrlen = sizeof(addr);
    363                 break;
    364         case AF_INET6:
    365                 addr6.sin6_port = htons(port);
    366                 address = (struct sockaddr *) &addr6;
    367                 addrlen = sizeof(addr6);
    368                 break;
    369         default:
    370                 fprintf(stderr, "Address family is not supported\n");
    371                 return EAFNOSUPPORT;
    372361        }
    373362       
     
    434423            &time_before));
    435424       
     425        free(address);
     426       
    436427        if (verbose)
    437428                printf("Exiting\n");
  • uspace/app/nettest2/nettest2.c

    rf4a47e52 r0773396  
    3838#include "print_error.h"
    3939
     40#include <assert.h>
    4041#include <malloc.h>
    4142#include <stdio.h>
     
    6061#define NETTEST2_TEXT  "Networking test 2 - transfer"
    6162
    62 static uint16_t family = PF_INET;
     63static uint16_t family = AF_NONE;
    6364static size_t size = 28;
    6465static bool verbose = false;
     
    271272                /* Interpret as a host name */
    272273                dnsr_hostinfo_t *hinfo = NULL;
    273                 rc = dnsr_name2host(addr_s, &hinfo, family);
     274                rc = dnsr_name2host(addr_s, &hinfo, ipver_from_af(family));
    274275               
    275276                if (rc != EOK) {
     
    281282        }
    282283       
    283         struct sockaddr_in addr;
    284         struct sockaddr_in6 addr6;
    285         uint16_t af = inet_addr_sockaddr_in(&addr_addr, &addr, &addr6);
    286        
    287         if (af != family) {
     284        struct sockaddr *address;
     285        socklen_t addrlen;
     286        rc = inet_addr_sockaddr(&addr_addr, port, &address, &addrlen);
     287        if (rc != EOK) {
     288                assert(rc == ENOMEM);
     289                printf("Out of memory.\n");
     290                return ENOMEM;
     291        }
     292       
     293        if (family == AF_NONE)
     294                family = address->sa_family;
     295       
     296        if (address->sa_family != family) {
    288297                printf("Address family does not match explicitly set family.\n");
    289298                return EINVAL;
    290         }
    291        
    292         /* Prepare the address buffer */
    293        
    294         struct sockaddr *address;
    295         socklen_t addrlen;
    296        
    297         switch (af) {
    298         case AF_INET:
    299                 addr.sin_port = htons(port);
    300                 address = (struct sockaddr *) &addr;
    301                 addrlen = sizeof(addr);
    302                 break;
    303         case AF_INET6:
    304                 addr6.sin6_port = htons(port);
    305                 address = (struct sockaddr *) &addr6;
    306                 addrlen = sizeof(addr6);
    307                 break;
    308         default:
    309                 fprintf(stderr, "Address family is not supported\n");
    310                 return EAFNOSUPPORT;
    311299        }
    312300       
     
    424412                return rc;
    425413       
     414        free(address);
     415       
    426416        if (verbose)
    427417                printf("\nExiting\n");
  • uspace/app/nettest3/nettest3.c

    rf4a47e52 r0773396  
    3737#include <async.h>
    3838#include <stdio.h>
     39#include <stdlib.h>
    3940#include <str.h>
    4041
     
    5253static char buf[BUF_SIZE];
    5354
    54 static struct sockaddr_in addr;
     55static struct sockaddr *address;
     56static socklen_t addrlen;
    5557
    5658static uint16_t port;
     
    6264        char *endptr;
    6365        dnsr_hostinfo_t *hinfo;
     66        inet_addr_t addr;
     67        char *addr_s;
    6468
    6569        port = 7;
     
    6973
    7074        /* Connect to local IP address by default */
    71         addr.sin_family = AF_INET;
    72         addr.sin_port = htons(port);
    73         addr.sin_addr.s_addr = htonl(0x7f000001);
     75        inet_addr(&addr, 127, 0, 0, 1);
    7476
    7577        if (argc >= 2) {
    7678                printf("parsing address '%s'\n", argv[1]);
    77                 rc = inet_pton(AF_INET, argv[1], (uint8_t *)&addr.sin_addr.s_addr);
     79                rc = inet_addr_parse(argv[1], &addr);
    7880                if (rc != EOK) {
    7981                        /* Try interpreting as a host name */
    80                         rc = dnsr_name2host(argv[1], &hinfo, AF_INET);
     82                        rc = dnsr_name2host(argv[1], &hinfo, ip_v4);
    8183                        if (rc != EOK) {
    8284                                printf("Error resolving host '%s'.\n", argv[1]);
    8385                                return rc;
    8486                        }
    85                        
    86                         uint16_t af = inet_addr_sockaddr_in(&hinfo->addr, &addr, NULL);
    87                         if (af != AF_INET) {
    88                                 printf("Host '%s' not resolved as IPv4 address.\n", argv[1]);
    89                                 return rc;
    90                         }
     87
     88                        addr = hinfo->addr;
    9189                }
    92                 printf("result: rc=%d, family=%d, addr=%x\n", rc,
    93                     addr.sin_family, addr.sin_addr.s_addr);
     90                rc = inet_addr_format(&addr, &addr_s);
     91                if (rc != EOK) {
     92                        assert(rc == ENOMEM);
     93                        printf("Out of memory.\n");
     94                        return rc;
     95                }
     96                printf("result: rc=%d, ver=%d, addr=%s\n", rc,
     97                    addr.version, addr_s);
     98                free(addr_s);
    9499        }
    95100
    96101        if (argc >= 3) {
    97102                printf("parsing port '%s'\n", argv[2]);
    98                 addr.sin_port = htons(strtoul(argv[2], &endptr, 10));
     103                port = htons(strtoul(argv[2], &endptr, 10));
    99104                if (*endptr != '\0') {
    100105                        fprintf(stderr, "Error parsing port\n");
     
    103108        }
    104109
     110        rc = inet_addr_sockaddr(&hinfo->addr, port, &address, &addrlen);
     111        if (rc != EOK) {
     112                printf("Out of memory.\n");
     113                return rc;
     114        }
     115
    105116        printf("socket()\n");
    106         fd = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP);
     117        fd = socket(address->sa_family, SOCK_STREAM, IPPROTO_TCP);
    107118        printf(" -> %d\n", fd);
    108119        if (fd < 0)
     
    110121
    111122        printf("connect()\n");
    112         rc = connect(fd, (struct sockaddr *) &addr, sizeof(addr));
     123        rc = connect(fd, address, addrlen);
    113124        printf(" -> %d\n", rc);
    114125        if (rc != 0)
     
    133144        printf(" -> %d\n", rc);
    134145
     146        free(address);
     147
    135148        return 0;
    136149}
  • uspace/app/nterm/conn.c

    rf4a47e52 r0773396  
    3838#include <fibril.h>
    3939#include <inet/dnsr.h>
     40#include <net/inet.h>
    4041#include <net/socket.h>
    4142#include <stdio.h>
     43#include <stdlib.h>
    4244#include <str_error.h>
    4345#include <sys/types.h>
     
    7375}
    7476
    75 int conn_open(const char *addr_s, const char *port_s)
     77int conn_open(const char *host, const char *port_s)
    7678{
    7779        int conn_fd = -1;
     80        struct sockaddr *saddr = NULL;
     81        socklen_t saddrlen;
    7882       
    7983        /* Interpret as address */
    80         inet_addr_t addr_addr;
    81         int rc = inet_addr_parse(addr_s, &addr_addr);
     84        inet_addr_t iaddr;
     85        int rc = inet_addr_parse(host, &iaddr);
    8286       
    8387        if (rc != EOK) {
    8488                /* Interpret as a host name */
    8589                dnsr_hostinfo_t *hinfo = NULL;
    86                 rc = dnsr_name2host(addr_s, &hinfo, 0);
     90                rc = dnsr_name2host(host, &hinfo, ip_any);
    8791               
    8892                if (rc != EOK) {
    89                         printf("Error resolving host '%s'.\n", addr_s);
     93                        printf("Error resolving host '%s'.\n", host);
    9094                        goto error;
    9195                }
    9296               
    93                 addr_addr = hinfo->addr;
     97                iaddr = hinfo->addr;
    9498        }
    95        
    96         struct sockaddr_in addr;
    97         struct sockaddr_in6 addr6;
    98         uint16_t af = inet_addr_sockaddr_in(&addr_addr, &addr, &addr6);
    9999       
    100100        char *endptr;
     
    105105        }
    106106       
    107         printf("Connecting to host %s port %u\n", addr_s, port);
     107        rc = inet_addr_sockaddr(&iaddr, port, &saddr, &saddrlen);
     108        if (rc != EOK) {
     109                assert(rc == ENOMEM);
     110                printf("Out of memory.\n");
     111                return ENOMEM;
     112        }
    108113       
    109         conn_fd = socket(PF_INET, SOCK_STREAM, 0);
     114        printf("Connecting to host %s port %u\n", host, port);
     115       
     116        conn_fd = socket(saddr->sa_family, SOCK_STREAM, 0);
    110117        if (conn_fd < 0)
    111118                goto error;
    112119       
    113         switch (af) {
    114         case AF_INET:
    115                 addr.sin_port = htons(port);
    116                 rc = connect(conn_fd, (struct sockaddr *) &addr, sizeof(addr));
    117                 break;
    118         case AF_INET6:
    119                 addr6.sin6_port = htons(port);
    120                 rc = connect(conn_fd, (struct sockaddr *) &addr6, sizeof(addr6));
    121                 break;
    122         default:
    123                 printf("Unknown address family.\n");
    124                 goto error;
    125         }
    126        
     120        rc = connect(conn_fd, saddr, saddrlen);
    127121        if (rc != EOK)
    128122                goto error;
     
    134128        fibril_add_ready(rcv_fid);
    135129       
     130        free(saddr);
    136131        return EOK;
    137        
    138132error:
    139133        if (conn_fd >= 0) {
     
    141135                conn_fd = -1;
    142136        }
     137        free(saddr);
    143138       
    144139        return EIO;
  • uspace/app/ping/ping.c

    rf4a47e52 r0773396  
    3737#include <errno.h>
    3838#include <fibril_synch.h>
    39 #include <net/socket_codes.h>
    4039#include <inet/dnsr.h>
    4140#include <inet/addr.h>
     
    7776};
    7877
    79 static addr32_t src;
    80 static addr32_t dest;
     78static inet_addr_t src_addr;
     79static inet_addr_t dest_addr;
    8180
    8281static bool repeat_forever = false;
    8382static size_t repeat_count = 1;
    8483
    85 static const char *short_options = "rn:";
     84static const char *short_options = "46rn:";
    8685
    8786static void print_syntax(void)
    8887{
    89         printf("Syntax: %s [-n <count>|-r] <host>\n", NAME);
     88        printf("Syntax: %s [<options>] <host>\n", NAME);
     89        printf("\t-n <count> Repeat the specified number of times\n");
     90        printf("\t-r         Repeat forever\n");
     91        printf("\t-4|-6      Use IPv4 or IPv6 destination host address\n");
    9092}
    9193
     
    108110static int ping_ev_recv(inetping_sdu_t *sdu)
    109111{
    110         inet_addr_t src_addr;
    111         inet_addr_set(sdu->src, &src_addr);
    112        
    113         inet_addr_t dest_addr;
    114         inet_addr_set(sdu->dest, &dest_addr);
    115        
    116112        char *asrc;
    117113        int rc = inet_addr_format(&src_addr, &asrc);
     
    140136        inetping_sdu_t sdu;
    141137       
    142         sdu.src = src;
    143         sdu.dest = dest;
     138        sdu.src = src_addr;
     139        sdu.dest = dest_addr;
    144140        sdu.seq_no = seq_no;
    145141        sdu.data = (void *) "foo";
     
    222218        char *adest = NULL;
    223219        char *sdest = NULL;
     220        ip_ver_t ip_ver = ip_any;
    224221       
    225222        int rc = inetping_init(&ev_ops);
     
    244241                        }
    245242                        break;
     243                case '4':
     244                        ip_ver = ip_v4;
     245                        break;
     246                case '6':
     247                        ip_ver = ip_v6;
     248                        break;
    246249                default:
    247250                        printf("Unknown option passed.\n");
     
    258261       
    259262        /* Parse destination address */
    260         inet_addr_t dest_addr;
    261263        rc = inet_addr_parse(argv[optind], &dest_addr);
    262264        if (rc != EOK) {
    263265                /* Try interpreting as a host name */
    264                 rc = dnsr_name2host(argv[optind], &hinfo, AF_INET);
     266                rc = dnsr_name2host(argv[optind], &hinfo, ip_ver);
    265267                if (rc != EOK) {
    266268                        printf("Error resolving host '%s'.\n", argv[optind]);
     
    271273        }
    272274       
    273         uint16_t af = inet_addr_get(&dest_addr, &dest, NULL);
    274         if (af != AF_INET) {
    275                 printf("Destination '%s' is not an IPv4 address.\n",
    276                     argv[optind]);
    277                 goto error;
    278         }
    279        
    280275        /* Determine source address */
    281         rc = inetping_get_srcaddr(dest, &src);
     276        rc = inetping_get_srcaddr(&dest_addr, &src_addr);
    282277        if (rc != EOK) {
    283278                printf("Failed determining source address.\n");
    284279                goto error;
    285280        }
    286        
    287         inet_addr_t src_addr;
    288         inet_addr_set(src, &src_addr);
    289281       
    290282        rc = inet_addr_format(&src_addr, &asrc);
  • uspace/app/sportdmp/sportdmp.c

    rf4a47e52 r0773396  
    4444        sysarg_t baud = 9600;
    4545        service_id_t svc_id;
    46        
     46
    4747        int arg = 1;
    4848        int rc;
    49                
     49
    5050        if (argc > arg && str_test_prefix(argv[arg], "--baud=")) {
    5151                size_t arg_offset = str_lsize(argv[arg], 7);
     
    6565                arg++;
    6666        }
    67        
     67
    6868        if (argc > arg) {
    6969                rc = loc_service_get_id(argv[arg], &svc_id, 0);
     
    7777        else {
    7878                category_id_t serial_cat_id;
    79                
     79
    8080                rc = loc_category_get_id("serial", &serial_cat_id, 0);
    8181                if (rc != EOK) {
     
    8484                        return 1;
    8585                }
    86                
     86
    8787                service_id_t *svc_ids;
    8888                size_t svc_count;
    89                
    90                 rc = loc_category_get_svcs(serial_cat_id, &svc_ids, &svc_count);                if (rc != EOK) {
     89
     90                rc = loc_category_get_svcs(serial_cat_id, &svc_ids, &svc_count);
     91                if (rc != EOK) {
    9192                        fprintf(stderr, "Failed getting list of services\n");
    9293                        return 1;
    9394                }
    94                
     95
    9596                if (svc_count == 0) {
    9697                        fprintf(stderr, "No service in category 'serial'\n");
     
    9899                        return 1;
    99100                }
    100                
     101
    101102                svc_id = svc_ids[0];
    102103                free(svc_ids);
    103104        }
    104        
     105
    105106        if (argc > arg) {
    106107                fprintf(stderr, "Too many arguments\n");
     
    108109                return 1;
    109110        }
    110        
    111        
     111
     112
    112113        async_sess_t *sess = loc_service_connect(EXCHANGE_SERIALIZE, svc_id,
    113114            IPC_FLAG_BLOCKING);
     
    115116                fprintf(stderr, "Failed connecting to service\n");
    116117        }
    117        
     118
    118119        async_exch_t *exch = async_exchange_begin(sess);
    119120        rc = async_req_4_0(exch, SERIAL_SET_COM_PROPS, baud,
    120121            SERIAL_NO_PARITY, 8, 1);
    121122        async_exchange_end(exch);
    122        
     123
    123124        if (rc != EOK) {
    124125                fprintf(stderr, "Failed setting serial properties\n");
    125126                return 2;
    126127        }
    127        
     128
    128129        uint8_t *buf = (uint8_t *) malloc(BUF_SIZE);
    129130        if (buf == NULL) {
     
    131132                return 3;
    132133        }
    133        
     134
    134135        while (true) {
    135136                ssize_t read = char_dev_read(sess, buf, BUF_SIZE);
     
    144145                fflush(stdout);
    145146        }
    146        
     147
    147148        free(buf);
    148149        return 0;
    149150}
     151
  • uspace/app/tester/Makefile

    rf4a47e52 r0773396  
    3737        util.c \
    3838        thread/thread1.c \
     39        thread/setjmp1.c \
    3940        print/print1.c \
    4041        print/print2.c \
  • uspace/app/tester/mm/common.c

    rf4a47e52 r0773396  
    8484}
    8585
    86 static bool overlap_match(link_t *link, void *addr, size_t size)
    87 {
    88         mem_block_t *block = list_get_instance(link, mem_block_t, link);
    89        
     86static bool overlap_match(mem_block_t *block, void *addr, size_t size)
     87{
    9088        /* Entry block control structure <mbeg, mend) */
    9189        uint8_t *mbeg = (uint8_t *) block;
     
    125123        bool fnd = false;
    126124       
    127         list_foreach(mem_blocks, link) {
    128                 if (overlap_match(link, addr, size)) {
     125        list_foreach(mem_blocks, link, mem_block_t, block) {
     126                if (overlap_match(block, addr, size)) {
    129127                        fnd = true;
    130128                        break;
  • uspace/app/tester/tester.c

    rf4a47e52 r0773396  
    4848test_t tests[] = {
    4949#include "thread/thread1.def"
     50#include "thread/setjmp1.def"
    5051#include "print/print1.def"
    5152#include "print/print2.def"
  • uspace/app/tester/tester.h

    rf4a47e52 r0773396  
    3939#include <stdbool.h>
    4040#include <stacktrace.h>
     41#include <stdio.h>
    4142
    4243#define IPC_TEST_SERVICE  10240
     
    8081
    8182extern const char *test_thread1(void);
     83extern const char *test_setjmp1(void);
    8284extern const char *test_print1(void);
    8385extern const char *test_print2(void);
  • uspace/app/trace/trace.c

    rf4a47e52 r0773396  
    724724        o = oper_new("stat", 0, arg_def, V_ERRNO, 0, resp_def);
    725725        proto_add_oper(p, VFS_IN_STAT, o);
     726        o = oper_new("statfs", 0, arg_def, V_ERRNO, 0, resp_def);
     727        proto_add_oper(p, VFS_IN_STATFS, o);
    726728
    727729        proto_register(SERVICE_VFS, p);
  • uspace/app/usbinfo/dump.c

    rf4a47e52 r0773396  
    103103void dump_match_ids(match_id_list_t *matches, const char *line_prefix)
    104104{
    105         list_foreach(matches->ids, link) {
    106                 match_id_t *match = list_get_instance(link, match_id_t, link);
    107 
     105        list_foreach(matches->ids, link, match_id_t, match) {
    108106                printf("%s%3d %s\n", line_prefix, match->score, match->id);
    109107        }
  • uspace/app/usbinfo/hid.c

    rf4a47e52 r0773396  
    100100        printf("%sParsed HID report descriptor for interface %d\n",
    101101            get_indent(0), iface_no);
    102         list_foreach(report->reports, report_it) {
    103                 usb_hid_report_description_t *description = list_get_instance(
    104                     report_it, usb_hid_report_description_t, reports_link);
     102        list_foreach(report->reports, reports_link,
     103            usb_hid_report_description_t, description) {
    105104                printf("%sReport %d (type %d)\n", get_indent(1),
    106105                    (int) description->report_id,
    107106                    (int) description->type);
    108                 list_foreach(description->report_items, item_it) {
    109                         usb_hid_report_field_t *field = list_get_instance(
    110                             item_it, usb_hid_report_field_t, ritems_link);
     107                list_foreach(description->report_items, ritems_link,
     108                    usb_hid_report_field_t, field) {
    111109                        printf("%sUsage page = 0x%04x    Usage = 0x%04x\n",
    112110                            get_indent(2),
  • uspace/app/wavplay/dplay.c

    rf4a47e52 r0773396  
    151151            device_event_callback, pb);
    152152        if (ret != EOK) {
    153                 printf("Failed to register event callback.\n");
     153                printf("Failed to register event callback: %s.\n",
     154                    str_error(ret));
    154155                return;
    155156        }
     
    285286                            pb->f.sample_format);
    286287                        if (ret != EOK) {
    287                                 printf("Failed to start playback\n");
     288                                printf("Failed to start playback: %s\n",
     289                                    str_error(ret));
    288290                                return;
    289291                        }
     
    291293                        ret = audio_pcm_get_buffer_pos(pb->device, &pos);
    292294                        if (ret != EOK) {
    293                                 printf("Failed to update position indicator\n");
     295                                printf("Failed to update position indicator "
     296                                   "%s\n", str_error(ret));
    294297                        }
    295298                }
     
    308311                const int ret = audio_pcm_get_buffer_pos(pb->device, &pos);
    309312                if (ret != EOK) {
    310                         printf("Failed to update position indicator\n");
     313                        printf("Failed to update position indicator %s\n",
     314                            str_error(ret));
    311315                }
    312316                getuptime(&time);
     
    350354        ret = audio_pcm_get_info_str(session, &info);
    351355        if (ret != EOK) {
    352                 printf("Failed to get PCM info.\n");
     356                printf("Failed to get PCM info: %s.\n", str_error(ret));
    353357                goto close_session;
    354358        }
  • uspace/app/wavplay/drec.c

    rf4a47e52 r0773396  
    213213        wave_header_t header;
    214214        fseek(rec.file, sizeof(header), SEEK_SET);
    215         const char *error;
    216         if (ret != EOK) {
    217                 printf("Error parsing wav header: %s.\n", error);
     215        if (ret != EOK) {
     216                printf("Error parsing wav header\n");
    218217                goto cleanup;
    219218        }
  • uspace/app/wavplay/main.c

    rf4a47e52 r0773396  
    7979            &format.sampling_rate, &format.sample_format, &error);
    8080        if (ret != EOK) {
    81                 printf("Error parsing wav header: %s.\n", error);
     81                printf("Error parsing `%s' wav header: %s.\n", filename, error);
    8282                fclose(source);
    8383                return EINVAL;
    8484        }
     85
     86        printf("File `%s' format: %u channel(s), %uHz, %s.\n", filename,
     87            format.channels, format.sampling_rate,
     88            pcm_sample_format_str(format.sample_format));
    8589
    8690        /* Allocate buffer and create new context */
     
    136140            &format.sampling_rate, &format.sample_format, &error);
    137141        if (ret != EOK) {
    138                 printf("Error parsing wav header: %s.\n", error);
     142                printf("Error parsing `%s' wav header: %s.\n", filename, error);
    139143                fclose(source);
    140144                return EINVAL;
    141145        }
     146        printf("File `%s' format: %u channel(s), %uHz, %s.\n", filename,
     147            format.channels, format.sampling_rate,
     148            pcm_sample_format_str(format.sample_format));
    142149
    143150        /* Connect new playback context */
  • uspace/app/wavplay/wave.c

    rf4a47e52 r0773396  
    8181        }
    8282
    83         if (uint16_t_le2host(header->subchunk1_size) != PCM_SUBCHUNK1_SIZE) {
     83        if (uint32_t_le2host(header->subchunk1_size) != PCM_SUBCHUNK1_SIZE) {
     84                //TODO subchunk 1 sizes other than 16 are allowed ( 18, 40)
     85                //http://www-mmsp.ece.mcgill.ca/documents/AudioFormats/WAVE/WAVE.html
    8486                if (error)
    8587                        *error = "invalid subchunk1 size";
    86                 return EINVAL;
     88//              return EINVAL;
    8789        }
    8890
     
    9496
    9597        if (str_lcmp(header->subchunk2_id, SUBCHUNK2_ID, 4) != 0) {
     98                //TODO basedd on subchunk1 size, we might be reading wrong
     99                //offset
    96100                if (error)
    97101                        *error = "invalid subchunk2 id";
    98                 return EINVAL;
     102//              return EINVAL;
    99103        }
    100104
    101105
     106        //TODO data and data_size are incorrect in extended wav formats
     107        //pcm params are OK
    102108        if (data)
    103109                *data = header->data;
Note: See TracChangeset for help on using the changeset viewer.