Changeset b8e72fd1 in mainline for uspace/app


Ignore:
Timestamp:
2013-05-30T17:13:02Z (13 years ago)
Author:
Vojtech Horky <vojtechhorky@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
98abd40
Parents:
be2bb4f (diff), 94dfb92 (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:
4 added
9 edited

Legend:

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

    rbe2bb4f rb8e72fd1  
    107107
    108108                if (offset[0] != offset[1] ||
    109                     bcmp(buffer[0], buffer[1], offset[0])) {
     109                    memcmp(buffer[0], buffer[1], offset[0]) != 0) {
    110110                        rc = 1;
    111111                        goto end;
  • uspace/app/inet/inet.c

    rbe2bb4f rb8e72fd1  
    11/*
    2  * Copyright (c) 2012 Jiri Svoboda
     2 * Copyright (c) 2013 Jiri Svoboda
    33 * All rights reserved.
    44 *
     
    3636
    3737#include <errno.h>
     38#include <inet/addr.h>
    3839#include <inet/inetcfg.h>
    3940#include <loc.h>
     
    5455}
    5556
    56 static int naddr_parse(const char *text, inet_naddr_t *naddr)
    57 {
    58         unsigned long a[4], bits;
    59         char *cp = (char *)text;
    60         int i;
    61 
    62         for (i = 0; i < 3; i++) {
    63                 a[i] = strtoul(cp, &cp, 10);
    64                 if (*cp != '.')
    65                         return EINVAL;
    66                 ++cp;
    67         }
    68 
    69         a[3] = strtoul(cp, &cp, 10);
    70         if (*cp != '/')
    71                 return EINVAL;
    72         ++cp;
    73 
    74         bits = strtoul(cp, &cp, 10);
    75         if (*cp != '\0')
    76                 return EINVAL;
    77 
    78         naddr->ipv4 = 0;
    79         for (i = 0; i < 4; i++) {
    80                 if (a[i] > 255)
    81                         return EINVAL;
    82                 naddr->ipv4 = (naddr->ipv4 << 8) | a[i];
    83         }
    84 
    85         if (bits > 31)
    86                 return EINVAL;
    87 
    88         naddr->bits = bits;
    89         return EOK;
    90 }
    91 
    92 static int addr_parse(const char *text, inet_addr_t *addr)
    93 {
    94         unsigned long a[4];
    95         char *cp = (char *)text;
    96         int i;
    97 
    98         for (i = 0; i < 3; i++) {
    99                 a[i] = strtoul(cp, &cp, 10);
    100                 if (*cp != '.')
    101                         return EINVAL;
    102                 ++cp;
    103         }
    104 
    105         a[3] = strtoul(cp, &cp, 10);
    106         if (*cp != '\0')
    107                 return EINVAL;
    108 
    109         addr->ipv4 = 0;
    110         for (i = 0; i < 4; i++) {
    111                 if (a[i] > 255)
    112                         return EINVAL;
    113                 addr->ipv4 = (addr->ipv4 << 8) | a[i];
    114         }
    115 
    116         return EOK;
    117 }
    118 
    119 static int naddr_format(inet_naddr_t *naddr, char **bufp)
    120 {
    121         int rc;
    122 
    123         rc = asprintf(bufp, "%d.%d.%d.%d/%d", naddr->ipv4 >> 24,
    124             (naddr->ipv4 >> 16) & 0xff, (naddr->ipv4 >> 8) & 0xff,
    125             naddr->ipv4 & 0xff, naddr->bits);
    126 
    127         if (rc < 0)
    128                 return ENOMEM;
    129 
    130         return EOK;
    131 }
    132 
    133 static int addr_format(inet_addr_t *addr, char **bufp)
    134 {
    135         int rc;
    136 
    137         rc = asprintf(bufp, "%d.%d.%d.%d", addr->ipv4 >> 24,
    138             (addr->ipv4 >> 16) & 0xff, (addr->ipv4 >> 8) & 0xff,
    139             addr->ipv4 & 0xff);
    140 
    141         if (rc < 0)
    142                 return ENOMEM;
    143 
    144         return EOK;
    145 }
    146 
    14757static int addr_create_static(int argc, char *argv[])
    14858{
     
    17888        }
    17989
    180         rc = naddr_parse(addr_spec, &naddr);
     90        rc = inet_naddr_parse(addr_spec, &naddr);
    18191        if (rc != EOK) {
    18292                printf(NAME ": Invalid network address format '%s'.\n",
     
    267177        route_name = argv[2];
    268178
    269         rc = naddr_parse(dest_str, &dest);
     179        rc = inet_naddr_parse(dest_str, &dest);
    270180        if (rc != EOK) {
    271181                printf(NAME ": Invalid network address format '%s'.\n",
     
    274184        }
    275185
    276         rc = addr_parse(router_str, &router);
     186        rc = inet_addr_parse(router_str, &router);
    277187        if (rc != EOK) {
    278188                printf(NAME ": Invalid address format '%s'.\n", router_str);
     
    366276                }
    367277
    368                 rc = naddr_format(&ainfo.naddr, &astr);
     278                rc = inet_naddr_format(&ainfo.naddr, &astr);
    369279                if (rc != EOK) {
    370280                        printf("Memory allocation failed.\n");
     
    430340                }
    431341
    432                 rc = naddr_format(&srinfo.dest, &dest_str);
     342                rc = inet_naddr_format(&srinfo.dest, &dest_str);
    433343                if (rc != EOK) {
    434344                        printf("Memory allocation failed.\n");
     
    437347                }
    438348
    439                 rc = addr_format(&srinfo.router, &router_str);
     349                rc = inet_addr_format(&srinfo.router, &router_str);
    440350                if (rc != EOK) {
    441351                        printf("Memory allocation failed.\n");
  • uspace/app/init/init.c

    rbe2bb4f rb8e72fd1  
    359359        srv_start("/srv/tcp");
    360360        srv_start("/srv/udp");
     361        srv_start("/srv/dnsrsrv");
    361362       
    362363        srv_start("/srv/clipboard");
  • uspace/app/nettest1/nettest1.c

    rbe2bb4f rb8e72fd1  
    4646#include <arg_parse.h>
    4747
     48#include <inet/dnsr.h>
    4849#include <net/in.h>
    4950#include <net/in6.h>
     
    7576        printf(
    7677            "Network Networking test 1 aplication - sockets\n"
    77             "Usage: echo [options] numeric_address\n"
     78            "Usage: nettest1 [options] host\n"
    7879            "Where options are:\n"
    7980            "-f protocol_family | --family=protocol_family\n"
     
    290291        struct sockaddr_in address_in;
    291292        struct sockaddr_in6 address_in6;
     293        dnsr_hostinfo_t *hinfo;
    292294        uint8_t *address_start;
    293295
     
    319321        }
    320322
    321         /* If not before the last argument containing the address */
     323        /* If not before the last argument containing the host */
    322324        if (index >= argc) {
    323                 printf("Command line error: missing address\n");
     325                printf("Command line error: missing host name\n");
    324326                nettest1_print_help();
    325327                return EINVAL;
     
    348350        }
    349351
    350         /* Parse the last argument which should contain the address */
     352        /* Parse the last argument which should contain the host/address */
    351353        rc = inet_pton(family, argv[argc - 1], address_start);
    352354        if (rc != EOK) {
    353                 fprintf(stderr, "Address parse error %d\n", rc);
    354                 return rc;
     355                /* Try interpreting as a host name */
     356                rc = dnsr_name2host(argv[argc - 1], &hinfo);
     357                if (rc != EOK) {
     358                        printf("Error resolving host '%s'.\n", argv[argc - 1]);
     359                        return rc;
     360                }
     361
     362                address_in.sin_addr.s_addr = host2uint32_t_be(hinfo->addr.ipv4);
    355363        }
    356364
  • uspace/app/nettest2/nettest2.c

    rbe2bb4f rb8e72fd1  
    4747#include <stdbool.h>
    4848
     49#include <inet/dnsr.h>
    4950#include <net/in.h>
    5051#include <net/in6.h>
     
    7172        printf(
    7273            "Network Networking test 2 aplication - UDP transfer\n"
    73             "Usage: echo [options] address\n"
     74            "Usage: nettest2 [options] host\n"
    7475            "Where options are:\n"
    7576            "-f protocol_family | --family=protocol_family\n"
     
    227228        struct sockaddr_in address_in;
    228229        struct sockaddr_in6 address_in6;
     230        dnsr_hostinfo_t *hinfo;
    229231        socklen_t addrlen;
    230232        uint8_t *address_start;
     
    265267        }
    266268
    267         /* If not before the last argument containing the address */
     269        /* If not before the last argument containing the host */
    268270        if (index >= argc) {
    269                 printf("Command line error: missing address\n");
     271                printf("Command line error: missing host name\n");
    270272                nettest2_print_help();
    271273                return EINVAL;
     
    294296        }
    295297
    296         /* Parse the last argument which should contain the address. */
     298        /* Parse the last argument which should contain the host/address */
    297299        rc = inet_pton(family, argv[argc - 1], address_start);
    298300        if (rc != EOK) {
    299                 fprintf(stderr, "Address parse error %d\n", rc);
    300                 return rc;
     301                /* Try interpreting as a host name */
     302                rc = dnsr_name2host(argv[argc - 1], &hinfo);
     303                if (rc != EOK) {
     304                        printf("Error resolving host '%s'.\n", argv[argc - 1]);
     305                        return rc;
     306                }
     307
     308                address_in.sin_addr.s_addr = host2uint32_t_be(hinfo->addr.ipv4);
    301309        }
    302310
  • uspace/app/nettest3/nettest3.c

    rbe2bb4f rb8e72fd1  
    3939#include <str.h>
    4040
     41#include <inet/dnsr.h>
    4142#include <net/in.h>
    4243#include <net/in6.h>
     
    6061        int fd;
    6162        char *endptr;
     63        dnsr_hostinfo_t *hinfo;
    6264
    6365        port = 7;
     
    7577                rc = inet_pton(AF_INET, argv[1], (uint8_t *)&addr.sin_addr.s_addr);
    7678                if (rc != EOK) {
    77                         fprintf(stderr, "Error parsing address\n");
    78                         return 1;
     79                        /* Try interpreting as a host name */
     80                        rc = dnsr_name2host(argv[1], &hinfo);
     81                        if (rc != EOK) {
     82                                printf("Error resolving host '%s'.\n", argv[1]);
     83                                return rc;
     84                        }
     85
     86                        addr.sin_addr.s_addr = host2uint32_t_be(hinfo->addr.ipv4);
     87                        addr.sin_family = AF_INET;
    7988                }
    8089                printf("result: rc=%d, family=%d, addr=%x\n", rc,
  • uspace/app/nterm/conn.c

    rbe2bb4f rb8e72fd1  
    3333 */
    3434
     35#include <byteorder.h>
    3536#include <stdbool.h>
    3637#include <errno.h>
    3738#include <fibril.h>
     39#include <inet/dnsr.h>
    3840#include <net/socket.h>
    3941#include <stdio.h>
     
    7476{
    7577        struct sockaddr_in addr;
     78        dnsr_hostinfo_t *hinfo = NULL;
    7679        int rc;
    7780        char *endptr;
     
    8184        rc = inet_pton(addr.sin_family, addr_s, (uint8_t *)&addr.sin_addr);
    8285        if (rc != EOK) {
    83                 printf("Invalid addres %s\n", addr_s);
    84                 return EINVAL;
     86                /* Try interpreting as a host name */
     87                rc = dnsr_name2host(addr_s, &hinfo);
     88                if (rc != EOK) {
     89                        printf("Error resolving host '%s'.\n", addr_s);
     90                        goto error;
     91                }
     92
     93                addr.sin_addr.s_addr = host2uint32_t_be(hinfo->addr.ipv4);
    8594        }
    8695
     
    8897        if (*endptr != '\0') {
    8998                printf("Invalid port number %s\n", port_s);
    90                 return EINVAL;
     99                goto error;
    91100        }
    92101
     
    95104                goto error;
    96105
    97         printf("Connecting to address %s port %u\n", addr_s, ntohs(addr.sin_port));
     106        printf("Connecting to host %s port %u\n", addr_s, ntohs(addr.sin_port));
    98107
    99108        rc = connect(conn_fd, (struct sockaddr *)&addr, sizeof(addr));
  • uspace/app/nterm/nterm.c

    rbe2bb4f rb8e72fd1  
    104104static void print_syntax(void)
    105105{
    106         printf("syntax: nterm <ip-address> <port>\n");
     106        printf("syntax: nterm <host> <port>\n");
    107107}
    108108
  • uspace/app/ping/ping.c

    rbe2bb4f rb8e72fd1  
    11/*
    2  * Copyright (c) 2012 Jiri Svoboda
     2 * Copyright (c) 2013 Jiri Svoboda
    33 * All rights reserved.
    44 *
     
    3737#include <errno.h>
    3838#include <fibril_synch.h>
     39#include <inet/dnsr.h>
     40#include <inet/addr.h>
    3941#include <inet/inetping.h>
    4042#include <io/console.h>
     
    6870static void print_syntax(void)
    6971{
    70         printf("syntax: " NAME " [-r] <addr>\n");
    71 }
    72 
    73 static int addr_parse(const char *text, inet_addr_t *addr)
    74 {
    75         unsigned long a[4];
    76         char *cp = (char *)text;
    77         int i;
    78 
    79         for (i = 0; i < 3; i++) {
    80                 a[i] = strtoul(cp, &cp, 10);
    81                 if (*cp != '.')
    82                         return EINVAL;
    83                 ++cp;
    84         }
    85 
    86         a[3] = strtoul(cp, &cp, 10);
    87         if (*cp != '\0')
    88                 return EINVAL;
    89 
    90         addr->ipv4 = 0;
    91         for (i = 0; i < 4; i++) {
    92                 if (a[i] > 255)
    93                         return EINVAL;
    94                 addr->ipv4 = (addr->ipv4 << 8) | a[i];
    95         }
    96 
    97         return EOK;
    98 }
    99 
    100 static int addr_format(inet_addr_t *addr, char **bufp)
    101 {
    102         int rc;
    103 
    104         rc = asprintf(bufp, "%d.%d.%d.%d", addr->ipv4 >> 24,
    105             (addr->ipv4 >> 16) & 0xff, (addr->ipv4 >> 8) & 0xff,
    106             addr->ipv4 & 0xff);
    107 
    108         if (rc < 0)
    109                 return ENOMEM;
    110 
    111         return EOK;
     72        printf("syntax: " NAME " [-r] <host>\n");
    11273}
    11374
     
    12586        int rc;
    12687
    127         rc = addr_format(&sdu->src, &asrc);
     88        rc = inet_addr_format(&sdu->src, &asrc);
    12889        if (rc != EOK)
    12990                return ENOMEM;
    13091
    131         rc = addr_format(&sdu->dest, &adest);
     92        rc = inet_addr_format(&sdu->dest, &adest);
    13293        if (rc != EOK) {
    13394                free(asrc);
     
    213174int main(int argc, char *argv[])
    214175{
     176        dnsr_hostinfo_t *hinfo = NULL;
     177        char *asrc = NULL;
     178        char *adest = NULL;
     179        char *sdest = NULL;
    215180        int rc;
    216181        int argi;
     
    220185                printf(NAME ": Failed connecting to internet ping service "
    221186                    "(%d).\n", rc);
    222                 return 1;
     187                goto error;
    223188        }
    224189
     
    233198        if (argc - argi != 1) {
    234199                print_syntax();
    235                 return 1;
     200                goto error;
    236201        }
    237202
    238203        /* Parse destination address */
    239         rc = addr_parse(argv[argi], &dest_addr);
    240         if (rc != EOK) {
    241                 printf(NAME ": Invalid address format.\n");
    242                 print_syntax();
    243                 return 1;
     204        rc = inet_addr_parse(argv[argi], &dest_addr);
     205        if (rc != EOK) {
     206                /* Try interpreting as a host name */
     207                rc = dnsr_name2host(argv[argi], &hinfo);
     208                if (rc != EOK) {
     209                        printf(NAME ": Error resolving host '%s'.\n", argv[argi]);
     210                        goto error;
     211                }
     212
     213                dest_addr = hinfo->addr;
    244214        }
    245215
     
    248218        if (rc != EOK) {
    249219                printf(NAME ": Failed determining source address.\n");
    250                 return 1;
    251         }
     220                goto error;
     221        }
     222
     223        rc = inet_addr_format(&src_addr, &asrc);
     224        if (rc != EOK) {
     225                printf(NAME ": Out of memory.\n");
     226                goto error;
     227        }
     228
     229        rc = inet_addr_format(&dest_addr, &adest);
     230        if (rc != EOK) {
     231                printf(NAME ": Out of memory.\n");
     232                goto error;
     233        }
     234
     235        if (hinfo != NULL) {
     236                rc = asprintf(&sdest, "%s (%s)", hinfo->cname, adest);
     237                if (rc < 0) {
     238                        printf(NAME ": Out of memory.\n");
     239                        goto error;
     240                }
     241        } else {
     242                sdest = adest;
     243                adest = NULL;
     244        }
     245
     246        printf("Sending ICMP echo request from %s to %s.\n",
     247            asrc, sdest);
    252248
    253249        fid_t fid;
     
    257253                if (fid == 0) {
    258254                        printf(NAME ": Failed creating transmit fibril.\n");
    259                         return 1;
     255                        goto error;
    260256                }
    261257
     
    265261                if (fid == 0) {
    266262                        printf(NAME ": Failed creating input fibril.\n");
    267                         return 1;
     263                        goto error;
    268264                }
    269265
     
    283279        if (rc == ETIMEOUT) {
    284280                printf(NAME ": Echo request timed out.\n");
    285                 return 1;
    286         }
    287 
     281                goto error;
     282        }
     283
     284        free(asrc);
     285        free(adest);
     286        free(sdest);
     287        dnsr_hostinfo_destroy(hinfo);
    288288        return 0;
     289error:
     290        free(asrc);
     291        free(adest);
     292        free(sdest);
     293        dnsr_hostinfo_destroy(hinfo);
     294        return 1;
    289295}
    290296
Note: See TracChangeset for help on using the changeset viewer.