real_packet_t rp;
cp
do_encrypt((vpn_packet_t*)packet, &rp, cl->key);
- rp.from = myself->vpn_ip;
+ rp.from = htonl(myself->vpn_ip);
+ rp.data->len = htons(rp.data->len);
+ rp.len = htons(rp.data->len);
if(debug_lvl > 3)
- syslog(LOG_ERR, "Sent %d bytes to %lx", rp.len, cl->vpn_ip);
+ syslog(LOG_ERR, "Sent %d bytes to %lx", ntohs(rp.len), cl->vpn_ip);
- if((r = send(cl->socket, (char*)&rp, rp.len, 0)) < 0)
+ if((r = send(cl->socket, (char*)&rp, ntohs(rp.len), 0)) < 0)
{
syslog(LOG_ERR, "Error sending data: %m");
return -1;
vpn_packet_t vp;
int lenin;
cp
+ packet->data->len = ntohs(packet->data->len);
+ packet->len = ntohs(packet->len);
+ packet->from = ntohl(packet->from);
+
do_decrypt((real_packet_t*)packet, &vp, cl->key);
add_mac_addresses(&vp);
for(;;)
{
- p=0;
+ cl->reqlen = 0;
for(i = oldlen; i < cl->buflen; i++)
{
if(cl->buffer[i] == '\n')
{
- cl->buffer[i] = 0; /* turn end-of-line into end-of-string */
- p = i + 1;
+ cl->buffer[i] = 0; /* replace end-of-line by end-of-string so we can use sscanf */
+ cl->reqlen = i + 1;
break;
}
}
- if(p)
+ if(cl->reqlen)
{
if(sscanf(cl->buffer, "%d", &request) == 1)
{
syslog(LOG_ERR, "Bogus data received: %s", cl->buffer);
}
- cl->buflen -= p;
- memmove(cl->buffer, cl->buffer + p, cl->buflen);
+ cl->buflen -= cl->reqlen;
+ memmove(cl->buffer, cl->buffer + cl->reqlen, cl->buflen);
oldlen = 0;
}
else