[66a272f8] | 1 | /*
|
---|
| 2 | * Copyright (c) 2012 Jiri Svoboda
|
---|
| 3 | * All rights reserved.
|
---|
| 4 | *
|
---|
| 5 | * Redistribution and use in source and binary forms, with or without
|
---|
| 6 | * modification, are permitted provided that the following conditions
|
---|
| 7 | * are met:
|
---|
| 8 | *
|
---|
| 9 | * - Redistributions of source code must retain the above copyright
|
---|
| 10 | * notice, this list of conditions and the following disclaimer.
|
---|
| 11 | * - Redistributions in binary form must reproduce the above copyright
|
---|
| 12 | * notice, this list of conditions and the following disclaimer in the
|
---|
| 13 | * documentation and/or other materials provided with the distribution.
|
---|
| 14 | * - The name of the author may not be used to endorse or promote products
|
---|
| 15 | * derived from this software without specific prior written permission.
|
---|
| 16 | *
|
---|
| 17 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
---|
| 18 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
---|
| 19 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
---|
| 20 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
---|
| 21 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
---|
| 22 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
---|
| 23 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
---|
| 24 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
---|
| 25 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
---|
| 26 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
---|
| 27 | */
|
---|
| 28 |
|
---|
| 29 | /** @addtogroup udp
|
---|
| 30 | * @{
|
---|
| 31 | */
|
---|
| 32 |
|
---|
| 33 | /**
|
---|
| 34 | * @file UDP (User Datagram Protocol) service
|
---|
| 35 | */
|
---|
| 36 |
|
---|
| 37 | #include <async.h>
|
---|
| 38 | #include <errno.h>
|
---|
| 39 | #include <io/log.h>
|
---|
| 40 | #include <stdio.h>
|
---|
| 41 | #include <task.h>
|
---|
| 42 |
|
---|
[2989c7e] | 43 | #include "assoc.h"
|
---|
[fab2746] | 44 | #include "service.h"
|
---|
[66a272f8] | 45 | #include "udp_inet.h"
|
---|
| 46 |
|
---|
| 47 | #define NAME "udp"
|
---|
| 48 |
|
---|
[89ba88c] | 49 | static udp_assocs_dep_t udp_assocs_dep = {
|
---|
| 50 | .get_srcaddr = udp_get_srcaddr,
|
---|
| 51 | .transmit_msg = udp_transmit_msg
|
---|
| 52 | };
|
---|
| 53 |
|
---|
[b7fd2a0] | 54 | static errno_t udp_init(void)
|
---|
[66a272f8] | 55 | {
|
---|
[b7fd2a0] | 56 | errno_t rc;
|
---|
[66a272f8] | 57 |
|
---|
[a1a101d] | 58 | log_msg(LOG_DEFAULT, LVL_DEBUG, "udp_init()");
|
---|
[66a272f8] | 59 |
|
---|
[89ba88c] | 60 | rc = udp_assocs_init(&udp_assocs_dep);
|
---|
[2989c7e] | 61 | if (rc != EOK) {
|
---|
| 62 | log_msg(LOG_DEFAULT, LVL_ERROR, "Failed initializing associations.");
|
---|
| 63 | return ENOMEM;
|
---|
| 64 | }
|
---|
| 65 |
|
---|
[66a272f8] | 66 | rc = udp_inet_init();
|
---|
| 67 | if (rc != EOK) {
|
---|
[a1a101d] | 68 | log_msg(LOG_DEFAULT, LVL_ERROR, "Failed connecting to internet service.");
|
---|
[66a272f8] | 69 | return ENOENT;
|
---|
| 70 | }
|
---|
| 71 |
|
---|
[fab2746] | 72 | rc = udp_service_init();
|
---|
[66a272f8] | 73 | if (rc != EOK) {
|
---|
[fab2746] | 74 | log_msg(LOG_DEFAULT, LVL_ERROR, "Failed initializing UDP service.");
|
---|
[66a272f8] | 75 | return ENOENT;
|
---|
| 76 | }
|
---|
| 77 |
|
---|
| 78 | return EOK;
|
---|
| 79 | }
|
---|
| 80 |
|
---|
| 81 | int main(int argc, char **argv)
|
---|
| 82 | {
|
---|
[b7fd2a0] | 83 | errno_t rc;
|
---|
[66a272f8] | 84 |
|
---|
| 85 | printf(NAME ": UDP (User Datagram Protocol) service\n");
|
---|
| 86 |
|
---|
[267f235] | 87 | rc = log_init(NAME);
|
---|
[66a272f8] | 88 | if (rc != EOK) {
|
---|
| 89 | printf(NAME ": Failed to initialize log.\n");
|
---|
| 90 | return 1;
|
---|
| 91 | }
|
---|
| 92 |
|
---|
| 93 | rc = udp_init();
|
---|
| 94 | if (rc != EOK)
|
---|
| 95 | return 1;
|
---|
| 96 |
|
---|
| 97 | printf(NAME ": Accepting connections.\n");
|
---|
| 98 | task_retval(0);
|
---|
| 99 | async_manager();
|
---|
| 100 |
|
---|
| 101 | /* Not reached */
|
---|
| 102 | return 0;
|
---|
| 103 | }
|
---|
| 104 |
|
---|
| 105 | /**
|
---|
| 106 | * @}
|
---|
| 107 | */
|
---|