Changeset 4e716180 in mainline for uspace/app


Ignore:
Timestamp:
2013-05-03T21:14:39Z (13 years ago)
Author:
Jiri Svoboda <jiri@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
716357f
Parents:
1c7ba2da (diff), 5d1cb8a (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 simple DNS resolver.

Location:
uspace/app
Files:
4 added
7 edited

Legend:

Unmodified
Added
Removed
  • uspace/app/init/init.c

    r1c7ba2da r4e716180  
    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

    r1c7ba2da r4e716180  
    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

    r1c7ba2da r4e716180  
    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

    r1c7ba2da r4e716180  
    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

    r1c7ba2da r4e716180  
    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

    r1c7ba2da r4e716180  
    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

    r1c7ba2da r4e716180  
    3737#include <errno.h>
    3838#include <fibril_synch.h>
     39#include <inet/dnsr.h>
    3940#include <inet/addr.h>
    4041#include <inet/inetping.h>
     
    6970static void print_syntax(void)
    7071{
    71         printf("syntax: " NAME " [-r] <addr>\n");
     72        printf("syntax: " NAME " [-r] <host>\n");
    7273}
    7374
     
    173174int main(int argc, char *argv[])
    174175{
     176        dnsr_hostinfo_t *hinfo = NULL;
     177        char *asrc = NULL;
     178        char *adest = NULL;
     179        char *sdest = NULL;
    175180        int rc;
    176181        int argi;
     
    180185                printf(NAME ": Failed connecting to internet ping service "
    181186                    "(%d).\n", rc);
    182                 return 1;
     187                goto error;
    183188        }
    184189
     
    193198        if (argc - argi != 1) {
    194199                print_syntax();
    195                 return 1;
     200                goto error;
    196201        }
    197202
     
    199204        rc = inet_addr_parse(argv[argi], &dest_addr);
    200205        if (rc != EOK) {
    201                 printf(NAME ": Invalid address format.\n");
    202                 print_syntax();
    203                 return 1;
     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;
    204214        }
    205215
     
    208218        if (rc != EOK) {
    209219                printf(NAME ": Failed determining source address.\n");
    210                 return 1;
    211         }
     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->name, 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);
    212248
    213249        fid_t fid;
     
    217253                if (fid == 0) {
    218254                        printf(NAME ": Failed creating transmit fibril.\n");
    219                         return 1;
     255                        goto error;
    220256                }
    221257
     
    225261                if (fid == 0) {
    226262                        printf(NAME ": Failed creating input fibril.\n");
    227                         return 1;
     263                        goto error;
    228264                }
    229265
     
    243279        if (rc == ETIMEOUT) {
    244280                printf(NAME ": Echo request timed out.\n");
    245                 return 1;
    246         }
    247 
     281                goto error;
     282        }
     283
     284        free(asrc);
     285        free(adest);
     286        free(sdest);
     287        dnsr_hostinfo_destroy(hinfo);
    248288        return 0;
     289error:
     290        free(asrc);
     291        free(adest);
     292        free(sdest);
     293        dnsr_hostinfo_destroy(hinfo);
     294        return 1;
    249295}
    250296
Note: See TracChangeset for help on using the changeset viewer.