8 * This file defines the gPXE UDP API.
14 #include <gpxe/pkbuff.h>
15 #include <gpxe/if_ether.h>
21 #define UDP_MAX_HLEN 72
22 #define UDP_MAX_TXPKB ETH_MAX_MTU
23 #define UDP_MIN_TXPKB ETH_ZLEN
25 typedef uint16_t port_t;
37 struct udp_connection;
43 struct udp_operations {
47 * @v conn UDP connection
49 * @v len Length of data
51 void ( * newdata ) ( struct udp_connection *conn,
52 void *data, size_t len );
59 struct udp_connection {
60 /** Address of the remote end of the connection */
62 /** Local port on which the connection receives packets */
64 /** Transmit buffer */
65 struct pk_buff *tx_pkb;
66 /** List of registered connections */
67 struct list_head list;
68 /** Operations table for this connection */
69 struct udp_operations *udp_op;
73 * List of registered UDP connections
75 static LIST_HEAD ( udp_conns );
80 extern struct tcpip_protocol udp_protocol;
83 * Functions provided to the application layer
86 extern void udp_init ( struct udp_connection *conn, struct udp_operations *udp_op );
87 extern int udp_open ( struct udp_connection *conn, uint16_t local_port );
89 extern void udp_connect ( struct udp_connection *conn, struct sockaddr *peer );
90 extern void udp_close ( struct udp_connection *conn );
92 extern int udp_send ( struct udp_connection *conn, const void *data, size_t len );
93 extern int udp_sendto ( struct udp_connection *conn, struct sockaddr *peer, const void *data, size_t len );
95 static inline void * udp_buffer ( struct udp_connection *conn ) {
96 return conn->tx_pkb->data;
99 static inline int udp_buflen ( struct udp_connection *conn ) {
100 return pkb_len ( conn->tx_pkb );
103 #endif /* _GPXE_UDP_H */