Code cleanup

This commit is contained in:
angt
2016-04-30 12:53:26 +00:00
parent a26e2af038
commit b4b687bd4c

52
mud.c
View File

@@ -108,10 +108,10 @@ struct path {
struct path *next; struct path *next;
}; };
struct sock { struct iface {
unsigned index; unsigned index;
char name[IF_NAMESIZE]; char name[IF_NAMESIZE];
struct sock *next; struct iface *next;
}; };
struct packet { struct packet {
@@ -143,7 +143,7 @@ struct mud {
uint64_t time_tolerance; uint64_t time_tolerance;
struct queue tx; struct queue tx;
struct queue rx; struct queue rx;
struct sock *sock; struct iface *iface;
struct path *path; struct path *path;
struct crypto crypto; struct crypto crypto;
}; };
@@ -317,16 +317,16 @@ int mud_cmp_addr (struct sockaddr *a, struct sockaddr *b)
} }
static static
struct sock *mud_get_sock (struct mud *mud, unsigned index) struct iface *mud_get_iface (struct mud *mud, unsigned index)
{ {
struct sock *sock; struct iface *iface;
for (sock = mud->sock; sock; sock = sock->next) { for (iface = mud->iface; iface; iface = iface->next) {
if (sock->index == index) if (iface->index == index)
break; break;
} }
return sock; return iface;
} }
static static
@@ -403,9 +403,9 @@ struct path *mud_new_path (struct mud *mud, unsigned index, struct sockaddr *add
if (path) if (path)
return path; return path;
struct sock *sock = mud_get_sock(mud, index); struct iface *iface = mud_get_iface(mud, index);
if (!sock) if (!iface)
return NULL; return NULL;
path = calloc(1, sizeof(struct path)); path = calloc(1, sizeof(struct path));
@@ -429,7 +429,7 @@ struct path *mud_new_path (struct mud *mud, unsigned index, struct sockaddr *add
if (ifa_addr->sa_family != addr->sa_family) if (ifa_addr->sa_family != addr->sa_family)
continue; continue;
if (strncmp(sock->name, ifa->ifa_name, sizeof(sock->name))) if (strncmp(iface->name, ifa->ifa_name, sizeof(iface->name)))
continue; continue;
mud_set_path(path, index, addr, ifa_addr); mud_set_path(path, index, addr, ifa_addr);
@@ -460,13 +460,13 @@ int mud_peer (struct mud *mud, const char *host, const char *port)
return -1; return -1;
for (p = ai; p; p = p->ai_next) { for (p = ai; p; p = p->ai_next) {
struct sock *sock; struct iface *iface;
if (!p->ai_addr) if (!p->ai_addr)
continue; continue;
for (sock = mud->sock; sock; sock = sock->next) { for (iface = mud->iface; iface; iface = iface->next) {
struct path *path = mud_new_path(mud, sock->index, p->ai_addr); struct path *path = mud_new_path(mud, iface->index, p->ai_addr);
if (!path) if (!path)
continue; continue;
@@ -495,20 +495,20 @@ int mud_bind (struct mud *mud, const char *name)
if (!index) if (!index)
return -1; return -1;
struct sock *sock = mud_get_sock(mud, index); struct iface *iface = mud_get_iface(mud, index);
if (sock) if (iface)
return 0; return 0;
sock = calloc(1, sizeof(struct sock)); iface = calloc(1, sizeof(struct iface));
if (!sock) if (!iface)
return -1; return -1;
memcpy(sock->name, name, len+1); memcpy(iface->name, name, len+1);
sock->index = index; iface->index = index;
sock->next = mud->sock; iface->next = mud->iface;
mud->sock = sock; mud->iface = iface;
struct path *path; struct path *path;
@@ -672,10 +672,10 @@ void mud_delete (struct mud *mud)
free(mud->tx.packet); free(mud->tx.packet);
free(mud->rx.packet); free(mud->rx.packet);
while (mud->sock) { while (mud->iface) {
struct sock *sock = mud->sock; struct iface *iface = mud->iface;
mud->sock = sock->next; mud->iface = iface->next;
free(sock); free(iface);
} }
while (mud->path) { while (mud->path) {