- unsigned char tmp[MAXSIZE];
-
- memcpy(tmp, p->data, p->len);
- p->len -= 12;
- memcpy(p->data, &tmp[12], p->len);
-}
-
-/*
- reassemble MAC addresses
-*/
-void add_mac_addresses(vpn_packet_t *p)
-{
- unsigned char tmp[MAXSIZE];
-
- memcpy(&tmp[12], p->data, p->len);
- p->len += 12;
- tmp[0] = tmp[6] = 0xfe;
- tmp[1] = tmp[7] = 0xfd;
- *((ip_t*)(&tmp[2])) = (ip_t)(htonl(myself->vpn_ip));
- *((ip_t*)(&tmp[8])) = *((ip_t*)(&tmp[26]));
- memcpy(p->data, &tmp[0], p->len);
-}
-
-int xsend(conn_list_t *cl, void *packet)
-{
- int r;
- real_packet_t rp;
-
- do_encrypt((vpn_packet_t*)packet, &rp, cl->key);
- rp.from = myself->vpn_ip;
-
- if(debug_lvl > 3)
- syslog(LOG_ERR, "Sent %d bytes to %lx", rp.len, cl->vpn_ip);
-
- if((r = send(cl->socket, (char*)&rp, rp.len, 0)) < 0)
- {
- syslog(LOG_ERR, "Error sending data: %m");
- return -1;
- }
-
- total_socket_out += r;
-
- 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;
-
- do
- {
- if((r = write(fd, buf, len)) < 0)
- return -1;
- len -= r;
- buf += r;
- done += r;
- } while(len > 0);
-
- return done;
-}
-
-int xrecv(conn_list_t *cl, void *packet)
-{
- vpn_packet_t vp;
- int lenin;
-
- 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;
-
- 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;