The udp interface is not similar to tcp, so the webserver code is not too helpful.
To send by udp, first get a packet with udp_alloc() specifying your data length and zero for the optlen. This sets the nb_prot pointer correctly but puts junk in nb_len. Replace nb_len with your length, copy your data to nb_prot, and set fhost to the ip address. Now you can call udp_send with the two ports and the packet.
To receive by udp, you must write an upcall function, and install it with udp_open(). When a packet arrives, the upcall function is called by the ip stack with a packet. You get at the data using the nb_prot pointer and nb_len length. The remote host is at fhost. Getting the remote port is tricky; I use:
Code:
struct udp *pup = (struct udp *) (p->nb_prot - sizeof(struct udp));port = pup->ud_srcp;
You should release the packet with udp_free() when you no longer need it (don't keep it very long because there aren't many packets).
Note that the example webserver uses msring, but the distributed copy of msring_add() has the % character (percent for modulus) replaced by & (ampersand) in the first line, which could lead to mysterious bugs.