1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2024-12-29 04:50:03 +01:00

tools/zep_dispatch: uncrustify

This commit is contained in:
Benjamin Valentin 2021-07-06 18:29:25 +02:00
parent aa3dfd9b88
commit c81e4d3a2c
2 changed files with 31 additions and 15 deletions

View File

@ -41,14 +41,16 @@ static void _send_flat(void *ctx, void *buffer, size_t len,
/* send packet to all other clients */
bool known_node = false;
list_node_t *prev = head;
for (list_node_t* n = head->next; n; n = n->next) {
for (list_node_t *n = head->next; n; n = n->next) {
struct sockaddr_in6 *addr = &container_of(n, zep_client_t, node)->addr;
/* don't echo packet back to sender */
if (memcmp(src_addr, addr, sizeof(*addr)) == 0) {
known_node = true;
/* remove client if sending fails */
} else if (sendto(sock, buffer, len, 0, (struct sockaddr *)addr, sizeof(*addr)) < 0) {
/* remove client if sending fails */
}
else if (sendto(sock, buffer, len, 0, (struct sockaddr *)addr, sizeof(*addr)) < 0) {
inet_ntop(AF_INET6, &addr->sin6_addr, addr_str, INET6_ADDRSTRLEN);
printf("removing [%s]:%d\n", addr_str, ntohs(addr->sin6_port));
prev->next = n->next;
@ -92,7 +94,7 @@ static void dispatch_loop(int sock, dispatch_cb_t dispatch, void *ctx)
/* receive incoming packet */
ssize_t bytes_in = recvfrom(sock, buffer, sizeof(buffer), 0,
(struct sockaddr*)&src_addr, &addr_len);
(struct sockaddr *)&src_addr, &addr_len);
if (bytes_in <= 0 || addr_len != sizeof(src_addr)) {
continue;
@ -112,7 +114,8 @@ static void _info_handler(int signal)
if (topology_print(graphviz_file, &topology)) {
fprintf(stderr, "can't open %s\n", graphviz_file);
} else {
}
else {
printf("graph written to %s\n", graphviz_file);
}
}
@ -172,7 +175,8 @@ int main(int argc, char **argv)
return -1;
}
topology.flat = false;
} else {
}
else {
topology.flat = true;
}
@ -190,6 +194,7 @@ int main(int argc, char **argv)
struct addrinfo *server_addr;
int res = getaddrinfo(argv[0], argv[1],
&hint, &server_addr);
if (res != 0) {
perror("getaddrinfo()");
exit(1);
@ -197,6 +202,7 @@ int main(int argc, char **argv)
int sock = socket(server_addr->ai_family, server_addr->ai_socktype,
server_addr->ai_protocol);
if (sock < 0) {
perror("socket() failed");
exit(1);
@ -211,7 +217,8 @@ int main(int argc, char **argv)
if (topology.flat) {
dispatch_loop(sock, _send_flat, &topology.nodes);
} else {
}
else {
dispatch_loop(sock, _send_topology, &topology);
}

View File

@ -128,7 +128,8 @@ int topology_print(const char *file, const topology_t *t)
if (strcmp(file, "-") == 0) {
out = stdout;
} else {
}
else {
out = fopen(file, "w");
}
@ -151,9 +152,9 @@ int topology_print(const char *file, const topology_t *t)
for (list_node_t *edge = t->edges.next; edge; edge = edge->next) {
struct edge *super = container_of(edge, struct edge, next);
fprintf(out, "\t%s -> %s [ label = \"%.2f\" ]\n",
super->a->name, super->b->name, super->weight_a_b);
super->a->name, super->b->name, super->weight_a_b);
fprintf(out, "\t%s -> %s [ label = \"%.2f\" ]\n",
super->b->name, super->a->name, super->weight_b_a);
super->b->name, super->a->name, super->weight_b_a);
}
fprintf(out, "}\n");
@ -168,11 +169,13 @@ int topology_print(const char *file, const topology_t *t)
int topology_parse(const char *file, topology_t *out)
{
FILE *in;
memset(out, 0, sizeof(*out));
if (strcmp(file, "-") == 0) {
in = stdin;
} else {
}
else {
in = fopen(file, "r");
}
@ -182,6 +185,7 @@ int topology_parse(const char *file, topology_t *out)
char *line = NULL;
size_t line_len = 0;
while (getline(&line, &line_len, in) > 0) {
_parse_line(line, &out->nodes, &out->edges);
}
@ -211,15 +215,20 @@ void topology_send(const topology_t *t, int sock,
return;
}
zep_set_lqi(buffer, super->weight_a_b * 0xFF);
sendto(sock, buffer, len, 0, (struct sockaddr*)&super->b->addr, sizeof(super->b->addr));
} else if ((mac_src_len == super->a->mac_len) &&
(memcmp(super->b->mac, mac_src, mac_src_len) == 0)) {
sendto(sock, buffer, len, 0,
(struct sockaddr *)&super->b->addr,
sizeof(super->b->addr));
}
else if ((mac_src_len == super->a->mac_len) &&
(memcmp(super->b->mac, mac_src, mac_src_len) == 0)) {
/* packet loss */
if (random() > super->weight_b_a * RAND_MAX) {
return;
}
zep_set_lqi(buffer, super->weight_b_a * 0xFF);
sendto(sock, buffer, len, 0, (struct sockaddr*)&super->a->addr, sizeof(super->a->addr));
sendto(sock, buffer, len, 0,
(struct sockaddr *)&super->a->addr,
sizeof(super->a->addr));
}
}
}