Index: uspace/lib/c/generic/inet/endpoint.c
===================================================================
--- uspace/lib/c/generic/inet/endpoint.c	(revision 47726b5e33f32673a583b9c6e90c4327cec059fa)
+++ uspace/lib/c/generic/inet/endpoint.c	(revision 6a8ce16e9d7ca696b63ae994c87911928c450d62)
@@ -36,4 +36,10 @@
 #include <mem.h>
 
+/** Initialize endpoint structure.
+ *
+ * Sets any address, any port number.
+ *
+ * @param ep Endpoint
+ */
 void inet_ep_init(inet_ep_t *ep)
 {
@@ -41,4 +47,10 @@
 }
 
+/** Initialize endpoint pair structure.
+ *
+ * Sets any address, any port number for both local and remote sides.
+ *
+ * @param ep2 Endpoint pair
+ */
 void inet_ep2_init(inet_ep2_t *ep2)
 {
Index: uspace/lib/c/generic/inet/tcp.c
===================================================================
--- uspace/lib/c/generic/inet/tcp.c	(revision 47726b5e33f32673a583b9c6e90c4327cec059fa)
+++ uspace/lib/c/generic/inet/tcp.c	(revision 6a8ce16e9d7ca696b63ae994c87911928c450d62)
@@ -44,10 +44,21 @@
 static int tcp_conn_fibril(void *);
 
-/** Incoming TCP connection info */
+/** Incoming TCP connection info
+ *
+ * Used to pass information about incoming TCP connection to the connection
+ * fibril
+ */
 typedef struct {
+	/** Listener who received the connection */
 	tcp_listener_t *lst;
+	/** Incoming connection */
 	tcp_conn_t *conn;
 } tcp_in_conn_t;
 
+/** Create callback connection from TCP service.
+ *
+ * @param tcp TCP service
+ * @return EOK on success or negative error code
+ */
 static int tcp_callback_create(tcp_t *tcp)
 {
@@ -67,4 +78,10 @@
 }
 
+/** Create TCP client instance.
+ *
+ * @param  rtcp Place to store pointer to new TCP client
+ * @return EOK on success, ENOMEM if out of memory, EIO if service
+ *         cannot be contacted
+ */
 int tcp_create(tcp_t **rtcp)
 {
@@ -111,4 +128,8 @@
 }
 
+/** Destroy TCP client instance.
+ *
+ * @param tcp TCP client
+ */
 void tcp_destroy(tcp_t *tcp)
 {
@@ -126,4 +147,14 @@
 }
 
+/** Create new TCP connection
+ *
+ * @param tcp   TCP client instance
+ * @param id    Connection ID
+ * @param cb    Callbacks
+ * @param arg   Callback argument
+ * @param rconn Place to store pointer to new connection
+ *
+ * @return EOK on success, ENOMEM if out of memory
+ */
 static int tcp_conn_new(tcp_t *tcp, sysarg_t id, tcp_cb_t *cb, void *arg,
     tcp_conn_t **rconn)
@@ -150,4 +181,26 @@
 }
 
+/** Create new TCP connection.
+ *
+ * Open a connection to the specified destination. This function returns
+ * even before the connection is established (or not). When the connection
+ * is established, @a cb->connected is called. If the connection fails,
+ * @a cb->conn_failed is called. Alternatively, the caller can call
+ * @c tcp_conn_wait_connected() to wait for connection to complete or fail.
+ * Other callbacks are available to monitor the changes in connection state.
+ *
+ * @a epp must specify the remote address and port. Both local address and
+ * port are optional. If local address is not specified, address selection
+ * will take place. If local port number is not specified, a suitable
+ * free dynamic port number will be allocated.
+ *
+ * @param tcp   TCP client
+ * @param epp   Internet endpoint pair
+ * @param cb    Callbacks
+ * @param arg   Argument to callbacks
+ * @param rconn Place to store pointer to new connection
+ *
+ * @return EOK on success or negative error code.
+ */
 int tcp_conn_create(tcp_t *tcp, inet_ep2_t *epp, tcp_cb_t *cb, void *arg,
     tcp_conn_t **rconn)
@@ -186,4 +239,11 @@
 }
 
+/** Destroy TCP connection.
+ *
+ * Destroy TCP connection. The caller should destroy all connections
+ * he created before destroying the TCP client and before terminating.
+ *
+ * @param conn TCP connection
+ */
 void tcp_conn_destroy(tcp_conn_t *conn)
 {
@@ -203,4 +263,12 @@
 }
 
+/** Get connection based on its ID.
+ *
+ * @param tcp   TCP client
+ * @param id    Connection ID
+ * @param rconn Place to store pointer to connection
+ *
+ * @return EOK on success, EINVAL if no connection with the given ID exists
+ */
 static int tcp_conn_get(tcp_t *tcp, sysarg_t id, tcp_conn_t **rconn)
 {
@@ -215,4 +283,9 @@
 }
 
+/** Get the user/callback argument for a connection.
+ *
+ * @param conn TCP connection
+ * @return User argument associated with connection
+ */
 void *tcp_conn_userptr(tcp_conn_t *conn)
 {
@@ -220,4 +293,25 @@
 }
 
+/** Create a TCP connection listener.
+ *
+ * A listener listens for connections on the set of endpoints specified
+ * by @a ep. Each time a new incoming connection is established,
+ * @a lcb->new_conn is called (and passed @a larg). Also, the new connection
+ * will have callbacks set to @a cb and argument to @a arg.
+ *
+ * @a ep must specify a valid port number. @a ep may specify an address
+ * or link to listen on. If it does not, the listener will listen on
+ * all links/addresses.
+ *
+ * @param tcp  TCP client
+ * @param ep   Internet endpoint
+ * @param lcb  Listener callbacks
+ * @param larg Listener callback argument
+ * @param cb   Connection callbacks for every new connection
+ * @param arg  Connection argument for every new connection
+ * @param rlst Place to store pointer to new listener
+ *
+ * @return EOK on success or negative error code
+ */
 int tcp_listener_create(tcp_t *tcp, inet_ep_t *ep, tcp_listen_cb_t *lcb,
     void *larg, tcp_cb_t *cb, void *arg, tcp_listener_t **rlst)
@@ -265,4 +359,8 @@
 }
 
+/** Destroy TCP connection listener.
+ *
+ * @param lst Listener
+ */
 void tcp_listener_destroy(tcp_listener_t *lst)
 {
@@ -282,4 +380,12 @@
 }
 
+/** Get TCP connection listener based on its ID.
+ *
+ * @param tcp TCP client
+ * @param id  Listener ID
+ * @param rlst Place to store pointer to listener
+ *
+ * @return EOK on success, EINVAL if no listener with the given ID is found
+ */
 static int tcp_listener_get(tcp_t *tcp, sysarg_t id, tcp_listener_t **rlst)
 {
@@ -294,4 +400,9 @@
 }
 
+/** Get callback/user argument associated with listener.
+ *
+ * @param lst Listener
+ * @return Callback/user argument
+ */
 void *tcp_listener_userptr(tcp_listener_t *lst)
 {
@@ -299,4 +410,14 @@
 }
 
+/** Wait until connection is either established or connection fails.
+ *
+ * Can be called after calling tcp_conn_create() to block until connection
+ * either completes or fails. If the connection fails, EIO is returned.
+ * In this case the connection still exists, but is in a failed
+ * state.
+ *
+ * @param conn Connection
+ * @return EOK if connection is established, EIO otherwise
+ */
 int tcp_conn_wait_connected(tcp_conn_t *conn)
 {
@@ -315,4 +436,12 @@
 }
 
+/** Send data over TCP connection.
+ *
+ * @param conn  Connection
+ * @param data  Data
+ * @param bytes Data size in bytes
+ *
+ * @return EOK on success or negative error code
+ */
 int tcp_conn_send(tcp_conn_t *conn, const void *data, size_t bytes)
 {
@@ -340,5 +469,11 @@
 }
 
-
+/** Send FIN.
+ *
+ * Send FIN, indicating no more data will be send over the connection.
+ *
+ * @param conn Connection
+ * @return EOK on success or negative error code
+ */
 int tcp_conn_send_fin(tcp_conn_t *conn)
 {
@@ -352,4 +487,9 @@
 }
 
+/** Push connection.
+ *
+ * @param conn Connection
+ * @return EOK on success or negative error code
+ */
 int tcp_conn_push(tcp_conn_t *conn)
 {
@@ -363,4 +503,9 @@
 }
 
+/** Reset connection.
+ *
+ * @param conn Connection
+ * @return EOK on success or negative error code
+ */
 int tcp_conn_reset(tcp_conn_t *conn)
 {
@@ -374,4 +519,21 @@
 }
 
+/** Read received data from connection without blocking.
+ *
+ * If any received data is pending on the connection, up to @a bsize bytes
+ * are copied to @a buf and the acutal number is stored in @a *nrecv.
+ * The entire buffer of @a bsize bytes is filled except when less data
+ * is currently available or FIN is received. EOK is returned.
+ *
+ * If no received data is pending, returns EAGAIN.
+ *
+ * @param conn Connection
+ * @param buf  Buffer
+ * @param bsize Buffer size
+ * @param nrecv Place to store actual number of received bytes
+ *
+ * @return EOK on success, EAGAIN if no received data is pending, or other
+ *         negative error code in case of other error
+ */
 int tcp_conn_recv(tcp_conn_t *conn, void *buf, size_t bsize, size_t *nrecv)
 {
@@ -408,5 +570,20 @@
 }
 
-int tcp_conn_recv_wait(tcp_conn_t *conn, void *buf, size_t bsize, size_t *nrecv)
+/** Read received data from connection with blocking.
+ *
+ * Wait for @a bsize bytes of data to be received and copy them to
+ * @a buf. Less data may be returned if FIN is received on the connection.
+ * The actual If any received data is written to @a *nrecv and EOK
+ * is returned on success.
+ *
+ * @param conn Connection
+ * @param buf  Buffer
+ * @param bsize Buffer size
+ * @param nrecv Place to store actual number of received bytes
+ *
+ * @return EOK on success or negative error code
+ */
+int tcp_conn_recv_wait(tcp_conn_t *conn, void *buf, size_t bsize,
+    size_t *nrecv)
 {
 	async_exch_t *exch;
@@ -450,4 +627,10 @@
 }
 
+/** Connection established event.
+ *
+ * @param tcp TCP client
+ * @param iid Call ID
+ * @param icall Call data
+ */
 static void tcp_ev_connected(tcp_t *tcp, ipc_callid_t iid, ipc_call_t *icall)
 {
@@ -472,4 +655,10 @@
 }
 
+/** Connection failed event.
+ *
+ * @param tcp TCP client
+ * @param iid Call ID
+ * @param icall Call data
+ */
 static void tcp_ev_conn_failed(tcp_t *tcp, ipc_callid_t iid, ipc_call_t *icall)
 {
@@ -494,4 +683,10 @@
 }
 
+/** Connection reset event.
+ *
+ * @param tcp TCP client
+ * @param iid Call ID
+ * @param icall Call data
+ */
 static void tcp_ev_conn_reset(tcp_t *tcp, ipc_callid_t iid, ipc_call_t *icall)
 {
@@ -516,4 +711,10 @@
 }
 
+/** Data available event.
+ *
+ * @param tcp TCP client
+ * @param iid Call ID
+ * @param icall Call data
+ */
 static void tcp_ev_data(tcp_t *tcp, ipc_callid_t iid, ipc_call_t *icall)
 {
@@ -539,4 +740,10 @@
 }
 
+/** Urgent data event.
+ *
+ * @param tcp TCP client
+ * @param iid Call ID
+ * @param icall Call data
+ */
 static void tcp_ev_urg_data(tcp_t *tcp, ipc_callid_t iid, ipc_call_t *icall)
 {
@@ -544,4 +751,10 @@
 }
 
+/** New connection event.
+ *
+ * @param tcp TCP client
+ * @param iid Call ID
+ * @param icall Call data
+ */
 static void tcp_ev_new_conn(tcp_t *tcp, ipc_callid_t iid, ipc_call_t *icall)
 {
@@ -590,4 +803,10 @@
 }
 
+/** Callback connection handler.
+ *
+ * @param iid Connect call ID
+ * @param icall Connect call data
+ * @param arg Argument, TCP client
+ */
 static void tcp_cb_conn(ipc_callid_t iid, ipc_call_t *icall, void *arg)
 {
@@ -636,5 +855,8 @@
 }
 
-/** Fibril for handling incoming TCP connection in background */
+/** Fibril for handling incoming TCP connection in background.
+ *
+ * @param arg Argument, incoming connection information (@c tcp_in_conn_t)
+ */
 static int tcp_conn_fibril(void *arg)
 {
Index: uspace/lib/c/generic/inet/udp.c
===================================================================
--- uspace/lib/c/generic/inet/udp.c	(revision 47726b5e33f32673a583b9c6e90c4327cec059fa)
+++ uspace/lib/c/generic/inet/udp.c	(revision 6a8ce16e9d7ca696b63ae994c87911928c450d62)
@@ -43,4 +43,9 @@
 static void udp_cb_conn(ipc_callid_t, ipc_call_t *, void *);
 
+/** Create callback connection from UDP service.
+ *
+ * @param udp UDP service
+ * @return EOK on success or negative error code
+ */
 static int udp_callback_create(udp_t *udp)
 {
@@ -60,4 +65,10 @@
 }
 
+/** Create UDP client instance.
+ *
+ * @param  rudp Place to store pointer to new UDP client
+ * @return EOK on success, ENOMEM if out of memory, EIO if service
+ *         cannot be contacted
+ */
 int udp_create(udp_t **rudp)
 {
@@ -103,4 +114,8 @@
 }
 
+/** Destroy UDP client instance.
+ *
+ * @param udp UDP client
+ */
 void udp_destroy(udp_t *udp)
 {
@@ -118,5 +133,28 @@
 }
 
-int udp_assoc_create(udp_t *udp, inet_ep2_t *ep2, udp_cb_t *cb, void *arg,
+/** Create new UDP association.
+ *
+ * Create a UDP association that allows sending and receiving messages.
+ *
+ * @a epp may specify remote address and port, in which case only messages
+ * from that remote endpoint will be received. Also, that remote endpoint
+ * is used as default when @c NULL is passed as destination to
+ * udp_assoc_send_msg.
+ *
+ * @a epp may specify a local link or address. If it does not, the association
+ * will listen on all local links/addresses. If @a epp does not specify
+ * a local port number, a free dynamic port number will be allocated.
+ *
+ * The caller is informed about incoming data by invoking @a cb->recv_msg
+ *
+ * @param udp    UDP client
+ * @param epp    Internet endpoint pair
+ * @param cb     Callbacks
+ * @param arg    Argument to callbacks
+ * @param rassoc Place to store pointer to new association
+ *
+ * @return EOK on success or negative error code.
+ */
+int udp_assoc_create(udp_t *udp, inet_ep2_t *epp, udp_cb_t *cb, void *arg,
     udp_assoc_t **rassoc)
 {
@@ -131,5 +169,5 @@
 	exch = async_exchange_begin(udp->sess);
 	aid_t req = async_send_0(exch, UDP_ASSOC_CREATE, &answer);
-	sysarg_t rc = async_data_write_start(exch, (void *)ep2,
+	sysarg_t rc = async_data_write_start(exch, (void *)epp,
 	    sizeof(inet_ep2_t));
 	async_exchange_end(exch);
@@ -161,4 +199,11 @@
 }
 
+/** Destroy UDP association.
+ *
+ * Destroy UDP association. The caller should destroy all associations
+ * he created before destroying the UDP client and before terminating.
+ *
+ * @param assoc UDP association
+ */
 void udp_assoc_destroy(udp_assoc_t *assoc)
 {
@@ -178,4 +223,13 @@
 }
 
+/** Send message via UDP association.
+ *
+ * @param assoc Association
+ * @param dest	Destination endpoint or @c NULL to use association's remote ep.
+ * @param data	Message data
+ * @param bytes Message size in bytes
+ *
+ * @return EOK on success or negative error code
+ */
 int udp_assoc_send_msg(udp_assoc_t *assoc, inet_ep_t *dest, void *data,
     size_t bytes)
@@ -211,4 +265,9 @@
 }
 
+/** Get the user/callback argument for an association.
+ *
+ * @param assoc UDP association
+ * @return User argument associated with association
+ */
 void *udp_assoc_userptr(udp_assoc_t *assoc)
 {
@@ -216,4 +275,13 @@
 }
 
+/** Get size of received message in bytes.
+ *
+ * Assuming jumbo messages can be received, the caller first needs to determine
+ * the size of the received message by calling this function, then they can
+ * read the message piece-wise using udp_rmsg_read().
+ *
+ * @param rmsg Received message
+ * @return Size of received message in bytes
+ */
 size_t udp_rmsg_size(udp_rmsg_t *rmsg)
 {
@@ -221,4 +289,13 @@
 }
 
+/** Read part of received message.
+ *
+ * @param rmsg  Received message
+ * @param off   Start offset
+ * @param buf   Buffer for storing data
+ * @param bsize Buffer size
+ *
+ * @return EOK on success or negative error code.
+ */
 int udp_rmsg_read(udp_rmsg_t *rmsg, size_t off, void *buf, size_t bsize)
 {
@@ -245,4 +322,12 @@
 }
 
+/** Get remote endpoint of received message.
+ *
+ * Place the remote endpoint (the one from which the message was supposedly
+ * sent) to @a ep.
+ *
+ * @param rmsg Received message
+ * @param ep   Place to store remote endpoint
+ */
 void udp_rmsg_remote_ep(udp_rmsg_t *rmsg, inet_ep_t *ep)
 {
@@ -250,4 +335,9 @@
 }
 
+/** Get type of received ICMP error message.
+ *
+ * @param rerr Received error message
+ * @return Error message type
+ */
 uint8_t udp_rerr_type(udp_rerr_t *rerr)
 {
@@ -255,4 +345,9 @@
 }
 
+/** Get code of received ICMP error message.
+ *
+ * @param rerr Received error message
+ * @return Error message code
+ */
 uint8_t udp_rerr_code(udp_rerr_t *rerr)
 {
@@ -260,4 +355,11 @@
 }
 
+/** Get information about the next received message from UDP service.
+ *
+ * @param udp  UDP client
+ * @param rmsg Place to store message information
+ *
+ * @return EOK on success or negative error code
+ */
 static int udp_rmsg_info(udp_t *udp, udp_rmsg_t *rmsg)
 {
@@ -288,4 +390,9 @@
 }
 
+/** Discard next received message in UDP service.
+ *
+ * @param udp UDP client
+ * @return EOK on success or negative error code
+ */
 static int udp_rmsg_discard(udp_t *udp)
 {
@@ -299,4 +406,12 @@
 }
 
+/** Get association based on its ID.
+ *
+ * @param udp    UDP client
+ * @param id     Association ID
+ * @param rassoc Place to store pointer to association
+ *
+ * @return EOK on success, EINVAL if no association with the given ID exists
+ */
 static int udp_assoc_get(udp_t *udp, sysarg_t id, udp_assoc_t **rassoc)
 {
@@ -311,4 +426,13 @@
 }
 
+/** Handle 'data' event, i.e. some message(s) arrived.
+ *
+ * For each received message, get information about it, call @c recv_msg
+ * callback and discard it.
+ *
+ * @param udp UDP client
+ * @param iid IPC message ID
+ * @param icall IPC message
+ */
 static void udp_ev_data(udp_t *udp, ipc_callid_t iid, ipc_call_t *icall)
 {
@@ -340,4 +464,10 @@
 }
 
+/** UDP service callback connection.
+ *
+ * @param iid Connect message ID
+ * @param icall Connect message
+ * @param arg Argument, UDP client
+ */
 static void udp_cb_conn(ipc_callid_t iid, ipc_call_t *icall, void *arg)
 {
