Cleanups:

- Changed recv/send calls into read/write calls for streams
- Made all sizeof() functions use a variable name instead of type
This commit is contained in:
Guus Sliepen 2000-04-26 17:42:55 +00:00
parent fca84d8a7d
commit 44f9449888
5 changed files with 36 additions and 35 deletions

View file

@ -71,7 +71,7 @@ add_config_val(config_t **cfg, int argtype, char *val)
config_t *p; config_t *p;
char *q; char *q;
p = (config_t*)xmalloc(sizeof(config_t)); p = (config_t*)xmalloc(sizeof(*p));
p->data.val = 0; p->data.val = 0;
switch(argtype) switch(argtype)

View file

@ -318,7 +318,7 @@ cp
continue; continue;
ek = make_shared_key(p->public_key->key); ek = make_shared_key(p->public_key->key);
free_key(p->key); free_key(p->key);
p->key = xmalloc(sizeof(enc_key_t)); p->key = xmalloc(sizeof(*p->key));
p->key->length = strlen(ek); p->key->length = strlen(ek);
p->key->expiry = p->public_key->expiry; p->key->expiry = p->public_key->expiry;
p->key->key = xmalloc(strlen(ek) + 1); p->key->key = xmalloc(strlen(ek) + 1);

View file

@ -157,13 +157,13 @@ cp
if(debug_lvl > 3) if(debug_lvl > 3)
syslog(LOG_DEBUG, "packet to queue: %d", s); syslog(LOG_DEBUG, "packet to queue: %d", s);
e = xmalloc(sizeof(queue_element_t)); e = xmalloc(sizeof(*e));
e->packet = xmalloc(s); e->packet = xmalloc(s);
memcpy(e->packet, packet, s); memcpy(e->packet, packet, s);
if(!*q) if(!*q)
{ {
*q = xmalloc(sizeof(packet_queue_t)); *q = xmalloc(sizeof(**q));
(*q)->head = (*q)->tail = NULL; (*q)->head = (*q)->tail = NULL;
} }
@ -914,7 +914,7 @@ int handle_new_meta_connection(conn_list_t *cl)
{ {
conn_list_t *ncn; conn_list_t *ncn;
struct sockaddr client; struct sockaddr client;
int nfd, len = sizeof(struct sockaddr); int nfd, len = sizeof(client);
cp cp
if((nfd = accept(cl->meta_socket, &client, &len)) < 0) if((nfd = accept(cl->meta_socket, &client, &len)) < 0)
{ {
@ -957,7 +957,7 @@ cp
return -1; return -1;
} }
if((lenin = recv(cl->meta_socket, &tmp, sizeof(tmp), 0)) <= 0) if((lenin = read(cl->meta_socket, &tmp, sizeof(tmp))) <= 0)
{ {
syslog(LOG_ERR, "Receive failed: %m"); syslog(LOG_ERR, "Receive failed: %m");
return -1; return -1;

View file

@ -126,10 +126,10 @@ cp
*/ */
conn_list_t *new_conn_list(void) conn_list_t *new_conn_list(void)
{ {
conn_list_t *p = xmalloc(sizeof(conn_list_t)); conn_list_t *p = xmalloc(sizeof(*p));
cp cp
/* initialise all those stupid pointers at once */ /* initialise all those stupid pointers at once */
memset(p, '\0', sizeof(conn_list_t)); memset(p, '\0', sizeof(*p));
p->nexthop = p; p->nexthop = p;
cp cp
return p; return p;
@ -213,7 +213,7 @@ cp
return NULL; return NULL;
} }
ip = xmalloc(sizeof(ip_mask_t)); ip = xmalloc(sizeof(*ip));
ip->ip = ntohl(*((ip_t*)(h->h_addr_list[0]))); ip->ip = ntohl(*((ip_t*)(h->h_addr_list[0])));
ip->mask = masker ? ~((1 << (32 - masker)) - 1) : 0; ip->mask = masker ? ~((1 << (32 - masker)) - 1) : 0;

View file

@ -23,6 +23,7 @@
#include <string.h> #include <string.h>
#include <syslog.h> #include <syslog.h>
#include <sys/socket.h> #include <sys/socket.h>
#include <unistd.h>
#include <utils.h> #include <utils.h>
#include <xalloc.h> #include <xalloc.h>
@ -41,7 +42,7 @@ cp
syslog(LOG_DEBUG, "Send ACK to %s", cl->hostname); syslog(LOG_DEBUG, "Send ACK to %s", cl->hostname);
syslog(LOG_NOTICE, "Connection with %s activated.", cl->hostname); syslog(LOG_NOTICE, "Connection with %s activated.", cl->hostname);
if((send(cl->meta_socket, &tmp, sizeof(tmp), 0)) < 0) if((write(cl->meta_socket, &tmp, sizeof(tmp))) < 0)
{ {
syslog(LOG_ERR, "send failed: %d:%d: %m", __FILE__, __LINE__); syslog(LOG_ERR, "send failed: %d:%d: %m", __FILE__, __LINE__);
return -1; return -1;
@ -61,7 +62,7 @@ cp
syslog(LOG_DEBUG, "Send TERMREQ(" IP_ADDR_S ") to " IP_ADDR_S, IP_ADDR_V(tmp.vpn_ip), syslog(LOG_DEBUG, "Send TERMREQ(" IP_ADDR_S ") to " IP_ADDR_S, IP_ADDR_V(tmp.vpn_ip),
IP_ADDR_V(cl->vpn_ip)); IP_ADDR_V(cl->vpn_ip));
if((send(cl->meta_socket, &tmp, sizeof(tmp), 0)) < 0) if((write(cl->meta_socket, &tmp, sizeof(tmp))) < 0)
{ {
syslog(LOG_ERR, "send failed: %s:%d: %m", __FILE__, __LINE__); syslog(LOG_ERR, "send failed: %s:%d: %m", __FILE__, __LINE__);
return -1; return -1;
@ -81,7 +82,7 @@ cp
syslog(LOG_DEBUG, "Send TIMEOUT(" IP_ADDR_S ") to " IP_ADDR_S, IP_ADDR_V(tmp.vpn_ip), syslog(LOG_DEBUG, "Send TIMEOUT(" IP_ADDR_S ") to " IP_ADDR_S, IP_ADDR_V(tmp.vpn_ip),
IP_ADDR_V(cl->vpn_ip)); IP_ADDR_V(cl->vpn_ip));
if((send(cl->meta_socket, &tmp, sizeof(tmp), 0)) < 0) if((write(cl->meta_socket, &tmp, sizeof(tmp))) < 0)
{ {
syslog(LOG_ERR, "send failed: %s:%d: %m", __FILE__, __LINE__); syslog(LOG_ERR, "send failed: %s:%d: %m", __FILE__, __LINE__);
return -1; return -1;
@ -101,7 +102,7 @@ cp
syslog(LOG_DEBUG, "Sending delete host %lx to " IP_ADDR_S, syslog(LOG_DEBUG, "Sending delete host %lx to " IP_ADDR_S,
tmp.vpn_ip, IP_ADDR_V(cl->vpn_ip)); tmp.vpn_ip, IP_ADDR_V(cl->vpn_ip));
if((send(cl->meta_socket, (unsigned char*)&tmp, sizeof(del_host_t), 0)) < 0) if((write(cl->meta_socket, &tmp, sizeof(tmp))) < 0)
{ {
syslog(LOG_ERR, "send failed: %s:%d: %m", __FILE__, __LINE__); syslog(LOG_ERR, "send failed: %s:%d: %m", __FILE__, __LINE__);
return -1; return -1;
@ -117,7 +118,7 @@ cp
if(debug_lvl > 3) if(debug_lvl > 3)
syslog(LOG_DEBUG, "pinging " IP_ADDR_S, IP_ADDR_V(cl->vpn_ip)); syslog(LOG_DEBUG, "pinging " IP_ADDR_S, IP_ADDR_V(cl->vpn_ip));
if((send(cl->meta_socket, &tmp, sizeof(tmp), 0)) < 0) if((write(cl->meta_socket, &tmp, sizeof(tmp))) < 0)
{ {
syslog(LOG_ERR, "send failed: %s:%d: %m", __FILE__, __LINE__); syslog(LOG_ERR, "send failed: %s:%d: %m", __FILE__, __LINE__);
return -1; return -1;
@ -130,7 +131,7 @@ int send_pong(conn_list_t *cl)
{ {
unsigned char tmp = PONG; unsigned char tmp = PONG;
cp cp
if((send(cl->meta_socket, &tmp, sizeof(tmp), 0)) < 0) if((write(cl->meta_socket, &tmp, sizeof(tmp))) < 0)
{ {
syslog(LOG_ERR, "send failed: %s:%d: %m", __FILE__, __LINE__); syslog(LOG_ERR, "send failed: %s:%d: %m", __FILE__, __LINE__);
return -1; return -1;
@ -154,7 +155,7 @@ cp
tmp.vpn_ip, tmp.vpn_mask, tmp.real_ip, tmp.portnr, tmp.vpn_ip, tmp.vpn_mask, tmp.real_ip, tmp.portnr,
IP_ADDR_V(cl->vpn_ip)); IP_ADDR_V(cl->vpn_ip));
if((send(cl->meta_socket, (unsigned char*)&tmp, sizeof(add_host_t), 0)) < 0) if((write(cl->meta_socket, &tmp, sizeof(tmp))) < 0)
{ {
syslog(LOG_ERR, "send failed: %s:%d: %m", __FILE__, __LINE__); syslog(LOG_ERR, "send failed: %s:%d: %m", __FILE__, __LINE__);
return -1; return -1;
@ -174,7 +175,7 @@ cp
syslog(LOG_DEBUG, "Sending KEY_CHANGED (%lx) to " IP_ADDR_S, syslog(LOG_DEBUG, "Sending KEY_CHANGED (%lx) to " IP_ADDR_S,
tmp.from, IP_ADDR_V(cl->vpn_ip)); tmp.from, IP_ADDR_V(cl->vpn_ip));
if((send(cl->meta_socket, (unsigned char*)&tmp, sizeof(key_changed_t), 0)) < 0) if((write(cl->meta_socket, &tmp, sizeof(tmp))) < 0)
{ {
syslog(LOG_ERR, "send failed: %s:%d: %m", __FILE__, __LINE__); syslog(LOG_ERR, "send failed: %s:%d: %m", __FILE__, __LINE__);
return -1; return -1;
@ -209,7 +210,7 @@ cp
tmp.protocol, tmp.portnr, IP_ADDR_V(tmp.vpn_ip), IP_ADDR_V(tmp.vpn_mask), tmp.protocol, tmp.portnr, IP_ADDR_V(tmp.vpn_ip), IP_ADDR_V(tmp.vpn_mask),
IP_ADDR_V(cl->real_ip)); IP_ADDR_V(cl->real_ip));
if((send(cl->meta_socket, &tmp, sizeof(tmp), 0)) < 0) if((write(cl->meta_socket, &tmp, sizeof(tmp))) < 0)
{ {
syslog(LOG_ERR, "send failed: %s:%d: %m", __FILE__, __LINE__); syslog(LOG_ERR, "send failed: %s:%d: %m", __FILE__, __LINE__);
return -1; return -1;
@ -229,7 +230,7 @@ cp
syslog(LOG_DEBUG, "Send PASSPHRASE(%hd,...) to " IP_ADDR_S, tmp.len, syslog(LOG_DEBUG, "Send PASSPHRASE(%hd,...) to " IP_ADDR_S, tmp.len,
IP_ADDR_V(cl->vpn_ip)); IP_ADDR_V(cl->vpn_ip));
if((send(cl->meta_socket, &tmp, tmp.len+3, 0)) < 0) if((write(cl->meta_socket, &tmp, tmp.len+3)) < 0)
{ {
syslog(LOG_ERR, "send failed: %s:%d: %m", __FILE__, __LINE__); syslog(LOG_ERR, "send failed: %s:%d: %m", __FILE__, __LINE__);
return -1; return -1;
@ -242,7 +243,7 @@ int send_public_key(conn_list_t *cl)
{ {
public_key_t *tmp; public_key_t *tmp;
cp cp
tmp = (public_key_t*)xmalloc(strlen(my_public_key_base36)+sizeof(public_key_t)); tmp = (public_key_t*)xmalloc(strlen(my_public_key_base36)+sizeof(*tmp));
tmp->type = PUBLIC_KEY; tmp->type = PUBLIC_KEY;
tmp->len = strlen(my_public_key_base36); tmp->len = strlen(my_public_key_base36);
strcpy(&tmp->key, my_public_key_base36); strcpy(&tmp->key, my_public_key_base36);
@ -251,7 +252,7 @@ cp
syslog(LOG_DEBUG, "Send PUBLIC_KEY(%hd,%s) to " IP_ADDR_S, tmp->len, &tmp->key, syslog(LOG_DEBUG, "Send PUBLIC_KEY(%hd,%s) to " IP_ADDR_S, tmp->len, &tmp->key,
IP_ADDR_V(cl->vpn_ip)); IP_ADDR_V(cl->vpn_ip));
if((send(cl->meta_socket, tmp, tmp->len+sizeof(public_key_t), 0)) < 0) if((write(cl->meta_socket, tmp, tmp->len+sizeof(*tmp))) < 0)
{ {
syslog(LOG_ERR, "send failed: %s:%d: %m", __FILE__, __LINE__); syslog(LOG_ERR, "send failed: %s:%d: %m", __FILE__, __LINE__);
return -1; return -1;
@ -264,12 +265,12 @@ int send_calculate(conn_list_t *cl, char *k)
{ {
calculate_t *tmp; calculate_t *tmp;
cp cp
tmp = xmalloc(strlen(k)+sizeof(calculate_t)); tmp = xmalloc(strlen(k)+sizeof(*tmp));
tmp->type = CALCULATE; tmp->type = CALCULATE;
tmp->len = strlen(k); tmp->len = strlen(k);
strcpy(&tmp->key, k); strcpy(&tmp->key, k);
if(send(cl->meta_socket, tmp, tmp->len+4, 0) < 0) if((write(cl->meta_socket, tmp, tmp->len+sizeof(*tmp))) < 0)
{ {
syslog(LOG_ERR, "send failed: %s:%d: %m", __FILE__, __LINE__); syslog(LOG_ERR, "send failed: %s:%d: %m", __FILE__, __LINE__);
return -1; return -1;
@ -283,7 +284,7 @@ int send_key_request(ip_t to)
key_req_t *tmp; key_req_t *tmp;
conn_list_t *fw; conn_list_t *fw;
cp cp
tmp = xmalloc(sizeof(key_req_t)); tmp = xmalloc(sizeof(*tmp));
tmp->type = REQ_KEY; tmp->type = REQ_KEY;
tmp->to = to; tmp->to = to;
tmp->from = myself->vpn_ip; tmp->from = myself->vpn_ip;
@ -300,7 +301,7 @@ cp
if(debug_lvl > 2) if(debug_lvl > 2)
syslog(LOG_DEBUG, "Sending out request for public key to " IP_ADDR_S, syslog(LOG_DEBUG, "Sending out request for public key to " IP_ADDR_S,
IP_ADDR_V(fw->nexthop->vpn_ip)); IP_ADDR_V(fw->nexthop->vpn_ip));
if(send(fw->nexthop->meta_socket, tmp, sizeof(key_req_t), 0) < 0) if(write(fw->nexthop->meta_socket, tmp, sizeof(*tmp)) < 0)
{ {
syslog(LOG_ERR, "send failed: %s:%d: %m", __FILE__, __LINE__); syslog(LOG_ERR, "send failed: %s:%d: %m", __FILE__, __LINE__);
return -1; return -1;
@ -315,7 +316,7 @@ int send_key_answer(conn_list_t *cl, ip_t to)
key_req_t *tmp; key_req_t *tmp;
conn_list_t *fw; conn_list_t *fw;
cp cp
tmp = xmalloc(sizeof(key_req_t)+strlen(my_public_key_base36)); tmp = xmalloc(sizeof(*tmp)+strlen(my_public_key_base36));
tmp->type = ANS_KEY; tmp->type = ANS_KEY;
tmp->to = to; tmp->to = to;
tmp->from = myself->vpn_ip; tmp->from = myself->vpn_ip;
@ -335,7 +336,7 @@ cp
if(debug_lvl > 2) if(debug_lvl > 2)
syslog(LOG_DEBUG, "Sending public key to " IP_ADDR_S, syslog(LOG_DEBUG, "Sending public key to " IP_ADDR_S,
IP_ADDR_V(fw->nexthop->vpn_ip)); IP_ADDR_V(fw->nexthop->vpn_ip));
if(send(fw->nexthop->meta_socket, tmp, sizeof(key_req_t)+tmp->len, 0) < 0) if(write(fw->nexthop->meta_socket, tmp, sizeof(*tmp)+tmp->len) < 0)
{ {
syslog(LOG_ERR, "send failed: %s:%d: %m", __FILE__, __LINE__); syslog(LOG_ERR, "send failed: %s:%d: %m", __FILE__, __LINE__);
return -1; return -1;
@ -606,11 +607,11 @@ cp
again, i'm cheating here. see the comment in ack_h. again, i'm cheating here. see the comment in ack_h.
Naughty zarq! Now you see what cheating will get you... [GS] Naughty zarq! Now you see what cheating will get you... [GS]
*/ */
if(len > sizeof(add_host_t)) /* Another ADD_HOST follows */ if(len > sizeof(*tmp)) /* Another ADD_HOST follows */
{ {
if(request_handlers[d[sizeof(add_host_t)]] == NULL) if(request_handlers[d[sizeof(*tmp)]] == NULL)
syslog(LOG_ERR, "Unknown request %d.", d[sizeof(add_host_t)]); syslog(LOG_ERR, "Unknown request %d.", d[sizeof(*tmp)]);
if(request_handlers[d[sizeof(add_host_t)]](cl, d + sizeof(add_host_t), len - sizeof(add_host_t)) < 0) if(request_handlers[d[sizeof(*tmp)]](cl, d + sizeof(*tmp), len - sizeof(*tmp)) < 0)
return -1; return -1;
} }
cp cp
@ -644,7 +645,7 @@ cp
if(debug_lvl > 3) if(debug_lvl > 3)
syslog(LOG_DEBUG, "Forwarding request for public key to " IP_ADDR_S, syslog(LOG_DEBUG, "Forwarding request for public key to " IP_ADDR_S,
IP_ADDR_V(fw->nexthop->vpn_ip)); IP_ADDR_V(fw->nexthop->vpn_ip));
if(send(fw->nexthop->meta_socket, tmp, sizeof(key_req_t), 0) < 0) if(write(fw->nexthop->meta_socket, tmp, sizeof(*tmp)) < 0)
{ {
syslog(LOG_ERR, "send failed: %s:%d: %m", __FILE__, __LINE__); syslog(LOG_ERR, "send failed: %s:%d: %m", __FILE__, __LINE__);
return -1; return -1;
@ -659,7 +660,7 @@ void set_keys(conn_list_t *cl, key_req_t *k)
cp cp
if(!cl->public_key) if(!cl->public_key)
{ {
cl->public_key = xmalloc(sizeof(enc_key_t)); cl->public_key = xmalloc(sizeof(*cl->key));
cl->public_key->key = NULL; cl->public_key->key = NULL;
} }
if(cl->public_key->key) if(cl->public_key->key)
@ -672,7 +673,7 @@ cp
ek = make_shared_key(&(k->key)); ek = make_shared_key(&(k->key));
if(!cl->key) if(!cl->key)
{ {
cl->key = xmalloc(sizeof(enc_key_t)); cl->key = xmalloc(sizeof(*cl->key));
cl->key->key = NULL; cl->key->key = NULL;
} }
if(cl->key->key) if(cl->key->key)
@ -725,7 +726,7 @@ cp
if(debug_lvl > 2) if(debug_lvl > 2)
syslog(LOG_DEBUG, "Forwarding public key to " IP_ADDR_S, syslog(LOG_DEBUG, "Forwarding public key to " IP_ADDR_S,
IP_ADDR_V(fw->nexthop->vpn_ip)); IP_ADDR_V(fw->nexthop->vpn_ip));
if(send(fw->nexthop->meta_socket, tmp, sizeof(key_req_t)+tmp->len, 0) < 0) if(write(fw->nexthop->meta_socket, tmp, sizeof(*tmp)+tmp->len) < 0)
{ {
syslog(LOG_ERR, "send failed: %s:%d: %m", __FILE__, __LINE__); syslog(LOG_ERR, "send failed: %s:%d: %m", __FILE__, __LINE__);
return -1; return -1;