Index: uspace/srv/net/tl/tcp/iqueue.c
===================================================================
--- uspace/srv/net/tl/tcp/iqueue.c	(revision 8c7a0540795c67f9ed8a2831e5830db5daa2cf50)
+++ uspace/srv/net/tl/tcp/iqueue.c	(revision 32aea9f480bd0b1171c0ef3bdc0230277d2d79a0)
@@ -65,4 +65,6 @@
 {
 	tcp_iqueue_entry_t *iqe;
+	tcp_iqueue_entry_t *qe;
+	link_t *link;
 	log_msg(LVL_DEBUG, "tcp_iqueue_insert_seg()");
 
@@ -75,6 +77,19 @@
 	iqe->seg = seg;
 
-	/* XXX Sort by sequence number */
-	list_append(&iqe->link, &iqueue->list);
+	/* Sort by sequence number */
+
+	link = list_first(&iqueue->list);
+	while (link != NULL) {
+		qe = list_get_instance(link,
+		    tcp_iqueue_entry_t, link);
+
+		if (seq_no_seg_cmp(iqueue->conn, iqe->seg, qe->seg) >= 0)
+			break;
+	}
+
+	if (link != NULL)
+		list_insert_before(&iqe->link, &qe->link);
+	else
+		list_append(&iqe->link, &iqueue->list);
 }
 
Index: uspace/srv/net/tl/tcp/seq_no.c
===================================================================
--- uspace/srv/net/tl/tcp/seq_no.c	(revision 8c7a0540795c67f9ed8a2831e5830db5daa2cf50)
+++ uspace/srv/net/tl/tcp/seq_no.c	(revision 32aea9f480bd0b1171c0ef3bdc0230277d2d79a0)
@@ -178,5 +178,5 @@
 
 /** Calculate the amount of trim needed to fit segment in receive window. */
-extern void seq_no_seg_trim_calc(tcp_conn_t *conn, tcp_segment_t *seg,
+void seq_no_seg_trim_calc(tcp_conn_t *conn, tcp_segment_t *seg,
     uint32_t *left, uint32_t *right)
 {
@@ -207,4 +207,30 @@
 }
 
+/** Segment order comparison.
+ *
+ * Compare sequence order of two acceptable segments.
+ *
+ * @param conn		Connection
+ * @param sa		Segment A
+ * @param sb		Segment B
+ *
+ * @return		-1, 0, 1, resp. if A < B, A == B, A > B in terms
+ *			of sequence order of the beginning of the segment.
+ */
+int seq_no_seg_cmp(tcp_conn_t *conn, tcp_segment_t *sa, tcp_segment_t *sb)
+{
+	assert(seq_no_segment_acceptable(conn, sa));
+	assert(seq_no_segment_acceptable(conn, sb));
+
+	if (seq_no_lt_le(sa->seq, sb->seq, conn->rcv_nxt + conn->rcv_wnd))
+		return -1;
+
+	if (seq_no_lt_le(sb->seq, sa->seq, conn->rcv_nxt + conn->rcv_wnd))
+		return +1;
+
+	assert(sa->seq == sb->seq);
+	return 0;
+}
+
 /**
  * @}
Index: uspace/srv/net/tl/tcp/seq_no.h
===================================================================
--- uspace/srv/net/tl/tcp/seq_no.h	(revision 8c7a0540795c67f9ed8a2831e5830db5daa2cf50)
+++ uspace/srv/net/tl/tcp/seq_no.h	(revision 32aea9f480bd0b1171c0ef3bdc0230277d2d79a0)
@@ -48,4 +48,5 @@
 extern void seq_no_seg_trim_calc(tcp_conn_t *, tcp_segment_t *, uint32_t *,
     uint32_t *);
+extern int seq_no_seg_cmp(tcp_conn_t *, tcp_segment_t *, tcp_segment_t *);
 
 extern uint32_t seq_no_control_len(tcp_control_t);
