1 /**
2  * @file re_udp.h  Interface to User Datagram Protocol
3  *
4  * Copyright (C) 2010 Creytiv.com
5  */
6 
7 
8 struct sa;
9 struct udp_sock;
10 
11 
12 /**
13  * Defines the UDP Receive handler
14  *
15  * @param src Source address
16  * @param mb  Datagram buffer
17  * @param arg Handler argument
18  */
19 typedef void (udp_recv_h)(const struct sa *src, struct mbuf *mb, void *arg);
20 typedef void (udp_error_h)(int err, void *arg);
21 
22 
23 int  udp_listen(struct udp_sock **usp, const struct sa *local,
24 		udp_recv_h *rh, void *arg);
25 int  udp_connect(struct udp_sock *us, const struct sa *peer);
26 int  udp_send(struct udp_sock *us, const struct sa *dst, struct mbuf *mb);
27 int  udp_send_anon(const struct sa *dst, struct mbuf *mb);
28 int  udp_local_get(const struct udp_sock *us, struct sa *local);
29 int  udp_setsockopt(struct udp_sock *us, int level, int optname,
30 		    const void *optval, uint32_t optlen);
31 int  udp_sockbuf_set(struct udp_sock *us, int size);
32 void udp_rxsz_set(struct udp_sock *us, size_t rxsz);
33 void udp_rxbuf_presz_set(struct udp_sock *us, size_t rx_presz);
34 void udp_handler_set(struct udp_sock *us, udp_recv_h *rh, void *arg);
35 void udp_error_handler_set(struct udp_sock *us, udp_error_h *eh);
36 int  udp_thread_attach(struct udp_sock *us);
37 void udp_thread_detach(struct udp_sock *us);
38 int  udp_sock_fd(const struct udp_sock *us, int af);
39 
40 int  udp_multicast_join(struct udp_sock *us, const struct sa *group);
41 int  udp_multicast_leave(struct udp_sock *us, const struct sa *group);
42 
43 
44 /* Helper API */
45 typedef bool (udp_helper_send_h)(int *err, struct sa *dst,
46 				 struct mbuf *mb, void *arg);
47 typedef bool (udp_helper_recv_h)(struct sa *src,
48 				 struct mbuf *mb, void *arg);
49 
50 struct udp_helper;
51 
52 
53 int udp_register_helper(struct udp_helper **uhp, struct udp_sock *us,
54 			int layer,
55 			udp_helper_send_h *sh, udp_helper_recv_h *rh,
56 			void *arg);
57 int udp_send_helper(struct udp_sock *us, const struct sa *dst,
58 		    struct mbuf *mb, struct udp_helper *uh);
59 struct udp_helper *udp_helper_find(const struct udp_sock *us, int layer);
60