blob: f744f2f9b8589e64ff5e47156287880422a72b43 [file] [log] [blame]
James Kuszmaul82f6c042021-01-17 11:30:16 -08001/**
2 * @file re_udp.h Interface to User Datagram Protocol
3 *
4 * Copyright (C) 2010 Creytiv.com
5 */
6
7
8struct sa;
9struct 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 */
19typedef void (udp_recv_h)(const struct sa *src, struct mbuf *mb, void *arg);
20typedef void (udp_error_h)(int err, void *arg);
21
22
23int udp_listen(struct udp_sock **usp, const struct sa *local,
24 udp_recv_h *rh, void *arg);
25int udp_connect(struct udp_sock *us, const struct sa *peer);
26int udp_send(struct udp_sock *us, const struct sa *dst, struct mbuf *mb);
27int udp_send_anon(const struct sa *dst, struct mbuf *mb);
28int udp_local_get(const struct udp_sock *us, struct sa *local);
29int udp_setsockopt(struct udp_sock *us, int level, int optname,
30 const void *optval, uint32_t optlen);
31int udp_sockbuf_set(struct udp_sock *us, int size);
32void udp_rxsz_set(struct udp_sock *us, size_t rxsz);
33void udp_rxbuf_presz_set(struct udp_sock *us, size_t rx_presz);
34void udp_handler_set(struct udp_sock *us, udp_recv_h *rh, void *arg);
35void udp_error_handler_set(struct udp_sock *us, udp_error_h *eh);
36int udp_thread_attach(struct udp_sock *us);
37void udp_thread_detach(struct udp_sock *us);
38int udp_sock_fd(const struct udp_sock *us, int af);
39
40int udp_multicast_join(struct udp_sock *us, const struct sa *group);
41int udp_multicast_leave(struct udp_sock *us, const struct sa *group);
42
43
44/* Helper API */
45typedef bool (udp_helper_send_h)(int *err, struct sa *dst,
46 struct mbuf *mb, void *arg);
47typedef bool (udp_helper_recv_h)(struct sa *src,
48 struct mbuf *mb, void *arg);
49
50struct udp_helper;
51
52
53int 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);
57int udp_send_helper(struct udp_sock *us, const struct sa *dst,
58 struct mbuf *mb, struct udp_helper *uh);
59struct udp_helper *udp_helper_find(const struct udp_sock *us, int layer);