UbixOS V2  2.0
udpecho.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2001, Swedish Institute of Computer Science.
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  * 1. Redistributions of source code must retain the above copyright
9  * notice, this list of conditions and the following disclaimer.
10  * 2. Redistributions in binary form must reproduce the above copyright
11  * notice, this list of conditions and the following disclaimer in the
12  * documentation and/or other materials provided with the distribution.
13  * 3. Neither the name of the Institute nor the names of its contributors
14  * may be used to endorse or promote products derived from this software
15  * without specific prior written permission.
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
18  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20  * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
21  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27  * SUCH DAMAGE.
28  *
29  * This file is part of the lwIP TCP/IP stack.
30  *
31  * Author: Adam Dunkels <adam@sics.se>
32  *
33  * $Id: udpecho.c 54 2016-01-11 01:29:55Z reddawg $
34  */
35 
36 #include <sys/types.h>
37 #include <lib/kprintf.h>
38 
39 #include "net/api.h"
40 #include "net/sys.h"
41 
42 /*-----------------------------------------------------------------------------------*/
43 void udpecho_thread(void *arg) {
44  static struct netconn *conn;
45  static struct netbuf *buf;
46  static struct ip_addr *addr;
47  static unsigned short port;
48  char buffer[4096];
49 
50  conn = netconn_new(NETCONN_UDP);
51  netconn_bind(conn, NULL, 7);
52 
53  while (1) {
54  buf = netconn_recv(conn);
55  addr = netbuf_fromaddr(buf);
56  port = netbuf_fromport(buf);
57  netconn_connect(conn, addr, port);
58  netconn_send(conn, buf);
59  netbuf_copy(buf, buffer, sizeof(buffer));
60  netbuf_delete(buf);
61  }
62 }
63 /*-----------------------------------------------------------------------------------*/
64 void udpecho_init(void) {
66 }
sys.h
buffer
char * buffer
Definition: shell.c:47
sys_thread_new
sys_thread_t sys_thread_new(const char *name, lwip_thread_fn thread, void *arg, int stacksize, int prio)
Definition: sys_arch.c:379
udpecho_init
void udpecho_init(void)
Definition: udpecho.c:64
types.h
kprintf.h
buf
Definition: buf.h:35
udpecho_thread
void udpecho_thread(void *arg)
Definition: udpecho.c:43
api.h
NULL
#define NULL
Definition: fat_string.h:17