1 /* Author: Domen Puncer Kugler <domen@cba.si>. License: WTFPL, see file LICENSE */
9 //#define udp_print_array print_array
10 #define udp_print_array(tag, buf, size)
13 static LIST_DECLARE_INIT(udp_handler_list
);
16 static int udp_handle(u8
*buf
, unsigned len
)
18 struct udp_packet
*udp
= (struct udp_packet
*)buf
;
19 int l
= get_be16(udp
->len
);
20 int port
= get_be16(udp
->dport
);
25 udp_print_array("UDX RX", buf
, sizeof(*udp
));
27 if (len
<= sizeof(*udp
))
30 /* skip ports, len, checksum for now */
33 udp_print_array("UDX RX data", udp
->payload
, len
);
36 list_for_each(&udp_handler_list
, it
) {
37 struct udp_handler
*han
= list_entry(it
, struct udp_handler
, list
);
39 if (port
== han
->port
)
40 return han
->handler(udp
->payload
, len
);
46 static struct ip_handler ip_handler_udp
= {
47 .list
= LIST_INIT(ip_handler_udp
.list
),
48 .protocol
= IP_PROT_UDP
,
49 .handler
= udp_handle
,
54 return ip_register_handler(&ip_handler_udp
);
57 int udp_register_handler(struct udp_handler
*han
)
59 list_add_tail(&udp_handler_list
, &han
->list
);