+int tcprecv(conn_list_t *cl, real_packet_t *rp)
+{
+ vpn_packet_t vp;
+ int lenin;
+ conn_list_t *f;
+cp
+ rp->data.len = ntohs(rp->data.len);
+ rp->len = ntohs(rp->len);
+ rp->from = ntohl(rp->from);
+
+ total_socket_in += rp->len;
+
+ if(rp->len >= 0)
+ {
+ f = lookup_conn(rp->from);
+ if(!f)
+ {
+ syslog(LOG_ERR, _("Got packet from %s (%s) with unknown origin %d.%d.%d.%d?"),
+ cl->vpn_hostname, cl->real_hostname, IP_ADDR_V(rp->from));
+ return -1;
+ }
+
+ if(f->status.validkey)
+ {
+ do_decrypt(rp, &vp, cl->key);
+ add_mac_addresses(&vp);
+
+ if(debug_lvl > 3)
+ syslog(LOG_ERR, _("Receiving packet of %d bytes from %s (%s)"),
+ rp->len, cl->vpn_hostname, cl->real_hostname);
+
+ if((lenin = write(tap_fd, &vp, vp.len + sizeof(vp.len))) < 0)
+ syslog(LOG_ERR, _("Can't write to tap device: %m"));
+ else
+ total_tap_out += lenin;
+ }
+ else
+ {
+ /* Can we add to queue? */
+ if(!cl->status.waitingforkey)
+ send_key_request(rp->from);
+ }
+
+ if(my_key_expiry <= time(NULL))
+ regenerate_keys();
+ }
+
+ cl->want_ping = 0;
+ cl->last_ping_time = time(NULL);
+cp
+ return 0;
+}
+