- total_socket_out += r;
-cp
- return 0;
-}
-
-/*
- write as many bytes as possible to the tap
- device, possibly in multiple turns.
-*/
-int write_n(int fd, void *buf, size_t len)
-{
- int r, done = 0;
-cp
- do
- {
- if((r = write(fd, buf, len)) < 0)
- return -1;
- len -= r;
- buf += r;
- done += r;
- } while(len > 0);
-
- return done;
-cp
-}
-
-int xrecv(conn_list_t *cl, void *packet)
-{
- vpn_packet_t vp;
- int lenin;
-cp
- do_decrypt((real_packet_t*)packet, &vp, cl->key);
- add_mac_addresses(&vp);
-
- if((lenin = write_n(tap_fd, &vp, vp.len + 2)) < 0)
- syslog(LOG_ERR, "Can't write to tap device: %m");
- else
- total_tap_out += lenin;
-cp
- return 0;
-}
-
-/*
- add the given packet of size s to the
- queue q, be it the send or receive queue
-*/
-void add_queue(packet_queue_t **q, void *packet, size_t s)
-{
- queue_element_t *e, *p;
-cp
- if(debug_lvl > 3)
- syslog(LOG_DEBUG, "packet to queue: %d", s);
-
- e = xmalloc(sizeof(queue_element_t));
- e->packet = xmalloc(s);
- memcpy(e->packet, packet, s);
- if(!*q)
- {
- *q = xmalloc(sizeof(packet_queue_t));
- (*q)->head = (*q)->tail = NULL;
- }
-
- e->next = NULL;
-
- if((*q)->tail != NULL)
- (*q)->tail->next = e;
-
- (*q)->tail = e;
-
- if((*q)->head == NULL)
- (*q)->head = e;
-cp
-}
-
-/*
- flush a queue by calling function for
- each packet, and removing it when that
- returned a zero exit code
-*/
-void flush_queue(conn_list_t *cl, packet_queue_t *pq,
- int (*function)(conn_list_t*,void*))
-{
- queue_element_t *p, *prev = NULL, *next = NULL;
-cp
- for(p = pq->head; p != NULL; )
- {
- next = p->next;