diff --git a/adsbus/exec.c b/adsbus/exec.c index b239320..f5826ed 100644 --- a/adsbus/exec.c +++ b/adsbus/exec.c @@ -68,7 +68,7 @@ static void exec_del(struct exec *exec) { } static void exec_close_handler(struct peer *peer) { - struct exec *exec = (struct exec *) peer; + struct exec *exec = container_of(peer, struct exec, peer); exec_harvest(exec); uint32_t delay = wakeup_get_retry_delay_ms(1); LOG(exec->id, "Will retry in %ds", delay / 1000); @@ -159,7 +159,7 @@ static void exec_spawn(struct exec *exec) { } static void exec_spawn_wrapper(struct peer *peer) { - struct exec *exec = (struct exec *) peer; + struct exec *exec = container_of(peer, struct exec, peer); exec_spawn(exec); } diff --git a/adsbus/file.c b/adsbus/file.c index dd4d2ef..89f1782 100644 --- a/adsbus/file.c +++ b/adsbus/file.c @@ -76,7 +76,7 @@ static void file_retry(struct file *file) { } static void file_handle_close(struct peer *peer) { - struct file *file = (struct file *) peer; + struct file *file = container_of(peer, struct file, peer); LOG(file->id, "File closed: %s", file->path); if (file->retry) { @@ -106,7 +106,7 @@ static void file_open(struct file *file) { } static void file_open_wrapper(struct peer *peer) { - struct file *file = (struct file *) peer; + struct file *file = container_of(peer, struct file, peer); file_open(file); } diff --git a/adsbus/incoming.c b/adsbus/incoming.c index db243bd..60e8cf5 100644 --- a/adsbus/incoming.c +++ b/adsbus/incoming.c @@ -48,7 +48,7 @@ static void incoming_retry(struct incoming *incoming) { } static void incoming_handler(struct peer *peer) { - struct incoming *incoming = (struct incoming *) peer; + struct incoming *incoming = container_of(peer, struct incoming, peer); struct sockaddr peer_addr, local_addr; socklen_t peer_addrlen = sizeof(peer_addr), local_addrlen = sizeof(local_addr); @@ -87,7 +87,7 @@ static void incoming_del(struct incoming *incoming) { } static void incoming_listen(struct peer *peer) { - struct incoming *incoming = (struct incoming *) peer; + struct incoming *incoming = container_of(peer, struct incoming, peer); struct addrinfo *addrs; int err = resolve_result(peer, &addrs); @@ -142,7 +142,7 @@ static void incoming_resolve(struct incoming *incoming) { } static void incoming_resolve_wrapper(struct peer *peer) { - incoming_resolve((struct incoming *) peer); + incoming_resolve(container_of(peer, struct incoming, peer)); } static bool incoming_add(const char *host_port, struct flow *flow, void *passthrough) { diff --git a/adsbus/outgoing.c b/adsbus/outgoing.c index 7188a29..2df996a 100644 --- a/adsbus/outgoing.c +++ b/adsbus/outgoing.c @@ -6,7 +6,6 @@ #include #include #include -#include #include "buf.h" #include "flow.h" @@ -73,7 +72,7 @@ static void outgoing_connect_next(struct outgoing *outgoing) { } static void outgoing_connect_handler(struct peer *peer) { - struct outgoing *outgoing = (struct outgoing *) peer; + struct outgoing *outgoing = container_of(peer, struct outgoing, peer); peer_epoll_del(&outgoing->peer); @@ -84,7 +83,7 @@ static void outgoing_connect_handler(struct peer *peer) { } static void outgoing_disconnect_handler(struct peer *peer) { - struct outgoing *outgoing = (struct outgoing *) peer; + struct outgoing *outgoing = container_of(peer, struct outgoing, peer); LOG(outgoing->id, "Peer disconnected; reconnecting..."); outgoing_retry(outgoing); } @@ -121,7 +120,7 @@ static void outgoing_connect_result(struct outgoing *outgoing, int result) { } static void outgoing_resolve_handler(struct peer *peer) { - struct outgoing *outgoing = (struct outgoing *) peer; + struct outgoing *outgoing = container_of(peer, struct outgoing, peer); int err = resolve_result(peer, &outgoing->addrs); if (err) { LOG(outgoing->id, "Failed to resolve %s/%s: %s", outgoing->node, outgoing->service, gai_strerror(err)); @@ -139,7 +138,7 @@ static void outgoing_resolve(struct outgoing *outgoing) { } static void outgoing_resolve_wrapper(struct peer *peer) { - outgoing_resolve((struct outgoing *) peer); + outgoing_resolve(container_of(peer, struct outgoing, peer)); } static void outgoing_del(struct outgoing *outgoing) { diff --git a/adsbus/receive.c b/adsbus/receive.c index 308672e..189e6b6 100644 --- a/adsbus/receive.c +++ b/adsbus/receive.c @@ -4,7 +4,6 @@ #include #include #include -#include #include "airspy_adsb.h" #include "beast.h" @@ -115,7 +114,7 @@ static void receive_del(struct receive *receive) { } static void receive_read(struct peer *peer) { - struct receive *receive = (struct receive *) peer; + struct receive *receive = container_of(peer, struct receive, peer); if (buf_fill(&receive->buf, receive->peer.fd) <= 0) { receive_del(receive); diff --git a/adsbus/send.c b/adsbus/send.c index ffd49f4..77b0732 100644 --- a/adsbus/send.c +++ b/adsbus/send.c @@ -99,7 +99,7 @@ static void send_del(struct send *send) { } static void send_del_wrapper(struct peer *peer) { - send_del((struct send *) peer); + send_del(container_of(peer, struct send, peer)); } static void send_new(int fd, void *passthrough, struct peer *on_close) { diff --git a/adsbus/send_receive.c b/adsbus/send_receive.c index 15af572..6e72b23 100644 --- a/adsbus/send_receive.c +++ b/adsbus/send_receive.c @@ -35,7 +35,7 @@ static void send_receive_del(struct send_receive *send_receive) { } static void send_receive_on_close(struct peer *peer) { - struct send_receive *send_receive = (struct send_receive *) peer; + struct send_receive *send_receive = container_of(peer, struct send_receive, peer); if (!--(send_receive->ref_count)) { send_receive_del(send_receive);