source: mainline/uspace/srv/net/udp/udp.c

Last change on this file was 89ba88c, checked in by Jiri Svoboda <jiri@…>, 6 years ago

Test udp_assoc_send()

This required virtualizing inet_get_src_addr() / udp_transmit_msg for the
association module

  • Property mode set to 100644
File size: 2.7 KB
Line 
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
43#include "assoc.h"
44#include "service.h"
45#include "udp_inet.h"
46
47#define NAME "udp"
48
49static udp_assocs_dep_t udp_assocs_dep = {
50 .get_srcaddr = udp_get_srcaddr,
51 .transmit_msg = udp_transmit_msg
52};
53
54static errno_t udp_init(void)
55{
56 errno_t rc;
57
58 log_msg(LOG_DEFAULT, LVL_DEBUG, "udp_init()");
59
60 rc = udp_assocs_init(&udp_assocs_dep);
61 if (rc != EOK) {
62 log_msg(LOG_DEFAULT, LVL_ERROR, "Failed initializing associations.");
63 return ENOMEM;
64 }
65
66 rc = udp_inet_init();
67 if (rc != EOK) {
68 log_msg(LOG_DEFAULT, LVL_ERROR, "Failed connecting to internet service.");
69 return ENOENT;
70 }
71
72 rc = udp_service_init();
73 if (rc != EOK) {
74 log_msg(LOG_DEFAULT, LVL_ERROR, "Failed initializing UDP service.");
75 return ENOENT;
76 }
77
78 return EOK;
79}
80
81int main(int argc, char **argv)
82{
83 errno_t rc;
84
85 printf(NAME ": UDP (User Datagram Protocol) service\n");
86
87 rc = log_init(NAME);
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 */
Note: See TracBrowser for help on using the repository browser.