diff --git a/agentf.c b/agentf.c index 2c869fe5..3b3407fa 100644 --- a/agentf.c +++ b/agentf.c @@ -174,7 +174,7 @@ Channel *agentf_new(SshChannel *c) static void agentf_free(Channel *chan) { assert(chan->vt == &agentf_channelvt); - agentf *af = FROMFIELD(chan, agentf, chan); + agentf *af = container_of(chan, agentf, chan); if (af->pending) agent_cancel_query(af->pending); @@ -186,7 +186,7 @@ static int agentf_send(Channel *chan, int is_stderr, const void *data, int length) { assert(chan->vt == &agentf_channelvt); - agentf *af = FROMFIELD(chan, agentf, chan); + agentf *af = container_of(chan, agentf, chan); bufchain_add(&af->inbuffer, data, length); agentf_try_forward(af); @@ -204,7 +204,7 @@ static int agentf_send(Channel *chan, int is_stderr, static void agentf_send_eof(Channel *chan) { assert(chan->vt == &agentf_channelvt); - agentf *af = FROMFIELD(chan, agentf, chan); + agentf *af = container_of(chan, agentf, chan); af->rcvd_eof = TRUE; @@ -222,7 +222,7 @@ static char *agentf_log_close_msg(Channel *chan) static void agentf_set_input_wanted(Channel *chan, int wanted) { assert(chan->vt == &agentf_channelvt); - agentf *af = FROMFIELD(chan, agentf, chan); + agentf *af = container_of(chan, agentf, chan); af->input_wanted = wanted; diff --git a/defs.h b/defs.h index 776ab888..0d98b70c 100644 --- a/defs.h +++ b/defs.h @@ -97,7 +97,7 @@ typedef struct PacketProtocolLayer PacketProtocolLayer; /* Return a pointer to the object of structure type 'type' whose field * with name 'field' is pointed at by 'object'. */ -#define FROMFIELD(object, type, field) \ +#define container_of(object, type, field) \ TYPECHECK(object == &((type *)0)->field, \ ((type *)(((char *)(object)) - offsetof(type, field)))) diff --git a/errsock.c b/errsock.c index 89c40a1d..d4878a9a 100644 --- a/errsock.c +++ b/errsock.c @@ -18,7 +18,7 @@ typedef struct { static Plug *sk_error_plug(Socket *s, Plug *p) { - ErrorSocket *es = FROMFIELD(s, ErrorSocket, sock); + ErrorSocket *es = container_of(s, ErrorSocket, sock); Plug *ret = es->plug; if (p) es->plug = p; @@ -27,7 +27,7 @@ static Plug *sk_error_plug(Socket *s, Plug *p) static void sk_error_close(Socket *s) { - ErrorSocket *es = FROMFIELD(s, ErrorSocket, sock); + ErrorSocket *es = container_of(s, ErrorSocket, sock); sfree(es->error); sfree(es); @@ -35,7 +35,7 @@ static void sk_error_close(Socket *s) static const char *sk_error_socket_error(Socket *s) { - ErrorSocket *es = FROMFIELD(s, ErrorSocket, sock); + ErrorSocket *es = container_of(s, ErrorSocket, sock); return es->error; } diff --git a/import.c b/import.c index 98cf8010..66be77cb 100644 --- a/import.c +++ b/import.c @@ -916,7 +916,7 @@ int openssh_pem_write(const Filename *filename, struct ssh2_userkey *key, ssh_key_alg(key->key) == &ssh_ecdsa_nistp384 || ssh_key_alg(key->key) == &ssh_ecdsa_nistp521) { const unsigned char *oid; - struct ec_key *ec = FROMFIELD(key->key, struct ec_key, sshk); + struct ec_key *ec = container_of(key->key, struct ec_key, sshk); int oidlen; int pointlen; strbuf *seq, *sub; diff --git a/misc.c b/misc.c index efb83579..f24a6e36 100644 --- a/misc.c +++ b/misc.c @@ -493,7 +493,7 @@ struct strbuf_impl { void *strbuf_append(strbuf *buf_o, size_t len) { - struct strbuf_impl *buf = FROMFIELD(buf_o, struct strbuf_impl, visible); + struct strbuf_impl *buf = container_of(buf_o, struct strbuf_impl, visible); char *toret; if (buf->size < buf->visible.len + len + 1) { buf->size = (buf->visible.len + len + 1) * 5 / 4 + 512; @@ -524,7 +524,7 @@ strbuf *strbuf_new(void) } void strbuf_free(strbuf *buf_o) { - struct strbuf_impl *buf = FROMFIELD(buf_o, struct strbuf_impl, visible); + struct strbuf_impl *buf = container_of(buf_o, struct strbuf_impl, visible); if (buf->visible.s) { smemclr(buf->visible.s, buf->size); sfree(buf->visible.s); @@ -533,14 +533,14 @@ void strbuf_free(strbuf *buf_o) } char *strbuf_to_str(strbuf *buf_o) { - struct strbuf_impl *buf = FROMFIELD(buf_o, struct strbuf_impl, visible); + struct strbuf_impl *buf = container_of(buf_o, struct strbuf_impl, visible); char *ret = buf->visible.s; sfree(buf); return ret; } void strbuf_catfv(strbuf *buf_o, const char *fmt, va_list ap) { - struct strbuf_impl *buf = FROMFIELD(buf_o, struct strbuf_impl, visible); + struct strbuf_impl *buf = container_of(buf_o, struct strbuf_impl, visible); STRBUF_SET_PTR(buf, dupvprintf_inner(buf->visible.s, buf->visible.len, &buf->size, fmt, ap)); buf->visible.len += strlen(buf->visible.s + buf->visible.len); @@ -561,7 +561,7 @@ strbuf *strbuf_new_for_agent_query(void) } void strbuf_finalise_agent_query(strbuf *buf_o) { - struct strbuf_impl *buf = FROMFIELD(buf_o, struct strbuf_impl, visible); + struct strbuf_impl *buf = container_of(buf_o, struct strbuf_impl, visible); assert(buf->visible.len >= 5); PUT_32BIT_MSB_FIRST(buf->visible.u, buf->visible.len - 4); } diff --git a/pageant.c b/pageant.c index 438fbe58..5f22127e 100644 --- a/pageant.c +++ b/pageant.c @@ -713,7 +713,7 @@ struct pageant_conn_state { static void pageant_conn_closing(Plug *plug, const char *error_msg, int error_code, int calling_back) { - struct pageant_conn_state *pc = FROMFIELD( + struct pageant_conn_state *pc = container_of( plug, struct pageant_conn_state, plug); if (error_msg) plog(pc->logctx, pc->logfn, "%p: error: %s", pc, error_msg); @@ -725,7 +725,7 @@ static void pageant_conn_closing(Plug *plug, const char *error_msg, static void pageant_conn_sent(Plug *plug, int bufsize) { - /* struct pageant_conn_state *pc = FROMFIELD( + /* struct pageant_conn_state *pc = container_of( plug, struct pageant_conn_state, plug); */ /* @@ -747,7 +747,7 @@ static void pageant_conn_log(void *logctx, const char *fmt, va_list ap) static void pageant_conn_receive(Plug *plug, int urgent, char *data, int len) { - struct pageant_conn_state *pc = FROMFIELD( + struct pageant_conn_state *pc = container_of( plug, struct pageant_conn_state, plug); char c; @@ -807,7 +807,7 @@ struct pageant_listen_state { static void pageant_listen_closing(Plug *plug, const char *error_msg, int error_code, int calling_back) { - struct pageant_listen_state *pl = FROMFIELD( + struct pageant_listen_state *pl = container_of( plug, struct pageant_listen_state, plug); if (error_msg) plog(pl->logctx, pl->logfn, "listening socket: error: %s", error_msg); @@ -826,7 +826,7 @@ static const PlugVtable pageant_connection_plugvt = { static int pageant_listen_accepting(Plug *plug, accept_fn_t constructor, accept_ctx_t ctx) { - struct pageant_listen_state *pl = FROMFIELD( + struct pageant_listen_state *pl = container_of( plug, struct pageant_listen_state, plug); struct pageant_conn_state *pc; const char *err; diff --git a/portfwd.c b/portfwd.c index 40c09c7b..8ae9e80c 100644 --- a/portfwd.c +++ b/portfwd.c @@ -124,7 +124,8 @@ static void pfd_close(struct PortForwarding *pf); static void pfd_closing(Plug *plug, const char *error_msg, int error_code, int calling_back) { - struct PortForwarding *pf = FROMFIELD(plug, struct PortForwarding, plug); + struct PortForwarding *pf = + container_of(plug, struct PortForwarding, plug); if (error_msg) { /* @@ -205,7 +206,8 @@ static char *ipv6_to_string(ptrlen ipv6) static void pfd_receive(Plug *plug, int urgent, char *data, int len) { - struct PortForwarding *pf = FROMFIELD(plug, struct PortForwarding, plug); + struct PortForwarding *pf = + container_of(plug, struct PortForwarding, plug); if (len == 0) return; @@ -429,7 +431,8 @@ static void pfd_receive(Plug *plug, int urgent, char *data, int len) static void pfd_sent(Plug *plug, int bufsize) { - struct PortForwarding *pf = FROMFIELD(plug, struct PortForwarding, plug); + struct PortForwarding *pf = + container_of(plug, struct PortForwarding, plug); if (pf->c) sshfwd_unthrottle(pf->c, bufsize); @@ -473,7 +476,7 @@ static int pfl_accepting(Plug *p, accept_fn_t constructor, accept_ctx_t ctx) Socket *s; const char *err; - pl = FROMFIELD(p, struct PortListener, plug); + pl = container_of(p, struct PortListener, plug); pf = new_portfwd_state(); pf->plug.vt = &PortForwarding_plugvt; pf->chan.initial_fixed_window_size = 0; @@ -588,7 +591,7 @@ static void pfl_terminate(struct PortListener *pl) static void pfd_set_input_wanted(Channel *chan, int wanted) { assert(chan->vt == &PortForwarding_channelvt); - PortForwarding *pf = FROMFIELD(chan, PortForwarding, chan); + PortForwarding *pf = container_of(chan, PortForwarding, chan); pf->input_wanted = wanted; sk_set_frozen(pf->s, !pf->input_wanted); } @@ -596,7 +599,7 @@ static void pfd_set_input_wanted(Channel *chan, int wanted) static void pfd_chan_free(Channel *chan) { assert(chan->vt == &PortForwarding_channelvt); - PortForwarding *pf = FROMFIELD(chan, PortForwarding, chan); + PortForwarding *pf = container_of(chan, PortForwarding, chan); pfd_close(pf); } @@ -606,21 +609,21 @@ static void pfd_chan_free(Channel *chan) static int pfd_send(Channel *chan, int is_stderr, const void *data, int len) { assert(chan->vt == &PortForwarding_channelvt); - PortForwarding *pf = FROMFIELD(chan, PortForwarding, chan); + PortForwarding *pf = container_of(chan, PortForwarding, chan); return sk_write(pf->s, data, len); } static void pfd_send_eof(Channel *chan) { assert(chan->vt == &PortForwarding_channelvt); - PortForwarding *pf = FROMFIELD(chan, PortForwarding, chan); + PortForwarding *pf = container_of(chan, PortForwarding, chan); sk_write_eof(pf->s); } static void pfd_open_confirmation(Channel *chan) { assert(chan->vt == &PortForwarding_channelvt); - PortForwarding *pf = FROMFIELD(chan, PortForwarding, chan); + PortForwarding *pf = container_of(chan, PortForwarding, chan); pf->ready = 1; sk_set_frozen(pf->s, 0); @@ -636,7 +639,7 @@ static void pfd_open_confirmation(Channel *chan) static void pfd_open_failure(Channel *chan, const char *errtext) { assert(chan->vt == &PortForwarding_channelvt); - PortForwarding *pf = FROMFIELD(chan, PortForwarding, chan); + PortForwarding *pf = container_of(chan, PortForwarding, chan); logeventf(pf->cl->frontend, "Forwarded connection refused by server%s%s", diff --git a/proxy.c b/proxy.c index f255824b..ee97472c 100644 --- a/proxy.c +++ b/proxy.c @@ -79,7 +79,7 @@ void proxy_activate (ProxySocket *p) static Plug *sk_proxy_plug (Socket *s, Plug *p) { - ProxySocket *ps = FROMFIELD(s, ProxySocket, sock); + ProxySocket *ps = container_of(s, ProxySocket, sock); Plug *ret = ps->plug; if (p) ps->plug = p; @@ -88,7 +88,7 @@ static Plug *sk_proxy_plug (Socket *s, Plug *p) static void sk_proxy_close (Socket *s) { - ProxySocket *ps = FROMFIELD(s, ProxySocket, sock); + ProxySocket *ps = container_of(s, ProxySocket, sock); sk_close(ps->sub_socket); sk_addr_free(ps->remote_addr); @@ -97,7 +97,7 @@ static void sk_proxy_close (Socket *s) static int sk_proxy_write (Socket *s, const void *data, int len) { - ProxySocket *ps = FROMFIELD(s, ProxySocket, sock); + ProxySocket *ps = container_of(s, ProxySocket, sock); if (ps->state != PROXY_STATE_ACTIVE) { bufchain_add(&ps->pending_output_data, data, len); @@ -108,7 +108,7 @@ static int sk_proxy_write (Socket *s, const void *data, int len) static int sk_proxy_write_oob (Socket *s, const void *data, int len) { - ProxySocket *ps = FROMFIELD(s, ProxySocket, sock); + ProxySocket *ps = container_of(s, ProxySocket, sock); if (ps->state != PROXY_STATE_ACTIVE) { bufchain_clear(&ps->pending_output_data); @@ -121,7 +121,7 @@ static int sk_proxy_write_oob (Socket *s, const void *data, int len) static void sk_proxy_write_eof (Socket *s) { - ProxySocket *ps = FROMFIELD(s, ProxySocket, sock); + ProxySocket *ps = container_of(s, ProxySocket, sock); if (ps->state != PROXY_STATE_ACTIVE) { ps->pending_eof = 1; @@ -132,7 +132,7 @@ static void sk_proxy_write_eof (Socket *s) static void sk_proxy_flush (Socket *s) { - ProxySocket *ps = FROMFIELD(s, ProxySocket, sock); + ProxySocket *ps = container_of(s, ProxySocket, sock); if (ps->state != PROXY_STATE_ACTIVE) { ps->pending_flush = 1; @@ -143,7 +143,7 @@ static void sk_proxy_flush (Socket *s) static void sk_proxy_set_frozen (Socket *s, int is_frozen) { - ProxySocket *ps = FROMFIELD(s, ProxySocket, sock); + ProxySocket *ps = container_of(s, ProxySocket, sock); if (ps->state != PROXY_STATE_ACTIVE) { ps->freeze = is_frozen; @@ -182,7 +182,7 @@ static void sk_proxy_set_frozen (Socket *s, int is_frozen) static const char * sk_proxy_socket_error (Socket *s) { - ProxySocket *ps = FROMFIELD(s, ProxySocket, sock); + ProxySocket *ps = container_of(s, ProxySocket, sock); if (ps->error != NULL || ps->sub_socket == NULL) { return ps->error; } @@ -194,7 +194,7 @@ static const char * sk_proxy_socket_error (Socket *s) static void plug_proxy_log(Plug *plug, int type, SockAddr *addr, int port, const char *error_msg, int error_code) { - ProxySocket *ps = FROMFIELD(plug, ProxySocket, plugimpl); + ProxySocket *ps = container_of(plug, ProxySocket, plugimpl); plug_log(ps->plug, type, addr, port, error_msg, error_code); } @@ -202,7 +202,7 @@ static void plug_proxy_log(Plug *plug, int type, SockAddr *addr, int port, static void plug_proxy_closing (Plug *p, const char *error_msg, int error_code, int calling_back) { - ProxySocket *ps = FROMFIELD(p, ProxySocket, plugimpl); + ProxySocket *ps = container_of(p, ProxySocket, plugimpl); if (ps->state != PROXY_STATE_ACTIVE) { ps->closing_error_msg = error_msg; @@ -216,7 +216,7 @@ static void plug_proxy_closing (Plug *p, const char *error_msg, static void plug_proxy_receive (Plug *p, int urgent, char *data, int len) { - ProxySocket *ps = FROMFIELD(p, ProxySocket, plugimpl); + ProxySocket *ps = container_of(p, ProxySocket, plugimpl); if (ps->state != PROXY_STATE_ACTIVE) { /* we will lose the urgentness of this data, but since most, @@ -235,7 +235,7 @@ static void plug_proxy_receive (Plug *p, int urgent, char *data, int len) static void plug_proxy_sent (Plug *p, int bufsize) { - ProxySocket *ps = FROMFIELD(p, ProxySocket, plugimpl); + ProxySocket *ps = container_of(p, ProxySocket, plugimpl); if (ps->state != PROXY_STATE_ACTIVE) { ps->sent_bufsize = bufsize; @@ -248,7 +248,7 @@ static void plug_proxy_sent (Plug *p, int bufsize) static int plug_proxy_accepting(Plug *p, accept_fn_t constructor, accept_ctx_t ctx) { - ProxySocket *ps = FROMFIELD(p, ProxySocket, plugimpl); + ProxySocket *ps = container_of(p, ProxySocket, plugimpl); if (ps->state != PROXY_STATE_ACTIVE) { ps->accepting_constructor = constructor; diff --git a/raw.c b/raw.c index 9e451d9c..e5db12f9 100644 --- a/raw.c +++ b/raw.c @@ -35,7 +35,7 @@ static void c_write(Raw *raw, const void *buf, int len) static void raw_log(Plug *plug, int type, SockAddr *addr, int port, const char *error_msg, int error_code) { - Raw *raw = FROMFIELD(plug, Raw, plug); + Raw *raw = container_of(plug, Raw, plug); backend_socket_log(raw->frontend, type, addr, port, error_msg, error_code, raw->conf, raw->session_started); } @@ -58,7 +58,7 @@ static void raw_check_close(Raw *raw) static void raw_closing(Plug *plug, const char *error_msg, int error_code, int calling_back) { - Raw *raw = FROMFIELD(plug, Raw, plug); + Raw *raw = container_of(plug, Raw, plug); if (error_msg) { /* A socket error has occurred. */ @@ -90,7 +90,7 @@ static void raw_closing(Plug *plug, const char *error_msg, int error_code, static void raw_receive(Plug *plug, int urgent, char *data, int len) { - Raw *raw = FROMFIELD(plug, Raw, plug); + Raw *raw = container_of(plug, Raw, plug); c_write(raw, data, len); /* We count 'session start', for proxy logging purposes, as being * when data is received from the network and printed. */ @@ -99,7 +99,7 @@ static void raw_receive(Plug *plug, int urgent, char *data, int len) static void raw_sent(Plug *plug, int bufsize) { - Raw *raw = FROMFIELD(plug, Raw, plug); + Raw *raw = container_of(plug, Raw, plug); raw->bufsize = bufsize; } @@ -181,7 +181,7 @@ static const char *raw_init(Frontend *frontend, Backend **backend_handle, static void raw_free(Backend *be) { - Raw *raw = FROMFIELD(be, Raw, backend); + Raw *raw = container_of(be, Raw, backend); if (raw->s) sk_close(raw->s); @@ -201,7 +201,7 @@ static void raw_reconfig(Backend *be, Conf *conf) */ static int raw_send(Backend *be, const char *buf, int len) { - Raw *raw = FROMFIELD(be, Raw, backend); + Raw *raw = container_of(be, Raw, backend); if (raw->s == NULL) return 0; @@ -216,7 +216,7 @@ static int raw_send(Backend *be, const char *buf, int len) */ static int raw_sendbuffer(Backend *be) { - Raw *raw = FROMFIELD(be, Raw, backend); + Raw *raw = container_of(be, Raw, backend); return raw->bufsize; } @@ -234,7 +234,7 @@ static void raw_size(Backend *be, int width, int height) */ static void raw_special(Backend *be, SessionSpecialCode code, int arg) { - Raw *raw = FROMFIELD(be, Raw, backend); + Raw *raw = container_of(be, Raw, backend); if (code == SS_EOF && raw->s) { sk_write_eof(raw->s); raw->sent_socket_eof= TRUE; @@ -255,7 +255,7 @@ static const SessionSpecial *raw_get_specials(Backend *be) static int raw_connected(Backend *be) { - Raw *raw = FROMFIELD(be, Raw, backend); + Raw *raw = container_of(be, Raw, backend); return raw->s != NULL; } @@ -266,7 +266,7 @@ static int raw_sendok(Backend *be) static void raw_unthrottle(Backend *be, int backlog) { - Raw *raw = FROMFIELD(be, Raw, backend); + Raw *raw = container_of(be, Raw, backend); sk_set_frozen(raw->s, backlog > RAW_MAX_BACKLOG); } @@ -289,7 +289,7 @@ static void raw_provide_logctx(Backend *be, LogContext *logctx) static int raw_exitcode(Backend *be) { - Raw *raw = FROMFIELD(be, Raw, backend); + Raw *raw = container_of(be, Raw, backend); if (raw->s != NULL) return -1; /* still connected */ else if (raw->closed_on_socket_error) diff --git a/rlogin.c b/rlogin.c index 01f79fc3..e982552b 100644 --- a/rlogin.c +++ b/rlogin.c @@ -39,7 +39,7 @@ static void c_write(Rlogin *rlogin, const void *buf, int len) static void rlogin_log(Plug *plug, int type, SockAddr *addr, int port, const char *error_msg, int error_code) { - Rlogin *rlogin = FROMFIELD(plug, Rlogin, plug); + Rlogin *rlogin = container_of(plug, Rlogin, plug); backend_socket_log(rlogin->frontend, type, addr, port, error_msg, error_code, rlogin->conf, !rlogin->firstbyte); @@ -48,7 +48,7 @@ static void rlogin_log(Plug *plug, int type, SockAddr *addr, int port, static void rlogin_closing(Plug *plug, const char *error_msg, int error_code, int calling_back) { - Rlogin *rlogin = FROMFIELD(plug, Rlogin, plug); + Rlogin *rlogin = container_of(plug, Rlogin, plug); /* * We don't implement independent EOF in each direction for Telnet @@ -72,7 +72,7 @@ static void rlogin_closing(Plug *plug, const char *error_msg, int error_code, static void rlogin_receive(Plug *plug, int urgent, char *data, int len) { - Rlogin *rlogin = FROMFIELD(plug, Rlogin, plug); + Rlogin *rlogin = container_of(plug, Rlogin, plug); if (urgent == 2) { char c; @@ -109,7 +109,7 @@ static void rlogin_receive(Plug *plug, int urgent, char *data, int len) static void rlogin_sent(Plug *plug, int bufsize) { - Rlogin *rlogin = FROMFIELD(plug, Rlogin, plug); + Rlogin *rlogin = container_of(plug, Rlogin, plug); rlogin->bufsize = bufsize; } @@ -236,7 +236,7 @@ static const char *rlogin_init(Frontend *frontend, Backend **backend_handle, static void rlogin_free(Backend *be) { - Rlogin *rlogin = FROMFIELD(be, Rlogin, backend); + Rlogin *rlogin = container_of(be, Rlogin, backend); if (rlogin->prompt) free_prompts(rlogin->prompt); @@ -258,7 +258,7 @@ static void rlogin_reconfig(Backend *be, Conf *conf) */ static int rlogin_send(Backend *be, const char *buf, int len) { - Rlogin *rlogin = FROMFIELD(be, Rlogin, backend); + Rlogin *rlogin = container_of(be, Rlogin, backend); bufchain bc; if (rlogin->s == NULL) @@ -300,7 +300,7 @@ static int rlogin_send(Backend *be, const char *buf, int len) */ static int rlogin_sendbuffer(Backend *be) { - Rlogin *rlogin = FROMFIELD(be, Rlogin, backend); + Rlogin *rlogin = container_of(be, Rlogin, backend); return rlogin->bufsize; } @@ -309,7 +309,7 @@ static int rlogin_sendbuffer(Backend *be) */ static void rlogin_size(Backend *be, int width, int height) { - Rlogin *rlogin = FROMFIELD(be, Rlogin, backend); + Rlogin *rlogin = container_of(be, Rlogin, backend); char b[12] = { '\xFF', '\xFF', 0x73, 0x73, 0, 0, 0, 0, 0, 0, 0, 0 }; rlogin->term_width = width; @@ -346,25 +346,25 @@ static const SessionSpecial *rlogin_get_specials(Backend *be) static int rlogin_connected(Backend *be) { - Rlogin *rlogin = FROMFIELD(be, Rlogin, backend); + Rlogin *rlogin = container_of(be, Rlogin, backend); return rlogin->s != NULL; } static int rlogin_sendok(Backend *be) { - /* Rlogin *rlogin = FROMFIELD(be, Rlogin, backend); */ + /* Rlogin *rlogin = container_of(be, Rlogin, backend); */ return 1; } static void rlogin_unthrottle(Backend *be, int backlog) { - Rlogin *rlogin = FROMFIELD(be, Rlogin, backend); + Rlogin *rlogin = container_of(be, Rlogin, backend); sk_set_frozen(rlogin->s, backlog > RLOGIN_MAX_BACKLOG); } static int rlogin_ldisc(Backend *be, int option) { - /* Rlogin *rlogin = FROMFIELD(be, Rlogin, backend); */ + /* Rlogin *rlogin = container_of(be, Rlogin, backend); */ return 0; } @@ -380,7 +380,7 @@ static void rlogin_provide_logctx(Backend *be, LogContext *logctx) static int rlogin_exitcode(Backend *be) { - Rlogin *rlogin = FROMFIELD(be, Rlogin, backend); + Rlogin *rlogin = container_of(be, Rlogin, backend); if (rlogin->s != NULL) return -1; /* still connected */ else if (rlogin->closed_on_socket_error) diff --git a/ssh.c b/ssh.c index c94554dd..5227b4de 100644 --- a/ssh.c +++ b/ssh.c @@ -141,7 +141,7 @@ static void ssh_connect_ppl(Ssh *ssh, PacketProtocolLayer *ppl) static void ssh_got_ssh_version(struct ssh_version_receiver *rcv, int major_version) { - Ssh *ssh = FROMFIELD(rcv, Ssh, version_receiver); + Ssh *ssh = container_of(rcv, Ssh, version_receiver); BinaryPacketProtocol *old_bpp; PacketProtocolLayer *connection_layer; @@ -489,7 +489,7 @@ void ssh_user_close(Ssh *ssh, const char *fmt, ...) static void ssh_socket_log(Plug *plug, int type, SockAddr *addr, int port, const char *error_msg, int error_code) { - Ssh *ssh = FROMFIELD(plug, Ssh, plug); + Ssh *ssh = container_of(plug, Ssh, plug); /* * While we're attempting connection sharing, don't loudly log @@ -509,7 +509,7 @@ static void ssh_socket_log(Plug *plug, int type, SockAddr *addr, int port, static void ssh_closing(Plug *plug, const char *error_msg, int error_code, int calling_back) { - Ssh *ssh = FROMFIELD(plug, Ssh, plug); + Ssh *ssh = container_of(plug, Ssh, plug); if (error_msg) { ssh_remote_error(ssh, "Network error: %s", error_msg); } else if (ssh->bpp) { @@ -520,7 +520,7 @@ static void ssh_closing(Plug *plug, const char *error_msg, int error_code, static void ssh_receive(Plug *plug, int urgent, char *data, int len) { - Ssh *ssh = FROMFIELD(plug, Ssh, plug); + Ssh *ssh = container_of(plug, Ssh, plug); /* Log raw data, if we're in that mode. */ if (ssh->logctx) @@ -534,7 +534,7 @@ static void ssh_receive(Plug *plug, int urgent, char *data, int len) static void ssh_sent(Plug *plug, int bufsize) { - Ssh *ssh = FROMFIELD(plug, Ssh, plug); + Ssh *ssh = container_of(plug, Ssh, plug); /* * If the send backlog on the SSH socket itself clears, we should * unthrottle the whole world if it was throttled. Also trigger an @@ -825,7 +825,7 @@ static const char *ssh_init(Frontend *frontend, Backend **backend_handle, static void ssh_free(Backend *be) { - Ssh *ssh = FROMFIELD(be, Ssh, backend); + Ssh *ssh = container_of(be, Ssh, backend); int need_random_unref; ssh_shutdown(ssh); @@ -860,7 +860,7 @@ static void ssh_free(Backend *be) */ static void ssh_reconfig(Backend *be, Conf *conf) { - Ssh *ssh = FROMFIELD(be, Ssh, backend); + Ssh *ssh = container_of(be, Ssh, backend); if (ssh->pinger) pinger_reconfig(ssh->pinger, ssh->conf, conf); @@ -877,7 +877,7 @@ static void ssh_reconfig(Backend *be, Conf *conf) */ static int ssh_send(Backend *be, const char *buf, int len) { - Ssh *ssh = FROMFIELD(be, Ssh, backend); + Ssh *ssh = container_of(be, Ssh, backend); if (ssh == NULL || ssh->s == NULL) return 0; @@ -894,7 +894,7 @@ static int ssh_send(Backend *be, const char *buf, int len) */ static int ssh_sendbuffer(Backend *be) { - Ssh *ssh = FROMFIELD(be, Ssh, backend); + Ssh *ssh = container_of(be, Ssh, backend); int backlog; if (!ssh || !ssh->s || !ssh->cl) @@ -919,7 +919,7 @@ static int ssh_sendbuffer(Backend *be) */ static void ssh_size(Backend *be, int width, int height) { - Ssh *ssh = FROMFIELD(be, Ssh, backend); + Ssh *ssh = container_of(be, Ssh, backend); ssh->term_width = width; ssh->term_height = height; @@ -956,7 +956,7 @@ static void ssh_add_special(void *vctx, const char *text, */ static const SessionSpecial *ssh_get_specials(Backend *be) { - Ssh *ssh = FROMFIELD(be, Ssh, backend); + Ssh *ssh = container_of(be, Ssh, backend); /* * Ask all our active protocol layers what specials they've got, @@ -986,7 +986,7 @@ static const SessionSpecial *ssh_get_specials(Backend *be) */ static void ssh_special(Backend *be, SessionSpecialCode code, int arg) { - Ssh *ssh = FROMFIELD(be, Ssh, backend); + Ssh *ssh = container_of(be, Ssh, backend); if (ssh->base_layer) ssh_ppl_special_cmd(ssh->base_layer, code, arg); @@ -998,20 +998,20 @@ static void ssh_special(Backend *be, SessionSpecialCode code, int arg) */ static void ssh_unthrottle(Backend *be, int bufsize) { - Ssh *ssh = FROMFIELD(be, Ssh, backend); + Ssh *ssh = container_of(be, Ssh, backend); ssh_stdout_unthrottle(ssh->cl, bufsize); } static int ssh_connected(Backend *be) { - Ssh *ssh = FROMFIELD(be, Ssh, backend); + Ssh *ssh = container_of(be, Ssh, backend); return ssh->s != NULL; } static int ssh_sendok(Backend *be) { - Ssh *ssh = FROMFIELD(be, Ssh, backend); + Ssh *ssh = container_of(be, Ssh, backend); return ssh->base_layer && ssh_ppl_want_user_input(ssh->base_layer); } @@ -1025,19 +1025,19 @@ void ssh_ldisc_update(Ssh *ssh) static int ssh_ldisc(Backend *be, int option) { - Ssh *ssh = FROMFIELD(be, Ssh, backend); + Ssh *ssh = container_of(be, Ssh, backend); return ssh->cl ? ssh_ldisc_option(ssh->cl, option) : FALSE; } static void ssh_provide_ldisc(Backend *be, Ldisc *ldisc) { - Ssh *ssh = FROMFIELD(be, Ssh, backend); + Ssh *ssh = container_of(be, Ssh, backend); ssh->ldisc = ldisc; } static void ssh_provide_logctx(Backend *be, LogContext *logctx) { - Ssh *ssh = FROMFIELD(be, Ssh, backend); + Ssh *ssh = container_of(be, Ssh, backend); ssh->logctx = logctx; } @@ -1048,7 +1048,7 @@ void ssh_got_exitcode(Ssh *ssh, int exitcode) static int ssh_return_exitcode(Backend *be) { - Ssh *ssh = FROMFIELD(be, Ssh, backend); + Ssh *ssh = container_of(be, Ssh, backend); if (ssh->s && (!ssh->session_started || ssh->base_layer)) return -1; else @@ -1062,7 +1062,7 @@ static int ssh_return_exitcode(Backend *be) */ static int ssh_cfg_info(Backend *be) { - Ssh *ssh = FROMFIELD(be, Ssh, backend); + Ssh *ssh = container_of(be, Ssh, backend); if (ssh->version == 0) return 0; /* don't know yet */ else if (ssh->bare_connection) @@ -1078,7 +1078,7 @@ static int ssh_cfg_info(Backend *be) */ extern int ssh_fallback_cmd(Backend *be) { - Ssh *ssh = FROMFIELD(be, Ssh, backend); + Ssh *ssh = container_of(be, Ssh, backend); return ssh->fallback_cmd; } diff --git a/ssh1bpp.c b/ssh1bpp.c index 98763e03..36afcd24 100644 --- a/ssh1bpp.c +++ b/ssh1bpp.c @@ -54,7 +54,7 @@ BinaryPacketProtocol *ssh1_bpp_new(void) static void ssh1_bpp_free(BinaryPacketProtocol *bpp) { - struct ssh1_bpp_state *s = FROMFIELD(bpp, struct ssh1_bpp_state, bpp); + struct ssh1_bpp_state *s = container_of(bpp, struct ssh1_bpp_state, bpp); if (s->cipher) ssh1_cipher_free(s->cipher); if (s->compctx) @@ -73,7 +73,7 @@ void ssh1_bpp_new_cipher(BinaryPacketProtocol *bpp, { struct ssh1_bpp_state *s; assert(bpp->vt == &ssh1_bpp_vtable); - s = FROMFIELD(bpp, struct ssh1_bpp_state, bpp); + s = container_of(bpp, struct ssh1_bpp_state, bpp); assert(!s->cipher); @@ -97,7 +97,7 @@ void ssh1_bpp_new_cipher(BinaryPacketProtocol *bpp, static void ssh1_bpp_handle_input(BinaryPacketProtocol *bpp) { - struct ssh1_bpp_state *s = FROMFIELD(bpp, struct ssh1_bpp_state, bpp); + struct ssh1_bpp_state *s = container_of(bpp, struct ssh1_bpp_state, bpp); crBegin(s->crState); @@ -314,7 +314,7 @@ static void ssh1_bpp_format_packet(struct ssh1_bpp_state *s, PktOut *pkt) static void ssh1_bpp_handle_output(BinaryPacketProtocol *bpp) { - struct ssh1_bpp_state *s = FROMFIELD(bpp, struct ssh1_bpp_state, bpp); + struct ssh1_bpp_state *s = container_of(bpp, struct ssh1_bpp_state, bpp); PktOut *pkt; if (s->pending_compression_request) { diff --git a/ssh1connection.c b/ssh1connection.c index 6a02676f..3cf75967 100644 --- a/ssh1connection.c +++ b/ssh1connection.c @@ -276,7 +276,7 @@ PacketProtocolLayer *ssh1_connection_new( static void ssh1_connection_free(PacketProtocolLayer *ppl) { struct ssh1_connection_state *s = - FROMFIELD(ppl, struct ssh1_connection_state, ppl); + container_of(ppl, struct ssh1_connection_state, ppl); struct X11FakeAuth *auth; struct ssh1_channel *c; struct ssh_rportfwd *rpf; @@ -305,7 +305,7 @@ void ssh1_connection_set_local_protoflags(PacketProtocolLayer *ppl, int flags) { assert(ppl->vt == &ssh1_connection_vtable); struct ssh1_connection_state *s = - FROMFIELD(ppl, struct ssh1_connection_state, ppl); + container_of(ppl, struct ssh1_connection_state, ppl); s->local_protoflags = flags; } @@ -619,7 +619,7 @@ static PktIn *ssh1_connection_pop(struct ssh1_connection_state *s) static void ssh1_connection_process_queue(PacketProtocolLayer *ppl) { struct ssh1_connection_state *s = - FROMFIELD(ppl, struct ssh1_connection_state, ppl); + container_of(ppl, struct ssh1_connection_state, ppl); PktIn *pktin; PktOut *pktout; @@ -942,14 +942,14 @@ static void ssh1_channel_init(struct ssh1_channel *c) static Conf *ssh1channel_get_conf(SshChannel *sc) { - struct ssh1_channel *c = FROMFIELD(sc, struct ssh1_channel, sc); + struct ssh1_channel *c = container_of(sc, struct ssh1_channel, sc); struct ssh1_connection_state *s = c->connlayer; return s->conf; } static void ssh1channel_write_eof(SshChannel *sc) { - struct ssh1_channel *c = FROMFIELD(sc, struct ssh1_channel, sc); + struct ssh1_channel *c = container_of(sc, struct ssh1_channel, sc); if (c->closes & CLOSES_SENT_CLOSE) return; @@ -960,7 +960,7 @@ static void ssh1channel_write_eof(SshChannel *sc) static void ssh1channel_unclean_close(SshChannel *sc, const char *err) { - struct ssh1_channel *c = FROMFIELD(sc, struct ssh1_channel, sc); + struct ssh1_channel *c = container_of(sc, struct ssh1_channel, sc); char *reason; reason = dupprintf("due to local error: %s", err); @@ -973,7 +973,7 @@ static void ssh1channel_unclean_close(SshChannel *sc, const char *err) static void ssh1channel_unthrottle(SshChannel *sc, int bufsize) { - struct ssh1_channel *c = FROMFIELD(sc, struct ssh1_channel, sc); + struct ssh1_channel *c = container_of(sc, struct ssh1_channel, sc); struct ssh1_connection_state *s = c->connlayer; if (c->throttling_conn && bufsize <= SSH1_BUFFER_LIMIT) { @@ -984,7 +984,7 @@ static void ssh1channel_unthrottle(SshChannel *sc, int bufsize) static int ssh1channel_write(SshChannel *sc, const void *buf, int len) { - struct ssh1_channel *c = FROMFIELD(sc, struct ssh1_channel, sc); + struct ssh1_channel *c = container_of(sc, struct ssh1_channel, sc); struct ssh1_connection_state *s = c->connlayer; assert(!(c->closes & CLOSES_SENT_CLOSE)); @@ -1009,7 +1009,7 @@ static SshChannel *ssh1_lportfwd_open( const char *org, Channel *chan) { struct ssh1_connection_state *s = - FROMFIELD(cl, struct ssh1_connection_state, cl); + container_of(cl, struct ssh1_connection_state, cl); PacketProtocolLayer *ppl = &s->ppl; /* for ppl_logevent */ struct ssh1_channel *c = snew(struct ssh1_channel); PktOut *pktout; @@ -1059,7 +1059,7 @@ static struct ssh_rportfwd *ssh1_rportfwd_alloc( ssh_sharing_connstate *share_ctx) { struct ssh1_connection_state *s = - FROMFIELD(cl, struct ssh1_connection_state, cl); + container_of(cl, struct ssh1_connection_state, cl); struct ssh_rportfwd *rpf = snew(struct ssh_rportfwd); rpf->shost = dupstr(shost); @@ -1098,7 +1098,7 @@ static void ssh1_rportfwd_remove(ConnectionLayer *cl, struct ssh_rportfwd *rpf) static int ssh1_agent_forwarding_permitted(ConnectionLayer *cl) { struct ssh1_connection_state *s = - FROMFIELD(cl, struct ssh1_connection_state, cl); + container_of(cl, struct ssh1_connection_state, cl); return conf_get_int(s->conf, CONF_agentfwd) && agent_exists(); } @@ -1106,7 +1106,7 @@ static void ssh1_connection_special_cmd(PacketProtocolLayer *ppl, SessionSpecialCode code, int arg) { struct ssh1_connection_state *s = - FROMFIELD(ppl, struct ssh1_connection_state, ppl); + container_of(ppl, struct ssh1_connection_state, ppl); PktOut *pktout; if (code == SS_PING || code == SS_NOP) { @@ -1134,7 +1134,7 @@ static void ssh1_connection_special_cmd(PacketProtocolLayer *ppl, static void ssh1_terminal_size(ConnectionLayer *cl, int width, int height) { struct ssh1_connection_state *s = - FROMFIELD(cl, struct ssh1_connection_state, cl); + container_of(cl, struct ssh1_connection_state, cl); s->term_width = width; s->term_height = height; @@ -1152,7 +1152,7 @@ static void ssh1_terminal_size(ConnectionLayer *cl, int width, int height) static void ssh1_stdout_unthrottle(ConnectionLayer *cl, int bufsize) { struct ssh1_connection_state *s = - FROMFIELD(cl, struct ssh1_connection_state, cl); + container_of(cl, struct ssh1_connection_state, cl); if (s->stdout_throttling && bufsize < SSH1_BUFFER_LIMIT) { s->stdout_throttling = 0; @@ -1168,7 +1168,7 @@ static int ssh1_stdin_backlog(ConnectionLayer *cl) static void ssh1_throttle_all_channels(ConnectionLayer *cl, int throttled) { struct ssh1_connection_state *s = - FROMFIELD(cl, struct ssh1_connection_state, cl); + container_of(cl, struct ssh1_connection_state, cl); struct ssh1_channel *c; int i; @@ -1179,7 +1179,7 @@ static void ssh1_throttle_all_channels(ConnectionLayer *cl, int throttled) static int ssh1_ldisc_option(ConnectionLayer *cl, int option) { struct ssh1_connection_state *s = - FROMFIELD(cl, struct ssh1_connection_state, cl); + container_of(cl, struct ssh1_connection_state, cl); /* We always return the same value for LD_ECHO and LD_EDIT */ return s->echoedit; @@ -1188,14 +1188,14 @@ static int ssh1_ldisc_option(ConnectionLayer *cl, int option) static int ssh1_connection_want_user_input(PacketProtocolLayer *ppl) { struct ssh1_connection_state *s = - FROMFIELD(ppl, struct ssh1_connection_state, ppl); + container_of(ppl, struct ssh1_connection_state, ppl); return s->session_ready && !s->session_eof_sent; } static void ssh1_connection_got_user_input(PacketProtocolLayer *ppl) { struct ssh1_connection_state *s = - FROMFIELD(ppl, struct ssh1_connection_state, ppl); + container_of(ppl, struct ssh1_connection_state, ppl); if (s->session_ready && !s->session_eof_sent) queue_idempotent_callback(&s->ppl.ic_process_queue); } @@ -1203,7 +1203,7 @@ static void ssh1_connection_got_user_input(PacketProtocolLayer *ppl) static void ssh1_connection_reconfigure(PacketProtocolLayer *ppl, Conf *conf) { struct ssh1_connection_state *s = - FROMFIELD(ppl, struct ssh1_connection_state, ppl); + container_of(ppl, struct ssh1_connection_state, ppl); conf_free(s->conf); s->conf = conf_copy(conf); diff --git a/ssh1login.c b/ssh1login.c index d2404fc5..e64bc834 100644 --- a/ssh1login.c +++ b/ssh1login.c @@ -99,7 +99,8 @@ PacketProtocolLayer *ssh1_login_new( static void ssh1_login_free(PacketProtocolLayer *ppl) { - struct ssh1_login_state *s = FROMFIELD(ppl, struct ssh1_login_state, ppl); + struct ssh1_login_state *s = + container_of(ppl, struct ssh1_login_state, ppl); if (s->successor_layer) ssh_ppl_free(s->successor_layer); @@ -166,7 +167,8 @@ static PktIn *ssh1_login_pop(struct ssh1_login_state *s) static void ssh1_login_process_queue(PacketProtocolLayer *ppl) { - struct ssh1_login_state *s = FROMFIELD(ppl, struct ssh1_login_state, ppl); + struct ssh1_login_state *s = + container_of(ppl, struct ssh1_login_state, ppl); PktIn *pktin; PktOut *pkt; int i; @@ -1172,7 +1174,7 @@ static void ssh1_login_special_cmd(PacketProtocolLayer *ppl, SessionSpecialCode code, int arg) { struct ssh1_login_state *s = - FROMFIELD(ppl, struct ssh1_login_state, ppl); + container_of(ppl, struct ssh1_login_state, ppl); PktOut *pktout; if (code == SS_PING || code == SS_NOP) { @@ -1187,14 +1189,14 @@ static void ssh1_login_special_cmd(PacketProtocolLayer *ppl, static int ssh1_login_want_user_input(PacketProtocolLayer *ppl) { struct ssh1_login_state *s = - FROMFIELD(ppl, struct ssh1_login_state, ppl); + container_of(ppl, struct ssh1_login_state, ppl); return s->want_user_input; } static void ssh1_login_got_user_input(PacketProtocolLayer *ppl) { struct ssh1_login_state *s = - FROMFIELD(ppl, struct ssh1_login_state, ppl); + container_of(ppl, struct ssh1_login_state, ppl); if (s->want_user_input) queue_idempotent_callback(&s->ppl.ic_process_queue); } @@ -1202,6 +1204,6 @@ static void ssh1_login_got_user_input(PacketProtocolLayer *ppl) static void ssh1_login_reconfigure(PacketProtocolLayer *ppl, Conf *conf) { struct ssh1_login_state *s = - FROMFIELD(ppl, struct ssh1_login_state, ppl); + container_of(ppl, struct ssh1_login_state, ppl); ssh_ppl_reconfigure(s->successor_layer, conf); } diff --git a/ssh2bpp-bare.c b/ssh2bpp-bare.c index ba40e7ab..213acf0c 100644 --- a/ssh2bpp-bare.c +++ b/ssh2bpp-bare.c @@ -45,7 +45,7 @@ BinaryPacketProtocol *ssh2_bare_bpp_new(void) static void ssh2_bare_bpp_free(BinaryPacketProtocol *bpp) { struct ssh2_bare_bpp_state *s = - FROMFIELD(bpp, struct ssh2_bare_bpp_state, bpp); + container_of(bpp, struct ssh2_bare_bpp_state, bpp); sfree(s->pktin); sfree(s); } @@ -62,7 +62,7 @@ static void ssh2_bare_bpp_free(BinaryPacketProtocol *bpp) static void ssh2_bare_bpp_handle_input(BinaryPacketProtocol *bpp) { struct ssh2_bare_bpp_state *s = - FROMFIELD(bpp, struct ssh2_bare_bpp_state, bpp); + container_of(bpp, struct ssh2_bare_bpp_state, bpp); crBegin(s->crState); @@ -175,7 +175,7 @@ static void ssh2_bare_bpp_format_packet(struct ssh2_bare_bpp_state *s, static void ssh2_bare_bpp_handle_output(BinaryPacketProtocol *bpp) { struct ssh2_bare_bpp_state *s = - FROMFIELD(bpp, struct ssh2_bare_bpp_state, bpp); + container_of(bpp, struct ssh2_bare_bpp_state, bpp); PktOut *pkt; while ((pkt = pq_pop(&s->bpp.out_pq)) != NULL) { diff --git a/ssh2bpp.c b/ssh2bpp.c index 6bda41d0..f0b6fd22 100644 --- a/ssh2bpp.c +++ b/ssh2bpp.c @@ -63,7 +63,7 @@ BinaryPacketProtocol *ssh2_bpp_new(struct DataTransferStats *stats) static void ssh2_bpp_free(BinaryPacketProtocol *bpp) { - struct ssh2_bpp_state *s = FROMFIELD(bpp, struct ssh2_bpp_state, bpp); + struct ssh2_bpp_state *s = container_of(bpp, struct ssh2_bpp_state, bpp); sfree(s->buf); if (s->out.cipher) ssh2_cipher_free(s->out.cipher); @@ -89,7 +89,7 @@ void ssh2_bpp_new_outgoing_crypto( { struct ssh2_bpp_state *s; assert(bpp->vt == &ssh2_bpp_vtable); - s = FROMFIELD(bpp, struct ssh2_bpp_state, bpp); + s = container_of(bpp, struct ssh2_bpp_state, bpp); if (s->out.cipher) ssh2_cipher_free(s->out.cipher); @@ -132,7 +132,7 @@ void ssh2_bpp_new_incoming_crypto( { struct ssh2_bpp_state *s; assert(bpp->vt == &ssh2_bpp_vtable); - s = FROMFIELD(bpp, struct ssh2_bpp_state, bpp); + s = container_of(bpp, struct ssh2_bpp_state, bpp); if (s->in.cipher) ssh2_cipher_free(s->in.cipher); @@ -177,7 +177,7 @@ void ssh2_bpp_new_incoming_crypto( static void ssh2_bpp_handle_input(BinaryPacketProtocol *bpp) { - struct ssh2_bpp_state *s = FROMFIELD(bpp, struct ssh2_bpp_state, bpp); + struct ssh2_bpp_state *s = container_of(bpp, struct ssh2_bpp_state, bpp); crBegin(s->crState); @@ -700,7 +700,7 @@ static void ssh2_bpp_format_packet(struct ssh2_bpp_state *s, PktOut *pkt) static void ssh2_bpp_handle_output(BinaryPacketProtocol *bpp) { - struct ssh2_bpp_state *s = FROMFIELD(bpp, struct ssh2_bpp_state, bpp); + struct ssh2_bpp_state *s = container_of(bpp, struct ssh2_bpp_state, bpp); PktOut *pkt; if (s->cbc_ignore_workaround) { diff --git a/ssh2connection.c b/ssh2connection.c index 9aa45dc9..6da82951 100644 --- a/ssh2connection.c +++ b/ssh2connection.c @@ -407,7 +407,7 @@ PacketProtocolLayer *ssh2_connection_new( static void ssh2_connection_free(PacketProtocolLayer *ppl) { struct ssh2_connection_state *s = - FROMFIELD(ppl, struct ssh2_connection_state, ppl); + container_of(ppl, struct ssh2_connection_state, ppl); struct X11FakeAuth *auth; struct ssh2_channel *c; struct ssh_rportfwd *rpf; @@ -1153,7 +1153,7 @@ static PktIn *ssh2_connection_pop(struct ssh2_connection_state *s) static void ssh2_connection_process_queue(PacketProtocolLayer *ppl) { struct ssh2_connection_state *s = - FROMFIELD(ppl, struct ssh2_connection_state, ppl); + container_of(ppl, struct ssh2_connection_state, ppl); PktIn *pktin; PktOut *pktout; @@ -1198,7 +1198,7 @@ static void ssh2_connection_process_queue(PacketProtocolLayer *ppl) &s->cl, conf_get_str(s->conf, CONF_ssh_nc_host), conf_get_int(s->conf, CONF_ssh_nc_port), "main channel", &mc->chan); - s->mainchan = FROMFIELD(mc->sc, struct ssh2_channel, sc); + s->mainchan = container_of(mc->sc, struct ssh2_channel, sc); break; } @@ -1865,14 +1865,14 @@ static PktOut *ssh2_chanreq_init(struct ssh2_channel *c, const char *type, static Conf *ssh2channel_get_conf(SshChannel *sc) { - struct ssh2_channel *c = FROMFIELD(sc, struct ssh2_channel, sc); + struct ssh2_channel *c = container_of(sc, struct ssh2_channel, sc); struct ssh2_connection_state *s = c->connlayer; return s->conf; } static void ssh2channel_write_eof(SshChannel *sc) { - struct ssh2_channel *c = FROMFIELD(sc, struct ssh2_channel, sc); + struct ssh2_channel *c = container_of(sc, struct ssh2_channel, sc); if (c->closes & CLOSES_SENT_EOF) return; @@ -1883,7 +1883,7 @@ static void ssh2channel_write_eof(SshChannel *sc) static void ssh2channel_unclean_close(SshChannel *sc, const char *err) { - struct ssh2_channel *c = FROMFIELD(sc, struct ssh2_channel, sc); + struct ssh2_channel *c = container_of(sc, struct ssh2_channel, sc); char *reason; reason = dupprintf("due to local error: %s", err); @@ -1896,7 +1896,7 @@ static void ssh2channel_unclean_close(SshChannel *sc, const char *err) static void ssh2channel_unthrottle(SshChannel *sc, int bufsize) { - struct ssh2_channel *c = FROMFIELD(sc, struct ssh2_channel, sc); + struct ssh2_channel *c = container_of(sc, struct ssh2_channel, sc); struct ssh2_connection_state *s = c->connlayer; int buflimit; @@ -1912,7 +1912,7 @@ static void ssh2channel_unthrottle(SshChannel *sc, int bufsize) static int ssh2channel_write(SshChannel *sc, const void *buf, int len) { - struct ssh2_channel *c = FROMFIELD(sc, struct ssh2_channel, sc); + struct ssh2_channel *c = container_of(sc, struct ssh2_channel, sc); assert(!(c->closes & CLOSES_SENT_EOF)); bufchain_add(&c->outbuffer, buf, len); return ssh2_try_send(c); @@ -1923,7 +1923,7 @@ static void ssh2channel_x11_sharing_handover( const char *peer_addr, int peer_port, int endian, int protomajor, int protominor, const void *initial_data, int initial_len) { - struct ssh2_channel *c = FROMFIELD(sc, struct ssh2_channel, sc); + struct ssh2_channel *c = container_of(sc, struct ssh2_channel, sc); /* * This function is called when we've just discovered that an X * forwarding channel on which we'd been handling the initial auth @@ -1945,7 +1945,7 @@ static void ssh2channel_x11_sharing_handover( static void ssh2channel_window_override_removed(SshChannel *sc) { - struct ssh2_channel *c = FROMFIELD(sc, struct ssh2_channel, sc); + struct ssh2_channel *c = container_of(sc, struct ssh2_channel, sc); struct ssh2_connection_state *s = c->connlayer; /* @@ -1961,7 +1961,7 @@ static SshChannel *ssh2_lportfwd_open( const char *org, Channel *chan) { struct ssh2_connection_state *s = - FROMFIELD(cl, struct ssh2_connection_state, cl); + container_of(cl, struct ssh2_connection_state, cl); PacketProtocolLayer *ppl = &s->ppl; /* for ppl_logevent */ struct ssh2_channel *c = snew(struct ssh2_channel); PktOut *pktout; @@ -2022,7 +2022,7 @@ static struct ssh_rportfwd *ssh2_rportfwd_alloc( ssh_sharing_connstate *share_ctx) { struct ssh2_connection_state *s = - FROMFIELD(cl, struct ssh2_connection_state, cl); + container_of(cl, struct ssh2_connection_state, cl); struct ssh_rportfwd *rpf = snew(struct ssh_rportfwd); rpf->shost = dupstr(shost); @@ -2058,7 +2058,7 @@ static struct ssh_rportfwd *ssh2_rportfwd_alloc( static void ssh2_rportfwd_remove(ConnectionLayer *cl, struct ssh_rportfwd *rpf) { struct ssh2_connection_state *s = - FROMFIELD(cl, struct ssh2_connection_state, cl); + container_of(cl, struct ssh2_connection_state, cl); if (rpf->share_ctx) { /* @@ -2095,14 +2095,14 @@ static void ssh2_sharing_queue_global_request( ConnectionLayer *cl, ssh_sharing_connstate *cs) { struct ssh2_connection_state *s = - FROMFIELD(cl, struct ssh2_connection_state, cl); + container_of(cl, struct ssh2_connection_state, cl); ssh2_queue_global_request_handler(s, ssh2_sharing_globreq_response, cs); } static void ssh2_sharing_no_more_downstreams(ConnectionLayer *cl) { struct ssh2_connection_state *s = - FROMFIELD(cl, struct ssh2_connection_state, cl); + container_of(cl, struct ssh2_connection_state, cl); queue_toplevel_callback(ssh2_check_termination_callback, s); } @@ -2111,7 +2111,7 @@ static struct X11FakeAuth *ssh2_add_sharing_x11_display( share_channel *share_chan) { struct ssh2_connection_state *s = - FROMFIELD(cl, struct ssh2_connection_state, cl); + container_of(cl, struct ssh2_connection_state, cl); struct X11FakeAuth *auth; /* @@ -2130,7 +2130,7 @@ static void ssh2_remove_sharing_x11_display( ConnectionLayer *cl, struct X11FakeAuth *auth) { struct ssh2_connection_state *s = - FROMFIELD(cl, struct ssh2_connection_state, cl); + container_of(cl, struct ssh2_connection_state, cl); del234(s->x11authtree, auth); x11_free_fake_auth(auth); } @@ -2139,7 +2139,7 @@ static unsigned ssh2_alloc_sharing_channel( ConnectionLayer *cl, ssh_sharing_connstate *connstate) { struct ssh2_connection_state *s = - FROMFIELD(cl, struct ssh2_connection_state, cl); + container_of(cl, struct ssh2_connection_state, cl); struct ssh2_channel *c = snew(struct ssh2_channel); c->connlayer = s; @@ -2152,7 +2152,7 @@ static unsigned ssh2_alloc_sharing_channel( static void ssh2_delete_sharing_channel(ConnectionLayer *cl, unsigned localid) { struct ssh2_connection_state *s = - FROMFIELD(cl, struct ssh2_connection_state, cl); + container_of(cl, struct ssh2_connection_state, cl); struct ssh2_channel *c = find234(s->channels, &localid, ssh2_channelfind); if (c) ssh2_channel_destroy(c); @@ -2163,7 +2163,7 @@ static void ssh2_send_packet_from_downstream( const void *data, int datalen, const char *additional_log_text) { struct ssh2_connection_state *s = - FROMFIELD(cl, struct ssh2_connection_state, cl); + container_of(cl, struct ssh2_connection_state, cl); PktOut *pkt = ssh_bpp_new_pktout(s->ppl.bpp, type); pkt->downstream_id = id; pkt->additional_log_text = additional_log_text; @@ -2174,7 +2174,7 @@ static void ssh2_send_packet_from_downstream( static int ssh2_agent_forwarding_permitted(ConnectionLayer *cl) { struct ssh2_connection_state *s = - FROMFIELD(cl, struct ssh2_connection_state, cl); + container_of(cl, struct ssh2_connection_state, cl); return conf_get_int(s->conf, CONF_agentfwd) && agent_exists(); } @@ -2210,7 +2210,7 @@ static mainchan *mainchan_new(struct ssh2_connection_state *s) static void mainchan_free(Channel *chan) { assert(chan->vt == &mainchan_channelvt); - mainchan *mc = FROMFIELD(chan, mainchan, chan); + mainchan *mc = container_of(chan, mainchan, chan); struct ssh2_connection_state *s = mc->connlayer; s->mainchan = NULL; sfree(mc); @@ -2218,7 +2218,7 @@ static void mainchan_free(Channel *chan) static void mainchan_open_confirmation(Channel *chan) { - mainchan *mc = FROMFIELD(chan, mainchan, chan); + mainchan *mc = container_of(chan, mainchan, chan); struct ssh2_connection_state *s = mc->connlayer; PacketProtocolLayer *ppl = &s->ppl; /* for ppl_logevent */ @@ -2229,7 +2229,7 @@ static void mainchan_open_confirmation(Channel *chan) static void mainchan_open_failure(Channel *chan, const char *errtext) { assert(chan->vt == &mainchan_channelvt); - mainchan *mc = FROMFIELD(chan, mainchan, chan); + mainchan *mc = container_of(chan, mainchan, chan); struct ssh2_connection_state *s = mc->connlayer; /* @@ -2244,7 +2244,7 @@ static int mainchan_send(Channel *chan, int is_stderr, const void *data, int length) { assert(chan->vt == &mainchan_channelvt); - mainchan *mc = FROMFIELD(chan, mainchan, chan); + mainchan *mc = container_of(chan, mainchan, chan); struct ssh2_connection_state *s = mc->connlayer; return from_backend(s->ppl.frontend, is_stderr, data, length); } @@ -2252,7 +2252,7 @@ static int mainchan_send(Channel *chan, int is_stderr, static void mainchan_send_eof(Channel *chan) { assert(chan->vt == &mainchan_channelvt); - mainchan *mc = FROMFIELD(chan, mainchan, chan); + mainchan *mc = container_of(chan, mainchan, chan); struct ssh2_connection_state *s = mc->connlayer; PacketProtocolLayer *ppl = &s->ppl; /* for ppl_logevent */ @@ -2275,7 +2275,7 @@ static void mainchan_send_eof(Channel *chan) static void mainchan_set_input_wanted(Channel *chan, int wanted) { assert(chan->vt == &mainchan_channelvt); - mainchan *mc = FROMFIELD(chan, mainchan, chan); + mainchan *mc = container_of(chan, mainchan, chan); struct ssh2_connection_state *s = mc->connlayer; /* @@ -2321,7 +2321,7 @@ static int ssh2_connection_get_specials( PacketProtocolLayer *ppl, add_special_fn_t add_special, void *ctx) { struct ssh2_connection_state *s = - FROMFIELD(ppl, struct ssh2_connection_state, ppl); + container_of(ppl, struct ssh2_connection_state, ppl); int toret = FALSE; if (s->mainchan) { @@ -2381,7 +2381,7 @@ static void ssh2_connection_special_cmd(PacketProtocolLayer *ppl, SessionSpecialCode code, int arg) { struct ssh2_connection_state *s = - FROMFIELD(ppl, struct ssh2_connection_state, ppl); + container_of(ppl, struct ssh2_connection_state, ppl); PktOut *pktout; const char *signame; @@ -2421,7 +2421,7 @@ static void ssh2_connection_special_cmd(PacketProtocolLayer *ppl, static void ssh2_terminal_size(ConnectionLayer *cl, int width, int height) { struct ssh2_connection_state *s = - FROMFIELD(cl, struct ssh2_connection_state, cl); + container_of(cl, struct ssh2_connection_state, cl); s->term_width = width; s->term_height = height; @@ -2440,7 +2440,7 @@ static void ssh2_terminal_size(ConnectionLayer *cl, int width, int height) static void ssh2_stdout_unthrottle(ConnectionLayer *cl, int bufsize) { struct ssh2_connection_state *s = - FROMFIELD(cl, struct ssh2_connection_state, cl); + container_of(cl, struct ssh2_connection_state, cl); if (s->mainchan) ssh2channel_unthrottle(&s->mainchan->sc, bufsize); @@ -2449,7 +2449,7 @@ static void ssh2_stdout_unthrottle(ConnectionLayer *cl, int bufsize) static int ssh2_stdin_backlog(ConnectionLayer *cl) { struct ssh2_connection_state *s = - FROMFIELD(cl, struct ssh2_connection_state, cl); + container_of(cl, struct ssh2_connection_state, cl); return s->mainchan ? bufchain_size(&s->mainchan->outbuffer) : 0; } @@ -2457,7 +2457,7 @@ static int ssh2_stdin_backlog(ConnectionLayer *cl) static void ssh2_throttle_all_channels(ConnectionLayer *cl, int throttled) { struct ssh2_connection_state *s = - FROMFIELD(cl, struct ssh2_connection_state, cl); + container_of(cl, struct ssh2_connection_state, cl); struct ssh2_channel *c; int i; @@ -2470,7 +2470,7 @@ static void ssh2_throttle_all_channels(ConnectionLayer *cl, int throttled) static int ssh2_ldisc_option(ConnectionLayer *cl, int option) { struct ssh2_connection_state *s = - FROMFIELD(cl, struct ssh2_connection_state, cl); + container_of(cl, struct ssh2_connection_state, cl); /* We always return the same value for LD_ECHO and LD_EDIT */ return s->echoedit; @@ -2479,14 +2479,14 @@ static int ssh2_ldisc_option(ConnectionLayer *cl, int option) static int ssh2_connection_want_user_input(PacketProtocolLayer *ppl) { struct ssh2_connection_state *s = - FROMFIELD(ppl, struct ssh2_connection_state, ppl); + container_of(ppl, struct ssh2_connection_state, ppl); return s->mainchan_ready && s->want_user_input; } static void ssh2_connection_got_user_input(PacketProtocolLayer *ppl) { struct ssh2_connection_state *s = - FROMFIELD(ppl, struct ssh2_connection_state, ppl); + container_of(ppl, struct ssh2_connection_state, ppl); while (s->mainchan && bufchain_size(s->ppl.user_input) > 0) { /* @@ -2503,7 +2503,7 @@ static void ssh2_connection_got_user_input(PacketProtocolLayer *ppl) static void ssh2_connection_reconfigure(PacketProtocolLayer *ppl, Conf *conf) { struct ssh2_connection_state *s = - FROMFIELD(ppl, struct ssh2_connection_state, ppl); + container_of(ppl, struct ssh2_connection_state, ppl); conf_free(s->conf); s->conf = conf_copy(conf); diff --git a/ssh2transport.c b/ssh2transport.c index 9a5a970d..bec55dac 100644 --- a/ssh2transport.c +++ b/ssh2transport.c @@ -357,7 +357,7 @@ PacketProtocolLayer *ssh2_transport_new( static void ssh2_transport_free(PacketProtocolLayer *ppl) { struct ssh2_transport_state *s = - FROMFIELD(ppl, struct ssh2_transport_state, ppl); + container_of(ppl, struct ssh2_transport_state, ppl); /* * As our last act before being freed, move any outgoing packets @@ -596,7 +596,7 @@ static PktIn *ssh2_transport_pop(struct ssh2_transport_state *s) static void ssh2_transport_process_queue(PacketProtocolLayer *ppl) { struct ssh2_transport_state *s = - FROMFIELD(ppl, struct ssh2_transport_state, ppl); + container_of(ppl, struct ssh2_transport_state, ppl); PktIn *pktin; PktOut *pktout; @@ -2767,7 +2767,7 @@ ptrlen ssh2_transport_get_session_id(PacketProtocolLayer *ppl) struct ssh2_transport_state *s; assert(ppl->vt == &ssh2_transport_vtable); - s = FROMFIELD(ppl, struct ssh2_transport_state, ppl); + s = container_of(ppl, struct ssh2_transport_state, ppl); assert(s->got_session_id); return make_ptrlen(s->session_id, s->session_id_len); @@ -2778,7 +2778,7 @@ void ssh2_transport_notify_auth_done(PacketProtocolLayer *ppl) struct ssh2_transport_state *s; assert(ppl->vt == &ssh2_transport_vtable); - s = FROMFIELD(ppl, struct ssh2_transport_state, ppl); + s = container_of(ppl, struct ssh2_transport_state, ppl); s->rekey_reason = NULL; /* will be filled in later */ s->rekey_class = RK_POST_USERAUTH; @@ -2791,7 +2791,7 @@ static int ssh2_transport_get_specials( PacketProtocolLayer *ppl, add_special_fn_t add_special, void *ctx) { struct ssh2_transport_state *s = - FROMFIELD(ppl, struct ssh2_transport_state, ppl); + container_of(ppl, struct ssh2_transport_state, ppl); int need_separator = FALSE; int toret; @@ -2836,7 +2836,7 @@ static void ssh2_transport_special_cmd(PacketProtocolLayer *ppl, SessionSpecialCode code, int arg) { struct ssh2_transport_state *s = - FROMFIELD(ppl, struct ssh2_transport_state, ppl); + container_of(ppl, struct ssh2_transport_state, ppl); if (code == SS_REKEY) { if (!s->kex_in_progress) { @@ -2884,7 +2884,7 @@ static void ssh2_transport_reconfigure(PacketProtocolLayer *ppl, Conf *conf) int i; assert(ppl->vt == &ssh2_transport_vtable); - s = FROMFIELD(ppl, struct ssh2_transport_state, ppl); + s = container_of(ppl, struct ssh2_transport_state, ppl); rekey_time = sanitise_rekey_time( conf_get_int(conf, CONF_ssh_rekey_time), 60); @@ -2951,7 +2951,7 @@ static void ssh2_transport_reconfigure(PacketProtocolLayer *ppl, Conf *conf) static int ssh2_transport_want_user_input(PacketProtocolLayer *ppl) { struct ssh2_transport_state *s = - FROMFIELD(ppl, struct ssh2_transport_state, ppl); + container_of(ppl, struct ssh2_transport_state, ppl); /* Just delegate this to the higher layer */ return ssh_ppl_want_user_input(s->higher_layer); @@ -2960,7 +2960,7 @@ static int ssh2_transport_want_user_input(PacketProtocolLayer *ppl) static void ssh2_transport_got_user_input(PacketProtocolLayer *ppl) { struct ssh2_transport_state *s = - FROMFIELD(ppl, struct ssh2_transport_state, ppl); + container_of(ppl, struct ssh2_transport_state, ppl); /* Just delegate this to the higher layer */ ssh_ppl_got_user_input(s->higher_layer); diff --git a/ssh2userauth.c b/ssh2userauth.c index 1e5a1207..5dbb7394 100644 --- a/ssh2userauth.c +++ b/ssh2userauth.c @@ -145,14 +145,14 @@ void ssh2_userauth_set_transport_layer(PacketProtocolLayer *userauth, PacketProtocolLayer *transport) { struct ssh2_userauth_state *s = - FROMFIELD(userauth, struct ssh2_userauth_state, ppl); + container_of(userauth, struct ssh2_userauth_state, ppl); s->transport_layer = transport; } static void ssh2_userauth_free(PacketProtocolLayer *ppl) { struct ssh2_userauth_state *s = - FROMFIELD(ppl, struct ssh2_userauth_state, ppl); + container_of(ppl, struct ssh2_userauth_state, ppl); bufchain_clear(&s->banner); if (s->successor_layer) @@ -198,7 +198,7 @@ static PktIn *ssh2_userauth_pop(struct ssh2_userauth_state *s) static void ssh2_userauth_process_queue(PacketProtocolLayer *ppl) { struct ssh2_userauth_state *s = - FROMFIELD(ppl, struct ssh2_userauth_state, ppl); + container_of(ppl, struct ssh2_userauth_state, ppl); PktIn *pktin; ssh2_userauth_filter_queue(s); /* no matter why we were called */ @@ -1653,14 +1653,14 @@ static void ssh2_userauth_special_cmd(PacketProtocolLayer *ppl, static int ssh2_userauth_want_user_input(PacketProtocolLayer *ppl) { struct ssh2_userauth_state *s = - FROMFIELD(ppl, struct ssh2_userauth_state, ppl); + container_of(ppl, struct ssh2_userauth_state, ppl); return s->want_user_input; } static void ssh2_userauth_got_user_input(PacketProtocolLayer *ppl) { struct ssh2_userauth_state *s = - FROMFIELD(ppl, struct ssh2_userauth_state, ppl); + container_of(ppl, struct ssh2_userauth_state, ppl); if (s->want_user_input) queue_idempotent_callback(&s->ppl.ic_process_queue); } @@ -1668,6 +1668,6 @@ static void ssh2_userauth_got_user_input(PacketProtocolLayer *ppl) static void ssh2_userauth_reconfigure(PacketProtocolLayer *ppl, Conf *conf) { struct ssh2_userauth_state *s = - FROMFIELD(ppl, struct ssh2_userauth_state, ppl); + container_of(ppl, struct ssh2_userauth_state, ppl); ssh_ppl_reconfigure(s->successor_layer, conf); } diff --git a/sshaes.c b/sshaes.c index 06e82f54..0790fc61 100644 --- a/sshaes.c +++ b/sshaes.c @@ -1054,38 +1054,38 @@ ssh2_cipher *aes_ssh2_new(const struct ssh2_cipheralg *alg) static void aes_ssh2_free(ssh2_cipher *cipher) { - struct aes_ssh2_ctx *ctx = FROMFIELD(cipher, struct aes_ssh2_ctx, vt); + struct aes_ssh2_ctx *ctx = container_of(cipher, struct aes_ssh2_ctx, vt); smemclr(ctx, sizeof(*ctx)); sfree(ctx); } static void aes_ssh2_setiv(ssh2_cipher *cipher, const void *iv) { - struct aes_ssh2_ctx *ctx = FROMFIELD(cipher, struct aes_ssh2_ctx, vt); + struct aes_ssh2_ctx *ctx = container_of(cipher, struct aes_ssh2_ctx, vt); aes_iv(&ctx->context, iv); } static void aes_ssh2_setkey(ssh2_cipher *cipher, const void *key) { - struct aes_ssh2_ctx *ctx = FROMFIELD(cipher, struct aes_ssh2_ctx, vt); + struct aes_ssh2_ctx *ctx = container_of(cipher, struct aes_ssh2_ctx, vt); aes_setup(&ctx->context, key, ctx->vt->padded_keybytes); } static void aes_ssh2_encrypt(ssh2_cipher *cipher, void *blk, int len) { - struct aes_ssh2_ctx *ctx = FROMFIELD(cipher, struct aes_ssh2_ctx, vt); + struct aes_ssh2_ctx *ctx = container_of(cipher, struct aes_ssh2_ctx, vt); aes_encrypt_cbc(blk, len, &ctx->context); } static void aes_ssh2_decrypt(ssh2_cipher *cipher, void *blk, int len) { - struct aes_ssh2_ctx *ctx = FROMFIELD(cipher, struct aes_ssh2_ctx, vt); + struct aes_ssh2_ctx *ctx = container_of(cipher, struct aes_ssh2_ctx, vt); aes_decrypt_cbc(blk, len, &ctx->context); } static void aes_ssh2_sdctr_method(ssh2_cipher *cipher, void *blk, int len) { - struct aes_ssh2_ctx *ctx = FROMFIELD(cipher, struct aes_ssh2_ctx, vt); + struct aes_ssh2_ctx *ctx = container_of(cipher, struct aes_ssh2_ctx, vt); aes_sdctr(blk, len, &ctx->context); } diff --git a/ssharcf.c b/ssharcf.c index 3434459c..fe1282fa 100644 --- a/ssharcf.c +++ b/ssharcf.c @@ -71,7 +71,7 @@ static ssh2_cipher *arcfour_new(const struct ssh2_cipheralg *alg) static void arcfour_free(ssh2_cipher *cipher) { - ArcfourContext *ctx = FROMFIELD(cipher, ArcfourContext, vt); + ArcfourContext *ctx = container_of(cipher, ArcfourContext, vt); smemclr(ctx, sizeof(*ctx)); sfree(ctx); } @@ -92,14 +92,14 @@ static void arcfour_ssh2_setiv(ssh2_cipher *cipher, const void *key) static void arcfour_ssh2_setkey(ssh2_cipher *cipher, const void *key) { - ArcfourContext *ctx = FROMFIELD(cipher, ArcfourContext, vt); + ArcfourContext *ctx = container_of(cipher, ArcfourContext, vt); arcfour_setkey(ctx, key, ctx->vt->padded_keybytes); arcfour_stir(ctx); } static void arcfour_ssh2_block(ssh2_cipher *cipher, void *blk, int len) { - ArcfourContext *ctx = FROMFIELD(cipher, ArcfourContext, vt); + ArcfourContext *ctx = container_of(cipher, ArcfourContext, vt); arcfour_block(ctx, blk, len); } diff --git a/sshblowf.c b/sshblowf.c index f5460518..d1d53c11 100644 --- a/sshblowf.c +++ b/sshblowf.c @@ -589,7 +589,7 @@ static ssh1_cipher *blowfish_ssh1_new(void) static void blowfish_ssh1_free(ssh1_cipher *cipher) { struct blowfish_ssh1_ctx *ctx = - FROMFIELD(cipher, struct blowfish_ssh1_ctx, vt); + container_of(cipher, struct blowfish_ssh1_ctx, vt); smemclr(ctx, sizeof(*ctx)); sfree(ctx); } @@ -597,7 +597,7 @@ static void blowfish_ssh1_free(ssh1_cipher *cipher) static void blowfish_ssh1_sesskey(ssh1_cipher *cipher, const void *key) { struct blowfish_ssh1_ctx *ctx = - FROMFIELD(cipher, struct blowfish_ssh1_ctx, vt); + container_of(cipher, struct blowfish_ssh1_ctx, vt); blowfish_setkey(&ctx->contexts[0], key, SSH1_SESSION_KEY_LENGTH); ctx->contexts[0].iv0 = ctx->contexts[0].iv1 = 0; ctx->contexts[1] = ctx->contexts[0]; /* structure copy */ @@ -606,14 +606,14 @@ static void blowfish_ssh1_sesskey(ssh1_cipher *cipher, const void *key) static void blowfish_ssh1_encrypt_blk(ssh1_cipher *cipher, void *blk, int len) { struct blowfish_ssh1_ctx *ctx = - FROMFIELD(cipher, struct blowfish_ssh1_ctx, vt); + container_of(cipher, struct blowfish_ssh1_ctx, vt); blowfish_lsb_encrypt_cbc(blk, len, ctx->contexts); } static void blowfish_ssh1_decrypt_blk(ssh1_cipher *cipher, void *blk, int len) { struct blowfish_ssh1_ctx *ctx = - FROMFIELD(cipher, struct blowfish_ssh1_ctx, vt); + container_of(cipher, struct blowfish_ssh1_ctx, vt); blowfish_lsb_decrypt_cbc(blk, len, ctx->contexts+1); } @@ -632,7 +632,7 @@ static ssh2_cipher *blowfish_ssh2_new(const struct ssh2_cipheralg *alg) static void blowfish_ssh2_free(ssh2_cipher *cipher) { struct blowfish_ssh2_ctx *ctx = - FROMFIELD(cipher, struct blowfish_ssh2_ctx, vt); + container_of(cipher, struct blowfish_ssh2_ctx, vt); smemclr(ctx, sizeof(*ctx)); sfree(ctx); } @@ -640,35 +640,35 @@ static void blowfish_ssh2_free(ssh2_cipher *cipher) static void blowfish_ssh2_setiv(ssh2_cipher *cipher, const void *iv) { struct blowfish_ssh2_ctx *ctx = - FROMFIELD(cipher, struct blowfish_ssh2_ctx, vt); + container_of(cipher, struct blowfish_ssh2_ctx, vt); blowfish_iv(&ctx->context, iv); } static void blowfish_ssh2_setkey(ssh2_cipher *cipher, const void *key) { struct blowfish_ssh2_ctx *ctx = - FROMFIELD(cipher, struct blowfish_ssh2_ctx, vt); + container_of(cipher, struct blowfish_ssh2_ctx, vt); blowfish_setkey(&ctx->context, key, ctx->vt->padded_keybytes); } static void blowfish_ssh2_encrypt_blk(ssh2_cipher *cipher, void *blk, int len) { struct blowfish_ssh2_ctx *ctx = - FROMFIELD(cipher, struct blowfish_ssh2_ctx, vt); + container_of(cipher, struct blowfish_ssh2_ctx, vt); blowfish_msb_encrypt_cbc(blk, len, &ctx->context); } static void blowfish_ssh2_decrypt_blk(ssh2_cipher *cipher, void *blk, int len) { struct blowfish_ssh2_ctx *ctx = - FROMFIELD(cipher, struct blowfish_ssh2_ctx, vt); + container_of(cipher, struct blowfish_ssh2_ctx, vt); blowfish_msb_decrypt_cbc(blk, len, &ctx->context); } static void blowfish_ssh2_sdctr(ssh2_cipher *cipher, void *blk, int len) { struct blowfish_ssh2_ctx *ctx = - FROMFIELD(cipher, struct blowfish_ssh2_ctx, vt); + container_of(cipher, struct blowfish_ssh2_ctx, vt); blowfish_msb_sdctr(blk, len, &ctx->context); } diff --git a/sshccp.c b/sshccp.c index dfcb02c8..4b26a438 100644 --- a/sshccp.c +++ b/sshccp.c @@ -873,7 +873,7 @@ struct ccp_context { static ssh2_mac *poly_ssh2_new( const struct ssh2_macalg *alg, ssh2_cipher *cipher) { - struct ccp_context *ctx = FROMFIELD(cipher, struct ccp_context, cvt); + struct ccp_context *ctx = container_of(cipher, struct ccp_context, cvt); ctx->mac_if.vt = alg; BinarySink_DELEGATE_INIT(&ctx->mac_if, ctx); return &ctx->mac_if; @@ -891,7 +891,7 @@ static void poly_setkey(ssh2_mac *mac, const void *key) static void poly_start(ssh2_mac *mac) { - struct ccp_context *ctx = FROMFIELD(mac, struct ccp_context, mac_if); + struct ccp_context *ctx = container_of(mac, struct ccp_context, mac_if); ctx->mac_initialised = 0; memset(ctx->mac_iv, 0, 8); @@ -933,7 +933,7 @@ static void poly_BinarySink_write(BinarySink *bs, const void *blkv, size_t len) static void poly_genresult(ssh2_mac *mac, unsigned char *blk) { - struct ccp_context *ctx = FROMFIELD(mac, struct ccp_context, mac_if); + struct ccp_context *ctx = container_of(mac, struct ccp_context, mac_if); poly1305_finalise(&ctx->mac, blk); } @@ -956,7 +956,7 @@ static ssh2_cipher *ccp_new(const struct ssh2_cipheralg *alg) static void ccp_free(ssh2_cipher *cipher) { - struct ccp_context *ctx = FROMFIELD(cipher, struct ccp_context, cvt); + struct ccp_context *ctx = container_of(cipher, struct ccp_context, cvt); smemclr(&ctx->a_cipher, sizeof(ctx->a_cipher)); smemclr(&ctx->b_cipher, sizeof(ctx->b_cipher)); smemclr(&ctx->mac, sizeof(ctx->mac)); @@ -965,14 +965,15 @@ static void ccp_free(ssh2_cipher *cipher) static void ccp_iv(ssh2_cipher *cipher, const void *iv) { - /* struct ccp_context *ctx = FROMFIELD(cipher, struct ccp_context, cvt); */ + /* struct ccp_context *ctx = + container_of(cipher, struct ccp_context, cvt); */ /* IV is set based on the sequence number */ } static void ccp_key(ssh2_cipher *cipher, const void *vkey) { const unsigned char *key = (const unsigned char *)vkey; - struct ccp_context *ctx = FROMFIELD(cipher, struct ccp_context, cvt); + struct ccp_context *ctx = container_of(cipher, struct ccp_context, cvt); /* Initialise the a_cipher (for decrypting lengths) with the first 256 bits */ chacha20_key(&ctx->a_cipher, key + 32); /* Initialise the b_cipher (for content and MAC) with the second 256 bits */ @@ -981,13 +982,13 @@ static void ccp_key(ssh2_cipher *cipher, const void *vkey) static void ccp_encrypt(ssh2_cipher *cipher, void *blk, int len) { - struct ccp_context *ctx = FROMFIELD(cipher, struct ccp_context, cvt); + struct ccp_context *ctx = container_of(cipher, struct ccp_context, cvt); chacha20_encrypt(&ctx->b_cipher, blk, len); } static void ccp_decrypt(ssh2_cipher *cipher, void *blk, int len) { - struct ccp_context *ctx = FROMFIELD(cipher, struct ccp_context, cvt); + struct ccp_context *ctx = container_of(cipher, struct ccp_context, cvt); chacha20_decrypt(&ctx->b_cipher, blk, len); } @@ -1011,7 +1012,7 @@ static void ccp_length_op(struct ccp_context *ctx, void *blk, int len, static void ccp_encrypt_length(ssh2_cipher *cipher, void *blk, int len, unsigned long seq) { - struct ccp_context *ctx = FROMFIELD(cipher, struct ccp_context, cvt); + struct ccp_context *ctx = container_of(cipher, struct ccp_context, cvt); ccp_length_op(ctx, blk, len, seq); chacha20_encrypt(&ctx->a_cipher, blk, len); } @@ -1019,7 +1020,7 @@ static void ccp_encrypt_length(ssh2_cipher *cipher, void *blk, int len, static void ccp_decrypt_length(ssh2_cipher *cipher, void *blk, int len, unsigned long seq) { - struct ccp_context *ctx = FROMFIELD(cipher, struct ccp_context, cvt); + struct ccp_context *ctx = container_of(cipher, struct ccp_context, cvt); ccp_length_op(ctx, blk, len, seq); chacha20_decrypt(&ctx->a_cipher, blk, len); } diff --git a/sshcommon.c b/sshcommon.c index ac4a6715..f7007ea9 100644 --- a/sshcommon.c +++ b/sshcommon.c @@ -59,7 +59,7 @@ static void pktin_free_queue_callback(void *vctx) { while (pktin_freeq_head.next != &pktin_freeq_head) { PacketQueueNode *node = pktin_freeq_head.next; - PktIn *pktin = FROMFIELD(node, PktIn, qnode); + PktIn *pktin = container_of(node, PktIn, qnode); pktin_freeq_head.next = node->next; sfree(pktin); } @@ -89,7 +89,7 @@ static PktIn *pq_in_get(PacketQueueBase *pqb, int pop) queue_idempotent_callback(&ic_pktin_free); } - return FROMFIELD(node, PktIn, qnode); + return container_of(node, PktIn, qnode); } static PktOut *pq_out_get(PacketQueueBase *pqb, int pop) @@ -104,7 +104,7 @@ static PktOut *pq_out_get(PacketQueueBase *pqb, int pop) node->prev = node->next = NULL; } - return FROMFIELD(node, PktOut, qnode); + return container_of(node, PktOut, qnode); } void pq_in_init(PktInQueue *pq) diff --git a/sshdes.c b/sshdes.c index d35c894e..b69e9bc0 100644 --- a/sshdes.c +++ b/sshdes.c @@ -800,53 +800,53 @@ static ssh1_cipher *des_ssh1_new(void) static void des3_ssh1_free(ssh1_cipher *cipher) { - struct des3_ssh1_ctx *ctx = FROMFIELD(cipher, struct des3_ssh1_ctx, vt); + struct des3_ssh1_ctx *ctx = container_of(cipher, struct des3_ssh1_ctx, vt); smemclr(ctx, sizeof(*ctx)); sfree(ctx); } static void des_ssh1_free(ssh1_cipher *cipher) { - struct des_ssh1_ctx *ctx = FROMFIELD(cipher, struct des_ssh1_ctx, vt); + struct des_ssh1_ctx *ctx = container_of(cipher, struct des_ssh1_ctx, vt); smemclr(ctx, sizeof(*ctx)); sfree(ctx); } static void des3_ssh1_sesskey(ssh1_cipher *cipher, const void *key) { - struct des3_ssh1_ctx *ctx = FROMFIELD(cipher, struct des3_ssh1_ctx, vt); + struct des3_ssh1_ctx *ctx = container_of(cipher, struct des3_ssh1_ctx, vt); des3_key(ctx->contexts, key); des3_key(ctx->contexts+3, key); } static void des3_ssh1_encrypt_blk(ssh1_cipher *cipher, void *blk, int len) { - struct des3_ssh1_ctx *ctx = FROMFIELD(cipher, struct des3_ssh1_ctx, vt); + struct des3_ssh1_ctx *ctx = container_of(cipher, struct des3_ssh1_ctx, vt); des_3cbc_encrypt(blk, len, ctx->contexts); } static void des3_ssh1_decrypt_blk(ssh1_cipher *cipher, void *blk, int len) { - struct des3_ssh1_ctx *ctx = FROMFIELD(cipher, struct des3_ssh1_ctx, vt); + struct des3_ssh1_ctx *ctx = container_of(cipher, struct des3_ssh1_ctx, vt); des_3cbc_decrypt(blk, len, ctx->contexts+3); } static void des_ssh1_sesskey(ssh1_cipher *cipher, const void *key) { - struct des_ssh1_ctx *ctx = FROMFIELD(cipher, struct des_ssh1_ctx, vt); + struct des_ssh1_ctx *ctx = container_of(cipher, struct des_ssh1_ctx, vt); des_key(ctx->contexts, key); des_key(ctx->contexts+1, key); } static void des_ssh1_encrypt_blk(ssh1_cipher *cipher, void *blk, int len) { - struct des_ssh1_ctx *ctx = FROMFIELD(cipher, struct des_ssh1_ctx, vt); + struct des_ssh1_ctx *ctx = container_of(cipher, struct des_ssh1_ctx, vt); des_cbc_encrypt(blk, len, ctx->contexts); } static void des_ssh1_decrypt_blk(ssh1_cipher *cipher, void *blk, int len) { - struct des_ssh1_ctx *ctx = FROMFIELD(cipher, struct des_ssh1_ctx, vt); + struct des_ssh1_ctx *ctx = container_of(cipher, struct des_ssh1_ctx, vt); des_cbc_decrypt(blk, len, ctx->contexts+1); } @@ -876,21 +876,21 @@ static ssh2_cipher *des_ssh2_new(const struct ssh2_cipheralg *alg) static void des3_ssh2_free(ssh2_cipher *cipher) { - struct des3_ssh2_ctx *ctx = FROMFIELD(cipher, struct des3_ssh2_ctx, vt); + struct des3_ssh2_ctx *ctx = container_of(cipher, struct des3_ssh2_ctx, vt); smemclr(ctx, sizeof(*ctx)); sfree(ctx); } static void des_ssh2_free(ssh2_cipher *cipher) { - struct des_ssh2_ctx *ctx = FROMFIELD(cipher, struct des_ssh2_ctx, vt); + struct des_ssh2_ctx *ctx = container_of(cipher, struct des_ssh2_ctx, vt); smemclr(ctx, sizeof(*ctx)); sfree(ctx); } static void des3_ssh2_setiv(ssh2_cipher *cipher, const void *iv) { - struct des3_ssh2_ctx *ctx = FROMFIELD(cipher, struct des3_ssh2_ctx, vt); + struct des3_ssh2_ctx *ctx = container_of(cipher, struct des3_ssh2_ctx, vt); des_iv(&ctx->contexts[0], iv); /* SSH-2 treats triple-DES as a single block cipher to wrap in * CBC, so there's only one IV required, not three */ @@ -898,49 +898,49 @@ static void des3_ssh2_setiv(ssh2_cipher *cipher, const void *iv) static void des3_ssh2_setkey(ssh2_cipher *cipher, const void *key) { - struct des3_ssh2_ctx *ctx = FROMFIELD(cipher, struct des3_ssh2_ctx, vt); + struct des3_ssh2_ctx *ctx = container_of(cipher, struct des3_ssh2_ctx, vt); des3_key(ctx->contexts, key); } static void des_ssh2_setiv(ssh2_cipher *cipher, const void *iv) { - struct des_ssh2_ctx *ctx = FROMFIELD(cipher, struct des_ssh2_ctx, vt); + struct des_ssh2_ctx *ctx = container_of(cipher, struct des_ssh2_ctx, vt); des_iv(&ctx->context, iv); } static void des_ssh2_setkey(ssh2_cipher *cipher, const void *key) { - struct des_ssh2_ctx *ctx = FROMFIELD(cipher, struct des_ssh2_ctx, vt); + struct des_ssh2_ctx *ctx = container_of(cipher, struct des_ssh2_ctx, vt); des_key(&ctx->context, key); } static void des3_ssh2_encrypt_blk(ssh2_cipher *cipher, void *blk, int len) { - struct des3_ssh2_ctx *ctx = FROMFIELD(cipher, struct des3_ssh2_ctx, vt); + struct des3_ssh2_ctx *ctx = container_of(cipher, struct des3_ssh2_ctx, vt); des_cbc3_encrypt(blk, len, ctx->contexts); } static void des3_ssh2_decrypt_blk(ssh2_cipher *cipher, void *blk, int len) { - struct des3_ssh2_ctx *ctx = FROMFIELD(cipher, struct des3_ssh2_ctx, vt); + struct des3_ssh2_ctx *ctx = container_of(cipher, struct des3_ssh2_ctx, vt); des_cbc3_decrypt(blk, len, ctx->contexts); } static void des3_ssh2_sdctr(ssh2_cipher *cipher, void *blk, int len) { - struct des3_ssh2_ctx *ctx = FROMFIELD(cipher, struct des3_ssh2_ctx, vt); + struct des3_ssh2_ctx *ctx = container_of(cipher, struct des3_ssh2_ctx, vt); des_sdctr3(blk, len, ctx->contexts); } static void des_ssh2_encrypt_blk(ssh2_cipher *cipher, void *blk, int len) { - struct des_ssh2_ctx *ctx = FROMFIELD(cipher, struct des_ssh2_ctx, vt); + struct des_ssh2_ctx *ctx = container_of(cipher, struct des_ssh2_ctx, vt); des_cbc_encrypt(blk, len, &ctx->context); } static void des_ssh2_decrypt_blk(ssh2_cipher *cipher, void *blk, int len) { - struct des_ssh2_ctx *ctx = FROMFIELD(cipher, struct des_ssh2_ctx, vt); + struct des_ssh2_ctx *ctx = container_of(cipher, struct des_ssh2_ctx, vt); des_cbc_decrypt(blk, len, &ctx->context); } diff --git a/sshdss.c b/sshdss.c index c4686645..3aa462b8 100644 --- a/sshdss.c +++ b/sshdss.c @@ -40,7 +40,7 @@ static ssh_key *dss_new_pub(const ssh_keyalg *self, ptrlen data) static void dss_freekey(ssh_key *key) { - struct dss_key *dss = FROMFIELD(key, struct dss_key, sshk); + struct dss_key *dss = container_of(key, struct dss_key, sshk); if (dss->p) freebn(dss->p); if (dss->q) @@ -56,7 +56,7 @@ static void dss_freekey(ssh_key *key) static char *dss_cache_str(ssh_key *key) { - struct dss_key *dss = FROMFIELD(key, struct dss_key, sshk); + struct dss_key *dss = container_of(key, struct dss_key, sshk); char *p; int len, i, pos, nibbles; static const char hex[] = "0123456789abcdef"; @@ -106,7 +106,7 @@ static char *dss_cache_str(ssh_key *key) static int dss_verify(ssh_key *key, ptrlen sig, ptrlen data) { - struct dss_key *dss = FROMFIELD(key, struct dss_key, sshk); + struct dss_key *dss = container_of(key, struct dss_key, sshk); BinarySource src[1]; unsigned char hash[20]; Bignum r, s, w, gu1p, yu2p, gu1yu2p, u1, u2, sha, v; @@ -206,7 +206,7 @@ static int dss_verify(ssh_key *key, ptrlen sig, ptrlen data) static void dss_public_blob(ssh_key *key, BinarySink *bs) { - struct dss_key *dss = FROMFIELD(key, struct dss_key, sshk); + struct dss_key *dss = container_of(key, struct dss_key, sshk); put_stringz(bs, "ssh-dss"); put_mp_ssh2(bs, dss->p); @@ -217,7 +217,7 @@ static void dss_public_blob(ssh_key *key, BinarySink *bs) static void dss_private_blob(ssh_key *key, BinarySink *bs) { - struct dss_key *dss = FROMFIELD(key, struct dss_key, sshk); + struct dss_key *dss = container_of(key, struct dss_key, sshk); put_mp_ssh2(bs, dss->x); } @@ -236,7 +236,7 @@ static ssh_key *dss_new_priv(const ssh_keyalg *self, ptrlen pub, ptrlen priv) if (!sshk) return NULL; - dss = FROMFIELD(sshk, struct dss_key, sshk); + dss = container_of(sshk, struct dss_key, sshk); BinarySource_BARE_INIT(src, priv.ptr, priv.len); dss->x = get_mp_ssh2(src); if (get_err(src)) { @@ -300,7 +300,7 @@ static ssh_key *dss_new_priv_openssh(const ssh_keyalg *self, static void dss_openssh_blob(ssh_key *key, BinarySink *bs) { - struct dss_key *dss = FROMFIELD(key, struct dss_key, sshk); + struct dss_key *dss = container_of(key, struct dss_key, sshk); put_mp_ssh2(bs, dss->p); put_mp_ssh2(bs, dss->q); @@ -319,7 +319,7 @@ static int dss_pubkey_bits(const ssh_keyalg *self, ptrlen pub) if (!sshk) return -1; - dss = FROMFIELD(sshk, struct dss_key, sshk); + dss = container_of(sshk, struct dss_key, sshk); ret = bignum_bitcount(dss->p); dss_freekey(&dss->sshk); @@ -449,7 +449,7 @@ Bignum *dss_gen_k(const char *id_string, Bignum modulus, Bignum private_key, static void dss_sign(ssh_key *key, const void *data, int datalen, BinarySink *bs) { - struct dss_key *dss = FROMFIELD(key, struct dss_key, sshk); + struct dss_key *dss = container_of(key, struct dss_key, sshk); Bignum k, gkp, hash, kinv, hxr, r, s; unsigned char digest[20]; int i; diff --git a/sshecc.c b/sshecc.c index 34d0e948..2806ea51 100644 --- a/sshecc.c +++ b/sshecc.c @@ -1700,7 +1700,7 @@ static void ecdsa_freekey(ssh_key *key) struct ec_key *ec; if (!key) return; - ec = FROMFIELD(key, struct ec_key, sshk); + ec = container_of(key, struct ec_key, sshk); if (ec->publicKey.x) freebn(ec->publicKey.x); @@ -1760,7 +1760,7 @@ static ssh_key *ecdsa_new_pub(const ssh_keyalg *self, ptrlen data) static char *ecdsa_cache_str(ssh_key *key) { - struct ec_key *ec = FROMFIELD(key, struct ec_key, sshk); + struct ec_key *ec = container_of(key, struct ec_key, sshk); char *p; int len, i, pos, nibbles; static const char hex[] = "0123456789abcdef"; @@ -1799,7 +1799,7 @@ static char *ecdsa_cache_str(ssh_key *key) static void ecdsa_public_blob(ssh_key *key, BinarySink *bs) { - struct ec_key *ec = FROMFIELD(key, struct ec_key, sshk); + struct ec_key *ec = container_of(key, struct ec_key, sshk); int pointlen; int i; @@ -1839,7 +1839,7 @@ static void ecdsa_public_blob(ssh_key *key, BinarySink *bs) static void ecdsa_private_blob(ssh_key *key, BinarySink *bs) { - struct ec_key *ec = FROMFIELD(key, struct ec_key, sshk); + struct ec_key *ec = container_of(key, struct ec_key, sshk); int keylen; int i; @@ -1875,7 +1875,7 @@ static ssh_key *ecdsa_new_priv(const ssh_keyalg *self, ptrlen pub, ptrlen priv) if (!sshk) return NULL; - ec = FROMFIELD(sshk, struct ec_key, sshk); + ec = container_of(sshk, struct ec_key, sshk); BinarySource_BARE_INIT(src, priv.ptr, priv.len); if (ec->publicKey.curve->type != EC_WEIERSTRASS @@ -1967,7 +1967,7 @@ static ssh_key *ed25519_new_priv_openssh(const ssh_keyalg *self, static void ed25519_openssh_blob(ssh_key *key, BinarySink *bs) { - struct ec_key *ec = FROMFIELD(key, struct ec_key, sshk); + struct ec_key *ec = container_of(key, struct ec_key, sshk); strbuf *pub; int pointlen; @@ -2068,7 +2068,7 @@ static ssh_key *ecdsa_new_priv_openssh(const ssh_keyalg *self, static void ecdsa_openssh_blob(ssh_key *key, BinarySink *bs) { - struct ec_key *ec = FROMFIELD(key, struct ec_key, sshk); + struct ec_key *ec = container_of(key, struct ec_key, sshk); int pointlen; int i; @@ -2099,7 +2099,7 @@ static int ecdsa_pubkey_bits(const ssh_keyalg *self, ptrlen blob) if (!sshk) return -1; - ec = FROMFIELD(sshk, struct ec_key, sshk); + ec = container_of(sshk, struct ec_key, sshk); ret = ec->publicKey.curve->fieldBits; ecdsa_freekey(&ec->sshk); @@ -2108,7 +2108,7 @@ static int ecdsa_pubkey_bits(const ssh_keyalg *self, ptrlen blob) static int ecdsa_verify(ssh_key *key, ptrlen sig, ptrlen data) { - struct ec_key *ec = FROMFIELD(key, struct ec_key, sshk); + struct ec_key *ec = container_of(key, struct ec_key, sshk); const struct ecsign_extra *extra = (const struct ecsign_extra *)ec->sshk->extra; BinarySource src[1]; @@ -2258,7 +2258,7 @@ static int ecdsa_verify(ssh_key *key, ptrlen sig, ptrlen data) static void ecdsa_sign(ssh_key *key, const void *data, int datalen, BinarySink *bs) { - struct ec_key *ec = FROMFIELD(key, struct ec_key, sshk); + struct ec_key *ec = container_of(key, struct ec_key, sshk); const struct ecsign_extra *extra = (const struct ecsign_extra *)ec->sshk->extra; unsigned char digest[512 / 8]; diff --git a/sshmd5.c b/sshmd5.c index 35a21df4..743df03f 100644 --- a/sshmd5.c +++ b/sshmd5.c @@ -256,7 +256,8 @@ void hmacmd5_free_context(struct hmacmd5_context *ctx) static void hmacmd5_ssh2_free(ssh2_mac *mac) { - struct hmacmd5_context *ctx = FROMFIELD(mac, struct hmacmd5_context, mac); + struct hmacmd5_context *ctx = + container_of(mac, struct hmacmd5_context, mac); hmacmd5_free_context(ctx); } @@ -283,13 +284,15 @@ void hmacmd5_key(struct hmacmd5_context *ctx, void const *keyv, int len) static void hmacmd5_ssh2_setkey(ssh2_mac *mac, const void *key) { - struct hmacmd5_context *ctx = FROMFIELD(mac, struct hmacmd5_context, mac); + struct hmacmd5_context *ctx = + container_of(mac, struct hmacmd5_context, mac); hmacmd5_key(ctx, key, ctx->mac.vt->keylen); } static void hmacmd5_start(ssh2_mac *mac) { - struct hmacmd5_context *ctx = FROMFIELD(mac, struct hmacmd5_context, mac); + struct hmacmd5_context *ctx = + container_of(mac, struct hmacmd5_context, mac); ctx->md5[2] = ctx->md5[0]; /* structure copy */ BinarySink_COPIED(&ctx->md5[2]); @@ -297,7 +300,8 @@ static void hmacmd5_start(ssh2_mac *mac) static void hmacmd5_genresult(ssh2_mac *mac, unsigned char *hmac) { - struct hmacmd5_context *ctx = FROMFIELD(mac, struct hmacmd5_context, mac); + struct hmacmd5_context *ctx = + container_of(mac, struct hmacmd5_context, mac); struct MD5Context s; unsigned char intermediate[16]; diff --git a/sshrsa.c b/sshrsa.c index c2bc4bfb..4d4ea5b1 100644 --- a/sshrsa.c +++ b/sshrsa.c @@ -501,14 +501,14 @@ static ssh_key *rsa2_new_pub(const ssh_keyalg *self, ptrlen data) static void rsa2_freekey(ssh_key *key) { - struct RSAKey *rsa = FROMFIELD(key, struct RSAKey, sshk); + struct RSAKey *rsa = container_of(key, struct RSAKey, sshk); freersakey(rsa); sfree(rsa); } static char *rsa2_cache_str(ssh_key *key) { - struct RSAKey *rsa = FROMFIELD(key, struct RSAKey, sshk); + struct RSAKey *rsa = container_of(key, struct RSAKey, sshk); char *p; int len; @@ -520,7 +520,7 @@ static char *rsa2_cache_str(ssh_key *key) static void rsa2_public_blob(ssh_key *key, BinarySink *bs) { - struct RSAKey *rsa = FROMFIELD(key, struct RSAKey, sshk); + struct RSAKey *rsa = container_of(key, struct RSAKey, sshk); put_stringz(bs, "ssh-rsa"); put_mp_ssh2(bs, rsa->exponent); @@ -529,7 +529,7 @@ static void rsa2_public_blob(ssh_key *key, BinarySink *bs) static void rsa2_private_blob(ssh_key *key, BinarySink *bs) { - struct RSAKey *rsa = FROMFIELD(key, struct RSAKey, sshk); + struct RSAKey *rsa = container_of(key, struct RSAKey, sshk); put_mp_ssh2(bs, rsa->private_exponent); put_mp_ssh2(bs, rsa->p); @@ -548,7 +548,7 @@ static ssh_key *rsa2_new_priv(const ssh_keyalg *self, if (!sshk) return NULL; - rsa = FROMFIELD(sshk, struct RSAKey, sshk); + rsa = container_of(sshk, struct RSAKey, sshk); BinarySource_BARE_INIT(src, priv.ptr, priv.len); rsa->private_exponent = get_mp_ssh2(src); rsa->p = get_mp_ssh2(src); @@ -589,7 +589,7 @@ static ssh_key *rsa2_new_priv_openssh(const ssh_keyalg *self, static void rsa2_openssh_blob(ssh_key *key, BinarySink *bs) { - struct RSAKey *rsa = FROMFIELD(key, struct RSAKey, sshk); + struct RSAKey *rsa = container_of(key, struct RSAKey, sshk); put_mp_ssh2(bs, rsa->modulus); put_mp_ssh2(bs, rsa->exponent); @@ -609,7 +609,7 @@ static int rsa2_pubkey_bits(const ssh_keyalg *self, ptrlen pub) if (!sshk) return -1; - rsa = FROMFIELD(sshk, struct RSAKey, sshk); + rsa = container_of(sshk, struct RSAKey, sshk); ret = bignum_bitcount(rsa->modulus); rsa2_freekey(&rsa->sshk); @@ -649,7 +649,7 @@ static const unsigned char asn1_weird_stuff[] = { static int rsa2_verify(ssh_key *key, ptrlen sig, ptrlen data) { - struct RSAKey *rsa = FROMFIELD(key, struct RSAKey, sshk); + struct RSAKey *rsa = container_of(key, struct RSAKey, sshk); BinarySource src[1]; ptrlen type, in_pl; Bignum in, out; @@ -709,7 +709,7 @@ static int rsa2_verify(ssh_key *key, ptrlen sig, ptrlen data) static void rsa2_sign(ssh_key *key, const void *data, int datalen, BinarySink *bs) { - struct RSAKey *rsa = FROMFIELD(key, struct RSAKey, sshk); + struct RSAKey *rsa = container_of(key, struct RSAKey, sshk); unsigned char *bytes; int nbytes; unsigned char hash[20]; @@ -770,7 +770,7 @@ struct RSAKey *ssh_rsakex_newkey(const void *data, int len) ssh_key *sshk = rsa2_new_pub(&ssh_rsa, make_ptrlen(data, len)); if (!sshk) return NULL; - return FROMFIELD(sshk, struct RSAKey, sshk); + return container_of(sshk, struct RSAKey, sshk); } void ssh_rsakex_freekey(struct RSAKey *key) diff --git a/sshsh256.c b/sshsh256.c index 75a04495..dbdfbcf0 100644 --- a/sshsh256.c +++ b/sshsh256.c @@ -223,8 +223,8 @@ static ssh_hash *sha256_copy(ssh_hash *hashold) struct sha256_hash *hold, *hnew; ssh_hash *hashnew = sha256_new(hashold->vt); - hold = FROMFIELD(hashold, struct sha256_hash, hash); - hnew = FROMFIELD(hashnew, struct sha256_hash, hash); + hold = container_of(hashold, struct sha256_hash, hash); + hnew = container_of(hashnew, struct sha256_hash, hash); hnew->state = hold->state; BinarySink_COPIED(&hnew->state); @@ -234,7 +234,7 @@ static ssh_hash *sha256_copy(ssh_hash *hashold) static void sha256_free(ssh_hash *hash) { - struct sha256_hash *h = FROMFIELD(hash, struct sha256_hash, hash); + struct sha256_hash *h = container_of(hash, struct sha256_hash, hash); smemclr(h, sizeof(*h)); sfree(h); @@ -242,7 +242,7 @@ static void sha256_free(ssh_hash *hash) static void sha256_final(ssh_hash *hash, unsigned char *output) { - struct sha256_hash *h = FROMFIELD(hash, struct sha256_hash, hash); + struct sha256_hash *h = container_of(hash, struct sha256_hash, hash); SHA256_Final(&h->state, output); sha256_free(hash); } @@ -272,7 +272,7 @@ static ssh2_mac *hmacsha256_new( static void hmacsha256_free(ssh2_mac *mac) { - struct hmacsha256 *ctx = FROMFIELD(mac, struct hmacsha256, mac); + struct hmacsha256 *ctx = container_of(mac, struct hmacsha256, mac); smemclr(ctx, sizeof(*ctx)); sfree(ctx); } @@ -300,13 +300,13 @@ static void sha256_key_internal(struct hmacsha256 *ctx, static void hmacsha256_key(ssh2_mac *mac, const void *key) { - struct hmacsha256 *ctx = FROMFIELD(mac, struct hmacsha256, mac); + struct hmacsha256 *ctx = container_of(mac, struct hmacsha256, mac); sha256_key_internal(ctx, key, ctx->mac.vt->keylen); } static void hmacsha256_start(ssh2_mac *mac) { - struct hmacsha256 *ctx = FROMFIELD(mac, struct hmacsha256, mac); + struct hmacsha256 *ctx = container_of(mac, struct hmacsha256, mac); ctx->sha[2] = ctx->sha[0]; /* structure copy */ BinarySink_COPIED(&ctx->sha[2]); @@ -314,7 +314,7 @@ static void hmacsha256_start(ssh2_mac *mac) static void hmacsha256_genresult(ssh2_mac *mac, unsigned char *hmac) { - struct hmacsha256 *ctx = FROMFIELD(mac, struct hmacsha256, mac); + struct hmacsha256 *ctx = container_of(mac, struct hmacsha256, mac); SHA256_State s; unsigned char intermediate[32]; diff --git a/sshsh512.c b/sshsh512.c index 85df1f29..b518f6a5 100644 --- a/sshsh512.c +++ b/sshsh512.c @@ -346,8 +346,8 @@ static ssh_hash *sha512_copy(ssh_hash *hashold) struct sha512_hash *hold, *hnew; ssh_hash *hashnew = sha512_new(hashold->vt); - hold = FROMFIELD(hashold, struct sha512_hash, hash); - hnew = FROMFIELD(hashnew, struct sha512_hash, hash); + hold = container_of(hashold, struct sha512_hash, hash); + hnew = container_of(hashnew, struct sha512_hash, hash); hnew->state = hold->state; BinarySink_COPIED(&hnew->state); @@ -357,7 +357,7 @@ static ssh_hash *sha512_copy(ssh_hash *hashold) static void sha512_free(ssh_hash *hash) { - struct sha512_hash *h = FROMFIELD(hash, struct sha512_hash, hash); + struct sha512_hash *h = container_of(hash, struct sha512_hash, hash); smemclr(h, sizeof(*h)); sfree(h); @@ -365,7 +365,7 @@ static void sha512_free(ssh_hash *hash) static void sha512_final(ssh_hash *hash, unsigned char *output) { - struct sha512_hash *h = FROMFIELD(hash, struct sha512_hash, hash); + struct sha512_hash *h = container_of(hash, struct sha512_hash, hash); SHA512_Final(&h->state, output); sha512_free(hash); } @@ -385,7 +385,7 @@ static ssh_hash *sha384_new(const struct ssh_hashalg *alg) static void sha384_final(ssh_hash *hash, unsigned char *output) { - struct sha512_hash *h = FROMFIELD(hash, struct sha512_hash, hash); + struct sha512_hash *h = container_of(hash, struct sha512_hash, hash); SHA384_Final(&h->state, output); sha512_free(hash); } diff --git a/sshsha.c b/sshsha.c index 282e98a3..a7f02791 100644 --- a/sshsha.c +++ b/sshsha.c @@ -251,8 +251,8 @@ static ssh_hash *sha1_copy(ssh_hash *hashold) struct sha1_hash *hold, *hnew; ssh_hash *hashnew = sha1_new(hashold->vt); - hold = FROMFIELD(hashold, struct sha1_hash, hash); - hnew = FROMFIELD(hashnew, struct sha1_hash, hash); + hold = container_of(hashold, struct sha1_hash, hash); + hnew = container_of(hashnew, struct sha1_hash, hash); hnew->state = hold->state; BinarySink_COPIED(&hnew->state); @@ -262,7 +262,7 @@ static ssh_hash *sha1_copy(ssh_hash *hashold) static void sha1_free(ssh_hash *hash) { - struct sha1_hash *h = FROMFIELD(hash, struct sha1_hash, hash); + struct sha1_hash *h = container_of(hash, struct sha1_hash, hash); smemclr(h, sizeof(*h)); sfree(h); @@ -270,7 +270,7 @@ static void sha1_free(ssh_hash *hash) static void sha1_final(ssh_hash *hash, unsigned char *output) { - struct sha1_hash *h = FROMFIELD(hash, struct sha1_hash, hash); + struct sha1_hash *h = container_of(hash, struct sha1_hash, hash); SHA_Final(&h->state, output); sha1_free(hash); } @@ -300,7 +300,7 @@ static ssh2_mac *hmacsha1_new( static void hmacsha1_free(ssh2_mac *mac) { - struct hmacsha1 *ctx = FROMFIELD(mac, struct hmacsha1, mac); + struct hmacsha1 *ctx = container_of(mac, struct hmacsha1, mac); smemclr(ctx, sizeof(*ctx)); sfree(ctx); } @@ -328,7 +328,7 @@ static void sha1_key_internal(SHA_State *keys, static void hmacsha1_key(ssh2_mac *mac, const void *key) { - struct hmacsha1 *ctx = FROMFIELD(mac, struct hmacsha1, mac); + struct hmacsha1 *ctx = container_of(mac, struct hmacsha1, mac); /* Reading the key length out of the ssh2_macalg structure means * this same method can be used for the _buggy variants which use * a shorter key */ @@ -337,7 +337,7 @@ static void hmacsha1_key(ssh2_mac *mac, const void *key) static void hmacsha1_start(ssh2_mac *mac) { - struct hmacsha1 *ctx = FROMFIELD(mac, struct hmacsha1, mac); + struct hmacsha1 *ctx = container_of(mac, struct hmacsha1, mac); ctx->sha[2] = ctx->sha[0]; /* structure copy */ BinarySink_COPIED(&ctx->sha[2]); @@ -345,7 +345,7 @@ static void hmacsha1_start(ssh2_mac *mac) static void hmacsha1_genresult(ssh2_mac *mac, unsigned char *hmac) { - struct hmacsha1 *ctx = FROMFIELD(mac, struct hmacsha1, mac); + struct hmacsha1 *ctx = container_of(mac, struct hmacsha1, mac); SHA_State s; unsigned char intermediate[20]; diff --git a/sshshare.c b/sshshare.c index 0f35635e..688f73b2 100644 --- a/sshshare.c +++ b/sshshare.c @@ -950,7 +950,7 @@ static void share_disconnect(struct ssh_sharing_connstate *cs, static void share_closing(Plug *plug, const char *error_msg, int error_code, int calling_back) { - struct ssh_sharing_connstate *cs = FROMFIELD( + struct ssh_sharing_connstate *cs = container_of( plug, struct ssh_sharing_connstate, plug); if (error_msg) { @@ -1766,7 +1766,7 @@ static void share_got_pkt_from_downstream(struct ssh_sharing_connstate *cs, static void share_receive(Plug *plug, int urgent, char *data, int len) { - ssh_sharing_connstate *cs = FROMFIELD( + ssh_sharing_connstate *cs = container_of( plug, ssh_sharing_connstate, plug); static const char expected_verstring_prefix[] = "SSHCONNECTION@putty.projects.tartarus.org-2.0-"; @@ -1842,7 +1842,7 @@ static void share_receive(Plug *plug, int urgent, char *data, int len) static void share_sent(Plug *plug, int bufsize) { - /* ssh_sharing_connstate *cs = FROMFIELD( + /* ssh_sharing_connstate *cs = container_of( plug, ssh_sharing_connstate, plug); */ /* @@ -1858,7 +1858,8 @@ static void share_sent(Plug *plug, int bufsize) static void share_listen_closing(Plug *plug, const char *error_msg, int error_code, int calling_back) { - ssh_sharing_state *sharestate = FROMFIELD(plug, ssh_sharing_state, plug); + ssh_sharing_state *sharestate = + container_of(plug, ssh_sharing_state, plug); if (error_msg) log_general(sharestate, "listening socket: %s", error_msg); sk_close(sharestate->listensock); @@ -1921,7 +1922,7 @@ static const PlugVtable ssh_sharing_conn_plugvt = { static int share_listen_accepting(Plug *plug, accept_fn_t constructor, accept_ctx_t ctx) { - struct ssh_sharing_state *sharestate = FROMFIELD( + struct ssh_sharing_state *sharestate = container_of( plug, struct ssh_sharing_state, plug); struct ssh_sharing_connstate *cs; const char *err; diff --git a/sshverstring.c b/sshverstring.c index d9bc8077..060587f4 100644 --- a/sshverstring.c +++ b/sshverstring.c @@ -107,7 +107,7 @@ BinaryPacketProtocol *ssh_verstring_new( void ssh_verstring_free(BinaryPacketProtocol *bpp) { struct ssh_verstring_state *s = - FROMFIELD(bpp, struct ssh_verstring_state, bpp); + container_of(bpp, struct ssh_verstring_state, bpp); conf_free(s->conf); sfree(s->vstring); sfree(s->protoversion); @@ -213,7 +213,7 @@ static void ssh_verstring_send(struct ssh_verstring_state *s) void ssh_verstring_handle_input(BinaryPacketProtocol *bpp) { struct ssh_verstring_state *s = - FROMFIELD(bpp, struct ssh_verstring_state, bpp); + container_of(bpp, struct ssh_verstring_state, bpp); crBegin(s->crState); @@ -604,21 +604,21 @@ static void ssh_detect_bugs(struct ssh_verstring_state *s) const char *ssh_verstring_get_remote(BinaryPacketProtocol *bpp) { struct ssh_verstring_state *s = - FROMFIELD(bpp, struct ssh_verstring_state, bpp); + container_of(bpp, struct ssh_verstring_state, bpp); return s->vstring; } const char *ssh_verstring_get_local(BinaryPacketProtocol *bpp) { struct ssh_verstring_state *s = - FROMFIELD(bpp, struct ssh_verstring_state, bpp); + container_of(bpp, struct ssh_verstring_state, bpp); return s->our_vstring; } int ssh_verstring_get_bugs(BinaryPacketProtocol *bpp) { struct ssh_verstring_state *s = - FROMFIELD(bpp, struct ssh_verstring_state, bpp); + container_of(bpp, struct ssh_verstring_state, bpp); return s->remote_bugs; } diff --git a/sshzlib.c b/sshzlib.c index ec8708b5..d0cbef8f 100644 --- a/sshzlib.c +++ b/sshzlib.c @@ -630,7 +630,7 @@ ssh_compressor *zlib_compress_init(void) void zlib_compress_cleanup(ssh_compressor *sc) { struct ssh_zlib_compressor *comp = - FROMFIELD(sc, struct ssh_zlib_compressor, sc); + container_of(sc, struct ssh_zlib_compressor, sc); sfree(comp->ectx.userdata); sfree(comp->ectx.ictx); sfree(comp); @@ -641,7 +641,7 @@ void zlib_compress_block(ssh_compressor *sc, unsigned char *block, int len, int minlen) { struct ssh_zlib_compressor *comp = - FROMFIELD(sc, struct ssh_zlib_compressor, sc); + container_of(sc, struct ssh_zlib_compressor, sc); struct Outbuf *out = (struct Outbuf *) comp->ectx.userdata; int in_block; @@ -916,7 +916,7 @@ ssh_decompressor *zlib_decompress_init(void) void zlib_decompress_cleanup(ssh_decompressor *dc) { struct zlib_decompress_ctx *dctx = - FROMFIELD(dc, struct zlib_decompress_ctx, dc); + container_of(dc, struct zlib_decompress_ctx, dc); if (dctx->currlentable && dctx->currlentable != dctx->staticlentable) zlib_freetable(&dctx->currlentable); @@ -978,7 +978,7 @@ int zlib_decompress_block(ssh_decompressor *dc, unsigned char *block, int len, unsigned char **outblock, int *outlen) { struct zlib_decompress_ctx *dctx = - FROMFIELD(dc, struct zlib_decompress_ctx, dc); + container_of(dc, struct zlib_decompress_ctx, dc); const coderecord *rec; int code, blktype, rep, dist, nlen, header; static const unsigned char lenlenmap[] = { diff --git a/telnet.c b/telnet.c index dee0aab9..fcaab876 100644 --- a/telnet.c +++ b/telnet.c @@ -645,7 +645,7 @@ static void do_telnet_read(Telnet *telnet, char *buf, int len) static void telnet_log(Plug *plug, int type, SockAddr *addr, int port, const char *error_msg, int error_code) { - Telnet *telnet = FROMFIELD(plug, Telnet, plug); + Telnet *telnet = container_of(plug, Telnet, plug); backend_socket_log(telnet->frontend, type, addr, port, error_msg, error_code, telnet->conf, telnet->session_started); @@ -654,7 +654,7 @@ static void telnet_log(Plug *plug, int type, SockAddr *addr, int port, static void telnet_closing(Plug *plug, const char *error_msg, int error_code, int calling_back) { - Telnet *telnet = FROMFIELD(plug, Telnet, plug); + Telnet *telnet = container_of(plug, Telnet, plug); /* * We don't implement independent EOF in each direction for Telnet @@ -678,7 +678,7 @@ static void telnet_closing(Plug *plug, const char *error_msg, int error_code, static void telnet_receive(Plug *plug, int urgent, char *data, int len) { - Telnet *telnet = FROMFIELD(plug, Telnet, plug); + Telnet *telnet = container_of(plug, Telnet, plug); if (urgent) telnet->in_synch = TRUE; telnet->session_started = TRUE; @@ -687,7 +687,7 @@ static void telnet_receive(Plug *plug, int urgent, char *data, int len) static void telnet_sent(Plug *plug, int bufsize) { - Telnet *telnet = FROMFIELD(plug, Telnet, plug); + Telnet *telnet = container_of(plug, Telnet, plug); telnet->bufsize = bufsize; } @@ -809,7 +809,7 @@ static const char *telnet_init(Frontend *frontend, Backend **backend_handle, static void telnet_free(Backend *be) { - Telnet *telnet = FROMFIELD(be, Telnet, backend); + Telnet *telnet = container_of(be, Telnet, backend); sfree(telnet->sb_buf); if (telnet->s) @@ -826,7 +826,7 @@ static void telnet_free(Backend *be) */ static void telnet_reconfig(Backend *be, Conf *conf) { - Telnet *telnet = FROMFIELD(be, Telnet, backend); + Telnet *telnet = container_of(be, Telnet, backend); pinger_reconfig(telnet->pinger, telnet->conf, conf); conf_free(telnet->conf); telnet->conf = conf_copy(conf); @@ -837,7 +837,7 @@ static void telnet_reconfig(Backend *be, Conf *conf) */ static int telnet_send(Backend *be, const char *buf, int len) { - Telnet *telnet = FROMFIELD(be, Telnet, backend); + Telnet *telnet = container_of(be, Telnet, backend); unsigned char *p, *end; static const unsigned char iac[2] = { IAC, IAC }; static const unsigned char cr[2] = { CR, NUL }; @@ -872,7 +872,7 @@ static int telnet_send(Backend *be, const char *buf, int len) */ static int telnet_sendbuffer(Backend *be) { - Telnet *telnet = FROMFIELD(be, Telnet, backend); + Telnet *telnet = container_of(be, Telnet, backend); return telnet->bufsize; } @@ -881,7 +881,7 @@ static int telnet_sendbuffer(Backend *be) */ static void telnet_size(Backend *be, int width, int height) { - Telnet *telnet = FROMFIELD(be, Telnet, backend); + Telnet *telnet = container_of(be, Telnet, backend); unsigned char b[24]; int n; char *logbuf; @@ -917,7 +917,7 @@ static void telnet_size(Backend *be, int width, int height) */ static void telnet_special(Backend *be, SessionSpecialCode code, int arg) { - Telnet *telnet = FROMFIELD(be, Telnet, backend); + Telnet *telnet = container_of(be, Telnet, backend); unsigned char b[2]; if (telnet->s == NULL) @@ -1022,25 +1022,25 @@ static const SessionSpecial *telnet_get_specials(Backend *be) static int telnet_connected(Backend *be) { - Telnet *telnet = FROMFIELD(be, Telnet, backend); + Telnet *telnet = container_of(be, Telnet, backend); return telnet->s != NULL; } static int telnet_sendok(Backend *be) { - /* Telnet *telnet = FROMFIELD(be, Telnet, backend); */ + /* Telnet *telnet = container_of(be, Telnet, backend); */ return 1; } static void telnet_unthrottle(Backend *be, int backlog) { - Telnet *telnet = FROMFIELD(be, Telnet, backend); + Telnet *telnet = container_of(be, Telnet, backend); sk_set_frozen(telnet->s, backlog > TELNET_MAX_BACKLOG); } static int telnet_ldisc(Backend *be, int option) { - Telnet *telnet = FROMFIELD(be, Telnet, backend); + Telnet *telnet = container_of(be, Telnet, backend); if (option == LD_ECHO) return telnet->echoing; if (option == LD_EDIT) @@ -1050,7 +1050,7 @@ static int telnet_ldisc(Backend *be, int option) static void telnet_provide_ldisc(Backend *be, Ldisc *ldisc) { - Telnet *telnet = FROMFIELD(be, Telnet, backend); + Telnet *telnet = container_of(be, Telnet, backend); telnet->ldisc = ldisc; } @@ -1061,7 +1061,7 @@ static void telnet_provide_logctx(Backend *be, LogContext *logctx) static int telnet_exitcode(Backend *be) { - Telnet *telnet = FROMFIELD(be, Telnet, backend); + Telnet *telnet = container_of(be, Telnet, backend); if (telnet->s != NULL) return -1; /* still connected */ else if (telnet->closed_on_socket_error) diff --git a/testback.c b/testback.c index 9e70819f..16f6476e 100644 --- a/testback.c +++ b/testback.c @@ -97,7 +97,7 @@ static void null_free(Backend *be) static void loop_free(Backend *be) { - struct loop_state *st = FROMFIELD(be, struct loop_state, backend); + struct loop_state *st = container_of(be, struct loop_state, backend); sfree(st); } @@ -112,7 +112,7 @@ static int null_send(Backend *be, const char *buf, int len) { } static int loop_send(Backend *be, const char *buf, int len) { - struct loop_state *st = FROMFIELD(be, struct loop_state, backend); + struct loop_state *st = container_of(be, struct loop_state, backend); return from_backend(st->frontend, 0, buf, len); } diff --git a/unix/gtkfont.c b/unix/gtkfont.c index d957476b..d0ecaa96 100644 --- a/unix/gtkfont.c +++ b/unix/gtkfont.c @@ -541,7 +541,7 @@ static unifont *x11font_create(GtkWidget *widget, const char *name, static void x11font_destroy(unifont *font) { - struct x11font *xfont = FROMFIELD(font, struct x11font, u); + struct x11font *xfont = container_of(font, struct x11font, u); Display *disp = xfont->disp; int i; @@ -579,7 +579,7 @@ static void x11_alloc_subfont(struct x11font *xfont, int sfid) static int x11font_has_glyph(unifont *font, wchar_t glyph) { - struct x11font *xfont = FROMFIELD(font, struct x11font, u); + struct x11font *xfont = container_of(font, struct x11font, u); if (xfont->sixteen_bit) { /* @@ -893,7 +893,7 @@ static void x11font_draw_text(unifont_drawctx *ctx, unifont *font, int x, int y, const wchar_t *string, int len, int wide, int bold, int cellwidth) { - struct x11font *xfont = FROMFIELD(font, struct x11font, u); + struct x11font *xfont = container_of(font, struct x11font, u); int sfid; int shadowoffset = 0; int mult = (wide ? 2 : 1); @@ -1200,7 +1200,7 @@ static char *x11font_scale_fontname(GtkWidget *widget, const char *name, static char *x11font_size_increment(unifont *font, int increment) { - struct x11font *xfont = FROMFIELD(font, struct x11font, u); + struct x11font *xfont = container_of(font, struct x11font, u); Display *disp = xfont->disp; Atom fontprop = XInternAtom(disp, "FONT", False); char *returned_name = NULL; @@ -1523,7 +1523,7 @@ static unifont *pangofont_create_fallback(GtkWidget *widget, int height, static void pangofont_destroy(unifont *font) { - struct pangofont *pfont = FROMFIELD(font, struct pangofont, u); + struct pangofont *pfont = container_of(font, struct pangofont, u); pango_font_description_free(pfont->desc); sfree(pfont->widthcache); g_object_unref(pfont->fset); @@ -1587,7 +1587,7 @@ static void pangofont_draw_internal(unifont_drawctx *ctx, unifont *font, int len, int wide, int bold, int cellwidth, int combining) { - struct pangofont *pfont = FROMFIELD(font, struct pangofont, u); + struct pangofont *pfont = container_of(font, struct pangofont, u); PangoLayout *layout; PangoRectangle rect; char *utfstring, *utfptr; @@ -2018,7 +2018,7 @@ static char *pangofont_scale_fontname(GtkWidget *widget, const char *name, static char *pangofont_size_increment(unifont *font, int increment) { - struct pangofont *pfont = FROMFIELD(font, struct pangofont, u); + struct pangofont *pfont = container_of(font, struct pangofont, u); PangoFontDescription *desc; int size; char *newname, *retname; @@ -2244,7 +2244,7 @@ unifont *multifont_create(GtkWidget *widget, const char *name, static void multifont_destroy(unifont *font) { - struct multifont *mfont = FROMFIELD(font, struct multifont, u); + struct multifont *mfont = container_of(font, struct multifont, u); unifont_destroy(mfont->main); if (mfont->fallback) unifont_destroy(mfont->fallback); @@ -2261,7 +2261,7 @@ static void multifont_draw_main(unifont_drawctx *ctx, unifont *font, int x, int wide, int bold, int cellwidth, int cellinc, unifont_draw_func_t draw) { - struct multifont *mfont = FROMFIELD(font, struct multifont, u); + struct multifont *mfont = container_of(font, struct multifont, u); unifont *f; int ok, i; @@ -2307,7 +2307,7 @@ static void multifont_draw_combining(unifont_drawctx *ctx, unifont *font, static char *multifont_size_increment(unifont *font, int increment) { - struct multifont *mfont = FROMFIELD(font, struct multifont, u); + struct multifont *mfont = container_of(font, struct multifont, u); return unifont_size_increment(mfont->main, increment); } @@ -3680,7 +3680,7 @@ unifontsel *unifontsel_new(const char *wintitle) void unifontsel_destroy(unifontsel *fontsel) { - unifontsel_internal *fs = FROMFIELD(fontsel, unifontsel_internal, u); + unifontsel_internal *fs = container_of(fontsel, unifontsel_internal, u); fontinfo *info; #ifndef NO_BACKING_PIXMAPS @@ -3699,7 +3699,7 @@ void unifontsel_destroy(unifontsel *fontsel) void unifontsel_set_name(unifontsel *fontsel, const char *fontname) { - unifontsel_internal *fs = FROMFIELD(fontsel, unifontsel_internal, u); + unifontsel_internal *fs = container_of(fontsel, unifontsel_internal, u); int i, start, end, size, flags; const char *fontname2 = NULL; fontinfo *info; @@ -3759,7 +3759,7 @@ void unifontsel_set_name(unifontsel *fontsel, const char *fontname) char *unifontsel_get_name(unifontsel *fontsel) { - unifontsel_internal *fs = FROMFIELD(fontsel, unifontsel_internal, u); + unifontsel_internal *fs = container_of(fontsel, unifontsel_internal, u); char *name; if (!fs->selected) diff --git a/unix/uxnet.c b/unix/uxnet.c index dbd1231b..dddaee9a 100644 --- a/unix/uxnet.c +++ b/unix/uxnet.c @@ -483,7 +483,7 @@ SockAddr *sk_addr_dup(SockAddr *addr) static Plug *sk_net_plug(Socket *sock, Plug *p) { - NetSocket *s = FROMFIELD(sock, NetSocket, sock); + NetSocket *s = container_of(sock, NetSocket, sock); Plug *ret = s->plug; if (p) s->plug = p; @@ -980,7 +980,7 @@ Socket *sk_newlistener(const char *srcaddr, int port, Plug *plug, if (address_family == AF_INET6 && orig_address_family == ADDRTYPE_UNSPEC) { NetSocket *other; - other = FROMFIELD( + other = container_of( sk_newlistener(srcaddr, port, plug, local_host_only, ADDRTYPE_IPV4), NetSocket, sock); @@ -1010,7 +1010,7 @@ Socket *sk_newlistener(const char *srcaddr, int port, Plug *plug, static void sk_net_close(Socket *sock) { - NetSocket *s = FROMFIELD(sock, NetSocket, sock); + NetSocket *s = container_of(sock, NetSocket, sock); if (s->child) sk_net_close(&s->child->sock); @@ -1039,7 +1039,7 @@ void *sk_getxdmdata(Socket *sock, int *lenp) */ if (sock->vt != &NetSocket_sockvt) return NULL; /* failure */ - s = FROMFIELD(sock, NetSocket, sock); + s = container_of(sock, NetSocket, sock); addrlen = sizeof(u); if (getsockname(s->s, &u.sa, &addrlen) < 0) @@ -1185,7 +1185,7 @@ void try_send(NetSocket *s) static int sk_net_write(Socket *sock, const void *buf, int len) { - NetSocket *s = FROMFIELD(sock, NetSocket, sock); + NetSocket *s = container_of(sock, NetSocket, sock); assert(s->outgoingeof == EOF_NO); @@ -1211,7 +1211,7 @@ static int sk_net_write(Socket *sock, const void *buf, int len) static int sk_net_write_oob(Socket *sock, const void *buf, int len) { - NetSocket *s = FROMFIELD(sock, NetSocket, sock); + NetSocket *s = container_of(sock, NetSocket, sock); assert(s->outgoingeof == EOF_NO); @@ -1240,7 +1240,7 @@ static int sk_net_write_oob(Socket *sock, const void *buf, int len) static void sk_net_write_eof(Socket *sock) { - NetSocket *s = FROMFIELD(sock, NetSocket, sock); + NetSocket *s = container_of(sock, NetSocket, sock); assert(s->outgoingeof == EOF_NO); @@ -1467,13 +1467,13 @@ const char *sk_addr_error(SockAddr *addr) } static const char *sk_net_socket_error(Socket *sock) { - NetSocket *s = FROMFIELD(sock, NetSocket, sock); + NetSocket *s = container_of(sock, NetSocket, sock); return s->error; } static void sk_net_set_frozen(Socket *sock, int is_frozen) { - NetSocket *s = FROMFIELD(sock, NetSocket, sock); + NetSocket *s = container_of(sock, NetSocket, sock); if (s->frozen == is_frozen) return; s->frozen = is_frozen; @@ -1482,7 +1482,7 @@ static void sk_net_set_frozen(Socket *sock, int is_frozen) static char *sk_net_peer_info(Socket *sock) { - NetSocket *s = FROMFIELD(sock, NetSocket, sock); + NetSocket *s = container_of(sock, NetSocket, sock); union sockaddr_union addr; socklen_t addrlen = sizeof(addr); #ifndef NO_IPV6 diff --git a/unix/uxproxy.c b/unix/uxproxy.c index cd5f4e7a..9e727ef8 100644 --- a/unix/uxproxy.c +++ b/unix/uxproxy.c @@ -104,7 +104,7 @@ static int localproxy_errfd_find(void *av, void *bv) static Plug *sk_localproxy_plug (Socket *s, Plug *p) { - LocalProxySocket *ps = FROMFIELD(s, LocalProxySocket, sock); + LocalProxySocket *ps = container_of(s, LocalProxySocket, sock); Plug *ret = ps->plug; if (p) ps->plug = p; @@ -113,7 +113,7 @@ static Plug *sk_localproxy_plug (Socket *s, Plug *p) static void sk_localproxy_close (Socket *s) { - LocalProxySocket *ps = FROMFIELD(s, LocalProxySocket, sock); + LocalProxySocket *ps = container_of(s, LocalProxySocket, sock); if (ps->to_cmd >= 0) { del234(localproxy_by_tofd, ps); @@ -201,7 +201,7 @@ static int localproxy_try_send(LocalProxySocket *ps) static int sk_localproxy_write (Socket *s, const void *data, int len) { - LocalProxySocket *ps = FROMFIELD(s, LocalProxySocket, sock); + LocalProxySocket *ps = container_of(s, LocalProxySocket, sock); assert(ps->outgoingeof == EOF_NO); @@ -223,7 +223,7 @@ static int sk_localproxy_write_oob (Socket *s, const void *data, int len) static void sk_localproxy_write_eof (Socket *s) { - LocalProxySocket *ps = FROMFIELD(s, LocalProxySocket, sock); + LocalProxySocket *ps = container_of(s, LocalProxySocket, sock); assert(ps->outgoingeof == EOF_NO); ps->outgoingeof = EOF_PENDING; @@ -233,13 +233,13 @@ static void sk_localproxy_write_eof (Socket *s) static void sk_localproxy_flush (Socket *s) { - /* LocalProxySocket *ps = FROMFIELD(s, LocalProxySocket, sock); */ + /* LocalProxySocket *ps = container_of(s, LocalProxySocket, sock); */ /* do nothing */ } static void sk_localproxy_set_frozen (Socket *s, int is_frozen) { - LocalProxySocket *ps = FROMFIELD(s, LocalProxySocket, sock); + LocalProxySocket *ps = container_of(s, LocalProxySocket, sock); if (ps->from_cmd < 0) return; @@ -252,7 +252,7 @@ static void sk_localproxy_set_frozen (Socket *s, int is_frozen) static const char * sk_localproxy_socket_error (Socket *s) { - LocalProxySocket *ps = FROMFIELD(s, LocalProxySocket, sock); + LocalProxySocket *ps = container_of(s, LocalProxySocket, sock); return ps->error; } diff --git a/unix/uxpty.c b/unix/uxpty.c index aebfb5c2..e0951808 100644 --- a/unix/uxpty.c +++ b/unix/uxpty.c @@ -1041,7 +1041,7 @@ static const char *pty_init(Frontend *frontend, Backend **backend_handle, static void pty_reconfig(Backend *be, Conf *conf) { - Pty *pty = FROMFIELD(be, Pty, backend); + Pty *pty = container_of(be, Pty, backend); /* * We don't have much need to reconfigure this backend, but * unfortunately we do need to pick up the setting of Close On @@ -1055,7 +1055,7 @@ static void pty_reconfig(Backend *be, Conf *conf) */ static void pty_free(Backend *be) { - Pty *pty = FROMFIELD(be, Pty, backend); + Pty *pty = container_of(be, Pty, backend); /* Either of these may fail `not found'. That's fine with us. */ del234(ptys_by_pid, pty); @@ -1108,7 +1108,7 @@ static void pty_try_write(Pty *pty) */ static int pty_send(Backend *be, const char *buf, int len) { - Pty *pty = FROMFIELD(be, Pty, backend); + Pty *pty = container_of(be, Pty, backend); if (pty->master_fd < 0) return 0; /* ignore all writes if fd closed */ @@ -1138,7 +1138,7 @@ static void pty_close(Pty *pty) */ static int pty_sendbuffer(Backend *be) { - /* Pty *pty = FROMFIELD(be, Pty, backend); */ + /* Pty *pty = container_of(be, Pty, backend); */ return 0; } @@ -1147,7 +1147,7 @@ static int pty_sendbuffer(Backend *be) */ static void pty_size(Backend *be, int width, int height) { - Pty *pty = FROMFIELD(be, Pty, backend); + Pty *pty = container_of(be, Pty, backend); struct winsize size; pty->term_width = width; @@ -1168,7 +1168,7 @@ static void pty_size(Backend *be, int width, int height) */ static void pty_special(Backend *be, SessionSpecialCode code, int arg) { - /* Pty *pty = FROMFIELD(be, Pty, backend); */ + /* Pty *pty = container_of(be, Pty, backend); */ /* Do nothing! */ return; } @@ -1179,7 +1179,7 @@ static void pty_special(Backend *be, SessionSpecialCode code, int arg) */ static const SessionSpecial *pty_get_specials(Backend *be) { - /* Pty *pty = FROMFIELD(be, Pty, backend); */ + /* Pty *pty = container_of(be, Pty, backend); */ /* * Hmm. When I get round to having this actually usable, it * might be quite nice to have the ability to deliver a few @@ -1191,43 +1191,43 @@ static const SessionSpecial *pty_get_specials(Backend *be) static int pty_connected(Backend *be) { - /* Pty *pty = FROMFIELD(be, Pty, backend); */ + /* Pty *pty = container_of(be, Pty, backend); */ return TRUE; } static int pty_sendok(Backend *be) { - /* Pty *pty = FROMFIELD(be, Pty, backend); */ + /* Pty *pty = container_of(be, Pty, backend); */ return 1; } static void pty_unthrottle(Backend *be, int backlog) { - /* Pty *pty = FROMFIELD(be, Pty, backend); */ + /* Pty *pty = container_of(be, Pty, backend); */ /* do nothing */ } static int pty_ldisc(Backend *be, int option) { - /* Pty *pty = FROMFIELD(be, Pty, backend); */ + /* Pty *pty = container_of(be, Pty, backend); */ return 0; /* neither editing nor echoing */ } static void pty_provide_ldisc(Backend *be, Ldisc *ldisc) { - /* Pty *pty = FROMFIELD(be, Pty, backend); */ + /* Pty *pty = container_of(be, Pty, backend); */ /* This is a stub. */ } static void pty_provide_logctx(Backend *be, LogContext *logctx) { - /* Pty *pty = FROMFIELD(be, Pty, backend); */ + /* Pty *pty = container_of(be, Pty, backend); */ /* This is a stub. */ } static int pty_exitcode(Backend *be) { - Pty *pty = FROMFIELD(be, Pty, backend); + Pty *pty = container_of(be, Pty, backend); if (!pty->finished) return -1; /* not dead yet */ else @@ -1236,7 +1236,7 @@ static int pty_exitcode(Backend *be) static int pty_cfg_info(Backend *be) { - /* Pty *pty = FROMFIELD(be, Pty, backend); */ + /* Pty *pty = container_of(be, Pty, backend); */ return 0; } diff --git a/unix/uxser.c b/unix/uxser.c index dc96f643..0b53d859 100644 --- a/unix/uxser.c +++ b/unix/uxser.c @@ -350,7 +350,7 @@ static void serial_close(Serial *serial) static void serial_free(Backend *be) { - Serial *serial = FROMFIELD(be, Serial, backend); + Serial *serial = container_of(be, Serial, backend); serial_close(serial); @@ -361,7 +361,7 @@ static void serial_free(Backend *be) static void serial_reconfig(Backend *be, Conf *conf) { - Serial *serial = FROMFIELD(be, Serial, backend); + Serial *serial = container_of(be, Serial, backend); /* * FIXME: what should we do if this returns an error? @@ -465,7 +465,7 @@ static void serial_try_write(Serial *serial) */ static int serial_send(Backend *be, const char *buf, int len) { - Serial *serial = FROMFIELD(be, Serial, backend); + Serial *serial = container_of(be, Serial, backend); if (serial->fd < 0) return 0; @@ -481,7 +481,7 @@ static int serial_send(Backend *be, const char *buf, int len) */ static int serial_sendbuffer(Backend *be) { - Serial *serial = FROMFIELD(be, Serial, backend); + Serial *serial = container_of(be, Serial, backend); return bufchain_size(&serial->output_data); } @@ -499,7 +499,7 @@ static void serial_size(Backend *be, int width, int height) */ static void serial_special(Backend *be, SessionSpecialCode code, int arg) { - Serial *serial = FROMFIELD(be, Serial, backend); + Serial *serial = container_of(be, Serial, backend); if (serial->fd >= 0 && code == SS_BRK) { tcsendbreak(serial->fd, 0); @@ -534,7 +534,7 @@ static int serial_sendok(Backend *be) static void serial_unthrottle(Backend *be, int backlog) { - Serial *serial = FROMFIELD(be, Serial, backend); + Serial *serial = container_of(be, Serial, backend); serial->inbufsize = backlog; serial_uxsel_setup(serial); } @@ -559,7 +559,7 @@ static void serial_provide_logctx(Backend *be, LogContext *logctx) static int serial_exitcode(Backend *be) { - Serial *serial = FROMFIELD(be, Serial, backend); + Serial *serial = container_of(be, Serial, backend); if (serial->fd >= 0) return -1; /* still connected */ else diff --git a/windows/winhsock.c b/windows/winhsock.c index b0387ffc..f4d0d916 100644 --- a/windows/winhsock.c +++ b/windows/winhsock.c @@ -106,7 +106,7 @@ static void handle_sentdata(struct handle *h, int new_backlog) static Plug *sk_handle_plug(Socket *s, Plug *p) { - HandleSocket *hs = FROMFIELD(s, HandleSocket, sock); + HandleSocket *hs = container_of(s, HandleSocket, sock); Plug *ret = hs->plug; if (p) hs->plug = p; @@ -115,7 +115,7 @@ static Plug *sk_handle_plug(Socket *s, Plug *p) static void sk_handle_close(Socket *s) { - HandleSocket *hs = FROMFIELD(s, HandleSocket, sock); + HandleSocket *hs = container_of(s, HandleSocket, sock); if (hs->defer_close) { hs->deferred_close = TRUE; @@ -135,7 +135,7 @@ static void sk_handle_close(Socket *s) static int sk_handle_write(Socket *s, const void *data, int len) { - HandleSocket *hs = FROMFIELD(s, HandleSocket, sock); + HandleSocket *hs = container_of(s, HandleSocket, sock); return handle_write(hs->send_h, data, len); } @@ -151,14 +151,14 @@ static int sk_handle_write_oob(Socket *s, const void *data, int len) static void sk_handle_write_eof(Socket *s) { - HandleSocket *hs = FROMFIELD(s, HandleSocket, sock); + HandleSocket *hs = container_of(s, HandleSocket, sock); handle_write_eof(hs->send_h); } static void sk_handle_flush(Socket *s) { - /* HandleSocket *hs = FROMFIELD(s, HandleSocket, sock); */ + /* HandleSocket *hs = container_of(s, HandleSocket, sock); */ /* do nothing */ } @@ -211,7 +211,7 @@ static void handle_socket_unfreeze(void *hsv) static void sk_handle_set_frozen(Socket *s, int is_frozen) { - HandleSocket *hs = FROMFIELD(s, HandleSocket, sock); + HandleSocket *hs = container_of(s, HandleSocket, sock); if (is_frozen) { switch (hs->frozen) { @@ -266,13 +266,13 @@ static void sk_handle_set_frozen(Socket *s, int is_frozen) static const char *sk_handle_socket_error(Socket *s) { - HandleSocket *hs = FROMFIELD(s, HandleSocket, sock); + HandleSocket *hs = container_of(s, HandleSocket, sock); return hs->error; } static char *sk_handle_peer_info(Socket *s) { - HandleSocket *hs = FROMFIELD(s, HandleSocket, sock); + HandleSocket *hs = container_of(s, HandleSocket, sock); ULONG pid; static HMODULE kernel32_module; DECL_WINDOWS_FUNCTION(static, BOOL, GetNamedPipeClientProcessId, diff --git a/windows/winnet.c b/windows/winnet.c index 94396d14..458ee4ec 100644 --- a/windows/winnet.c +++ b/windows/winnet.c @@ -909,7 +909,7 @@ SockAddr *sk_addr_dup(SockAddr *addr) static Plug *sk_net_plug(Socket *sock, Plug *p) { - NetSocket *s = FROMFIELD(sock, NetSocket, sock); + NetSocket *s = container_of(sock, NetSocket, sock); Plug *ret = s->plug; if (p) s->plug = p; @@ -1411,7 +1411,7 @@ Socket *sk_newlistener(const char *srcaddr, int port, Plug *plug, local_host_only, ADDRTYPE_IPV6); if (other) { - NetSocket *ns = FROMFIELD(other, NetSocket, sock); + NetSocket *ns = container_of(other, NetSocket, sock); if (!ns->error) { ns->parent = ret; ret->child = ns; @@ -1428,7 +1428,7 @@ Socket *sk_newlistener(const char *srcaddr, int port, Plug *plug, static void sk_net_close(Socket *sock) { extern char *do_select(SOCKET skt, int startup); - NetSocket *s = FROMFIELD(sock, NetSocket, sock); + NetSocket *s = container_of(sock, NetSocket, sock); if (s->child) sk_net_close(&s->child->sock); @@ -1539,7 +1539,7 @@ void try_send(NetSocket *s) static int sk_net_write(Socket *sock, const void *buf, int len) { - NetSocket *s = FROMFIELD(sock, NetSocket, sock); + NetSocket *s = container_of(sock, NetSocket, sock); assert(s->outgoingeof == EOF_NO); @@ -1559,7 +1559,7 @@ static int sk_net_write(Socket *sock, const void *buf, int len) static int sk_net_write_oob(Socket *sock, const void *buf, int len) { - NetSocket *s = FROMFIELD(sock, NetSocket, sock); + NetSocket *s = container_of(sock, NetSocket, sock); assert(s->outgoingeof == EOF_NO); @@ -1582,7 +1582,7 @@ static int sk_net_write_oob(Socket *sock, const void *buf, int len) static void sk_net_write_eof(Socket *sock) { - NetSocket *s = FROMFIELD(sock, NetSocket, sock); + NetSocket *s = container_of(sock, NetSocket, sock); assert(s->outgoingeof == EOF_NO); @@ -1785,13 +1785,13 @@ const char *sk_addr_error(SockAddr *addr) } static const char *sk_net_socket_error(Socket *sock) { - NetSocket *s = FROMFIELD(sock, NetSocket, sock); + NetSocket *s = container_of(sock, NetSocket, sock); return s->error; } static char *sk_net_peer_info(Socket *sock) { - NetSocket *s = FROMFIELD(sock, NetSocket, sock); + NetSocket *s = container_of(sock, NetSocket, sock); #ifdef NO_IPV6 struct sockaddr_in addr; #else @@ -1823,7 +1823,7 @@ static char *sk_net_peer_info(Socket *sock) static void sk_net_set_frozen(Socket *sock, int is_frozen) { - NetSocket *s = FROMFIELD(sock, NetSocket, sock); + NetSocket *s = container_of(sock, NetSocket, sock); if (s->frozen == is_frozen) return; s->frozen = is_frozen; diff --git a/windows/winnps.c b/windows/winnps.c index 8422d493..d76d5dae 100644 --- a/windows/winnps.c +++ b/windows/winnps.c @@ -38,7 +38,7 @@ typedef struct NamedPipeServerSocket { static Plug *sk_namedpipeserver_plug(Socket *s, Plug *p) { - NamedPipeServerSocket *ps = FROMFIELD(s, NamedPipeServerSocket, sock); + NamedPipeServerSocket *ps = container_of(s, NamedPipeServerSocket, sock); Plug *ret = ps->plug; if (p) ps->plug = p; @@ -47,7 +47,7 @@ static Plug *sk_namedpipeserver_plug(Socket *s, Plug *p) static void sk_namedpipeserver_close(Socket *s) { - NamedPipeServerSocket *ps = FROMFIELD(s, NamedPipeServerSocket, sock); + NamedPipeServerSocket *ps = container_of(s, NamedPipeServerSocket, sock); if (ps->callback_handle) handle_free(ps->callback_handle); @@ -64,7 +64,7 @@ static void sk_namedpipeserver_close(Socket *s) static const char *sk_namedpipeserver_socket_error(Socket *s) { - NamedPipeServerSocket *ps = FROMFIELD(s, NamedPipeServerSocket, sock); + NamedPipeServerSocket *ps = container_of(s, NamedPipeServerSocket, sock); return ps->error; } diff --git a/windows/winser.c b/windows/winser.c index 30c605f7..db53d24e 100644 --- a/windows/winser.c +++ b/windows/winser.c @@ -284,7 +284,7 @@ static const char *serial_init(Frontend *frontend, Backend **backend_handle, static void serial_free(Backend *be) { - Serial *serial = FROMFIELD(be, Serial, backend); + Serial *serial = container_of(be, Serial, backend); serial_terminate(serial); expire_timer_context(serial); @@ -293,7 +293,7 @@ static void serial_free(Backend *be) static void serial_reconfig(Backend *be, Conf *conf) { - Serial *serial = FROMFIELD(be, Serial, backend); + Serial *serial = container_of(be, Serial, backend); serial_configure(serial, serial->port, conf); @@ -308,7 +308,7 @@ static void serial_reconfig(Backend *be, Conf *conf) */ static int serial_send(Backend *be, const char *buf, int len) { - Serial *serial = FROMFIELD(be, Serial, backend); + Serial *serial = container_of(be, Serial, backend); if (serial->out == NULL) return 0; @@ -322,7 +322,7 @@ static int serial_send(Backend *be, const char *buf, int len) */ static int serial_sendbuffer(Backend *be) { - Serial *serial = FROMFIELD(be, Serial, backend); + Serial *serial = container_of(be, Serial, backend); return serial->bufsize; } @@ -351,7 +351,7 @@ static void serbreak_timer(void *ctx, unsigned long now) */ static void serial_special(Backend *be, SessionSpecialCode code, int arg) { - Serial *serial = FROMFIELD(be, Serial, backend); + Serial *serial = container_of(be, Serial, backend); if (serial->port && code == SS_BRK) { logevent(serial->frontend, "Starting serial break at user request"); @@ -399,7 +399,7 @@ static int serial_sendok(Backend *be) static void serial_unthrottle(Backend *be, int backlog) { - Serial *serial = FROMFIELD(be, Serial, backend); + Serial *serial = container_of(be, Serial, backend); if (serial->in) handle_unthrottle(serial->in, backlog); } @@ -424,7 +424,7 @@ static void serial_provide_logctx(Backend *be, LogContext *logctx) static int serial_exitcode(Backend *be) { - Serial *serial = FROMFIELD(be, Serial, backend); + Serial *serial = container_of(be, Serial, backend); if (serial->port != INVALID_HANDLE_VALUE) return -1; /* still connected */ else diff --git a/x11fwd.c b/x11fwd.c index b975bd19..9cdefeea 100644 --- a/x11fwd.c +++ b/x11fwd.c @@ -634,7 +634,7 @@ static void x11_send_init_error(struct X11Connection *conn, static void x11_closing(Plug *plug, const char *error_msg, int error_code, int calling_back) { - struct X11Connection *xconn = FROMFIELD( + struct X11Connection *xconn = container_of( plug, struct X11Connection, plug); if (error_msg) { @@ -666,7 +666,7 @@ static void x11_closing(Plug *plug, const char *error_msg, int error_code, static void x11_receive(Plug *plug, int urgent, char *data, int len) { - struct X11Connection *xconn = FROMFIELD( + struct X11Connection *xconn = container_of( plug, struct X11Connection, plug); xconn->no_data_sent_to_x_client = FALSE; @@ -675,7 +675,7 @@ static void x11_receive(Plug *plug, int urgent, char *data, int len) static void x11_sent(Plug *plug, int bufsize) { - struct X11Connection *xconn = FROMFIELD( + struct X11Connection *xconn = container_of( plug, struct X11Connection, plug); sshfwd_unthrottle(xconn->c, bufsize); @@ -773,7 +773,7 @@ Channel *x11_new_channel(tree234 *authtree, SshChannel *c, static void x11_chan_free(Channel *chan) { assert(chan->vt == &X11Connection_channelvt); - X11Connection *xconn = FROMFIELD(chan, X11Connection, chan); + X11Connection *xconn = container_of(chan, X11Connection, chan); if (xconn->auth_protocol) { sfree(xconn->auth_protocol); @@ -790,7 +790,7 @@ static void x11_chan_free(Channel *chan) static void x11_set_input_wanted(Channel *chan, int wanted) { assert(chan->vt == &X11Connection_channelvt); - X11Connection *xconn = FROMFIELD(chan, X11Connection, chan); + X11Connection *xconn = container_of(chan, X11Connection, chan); xconn->input_wanted = wanted; if (xconn->s) @@ -845,7 +845,7 @@ static int x11_parse_ip(const char *addr_string, unsigned long *ip) static int x11_send(Channel *chan, int is_stderr, const void *vdata, int len) { assert(chan->vt == &X11Connection_channelvt); - X11Connection *xconn = FROMFIELD(chan, X11Connection, chan); + X11Connection *xconn = container_of(chan, X11Connection, chan); const char *data = (const char *)vdata; /* @@ -999,7 +999,7 @@ static int x11_send(Channel *chan, int is_stderr, const void *vdata, int len) static void x11_send_eof(Channel *chan) { assert(chan->vt == &X11Connection_channelvt); - X11Connection *xconn = FROMFIELD(chan, X11Connection, chan); + X11Connection *xconn = container_of(chan, X11Connection, chan); if (xconn->s) { sk_write_eof(xconn->s);