Browse Source

PuTTY snapshot 9396fcc9 (Rename FROMFIELD to 'container_of' - 2018-10-06)

Source commit: 70e398bf13207a3d0248861601ecb78d85c78f8d
Martin Prikryl 6 years ago
parent
commit
25d2842301

+ 13 - 14
source/putty/WINDOWS/winhsock.c

@@ -7,7 +7,6 @@
 #include <assert.h>
 #include <limits.h>
 
-#define DEFINE_PLUG_METHOD_MACROS
 #include "tree234.h"
 #include "putty.h"
 #include "network.h"
@@ -43,7 +42,7 @@ typedef struct HandleSocket {
 
     Plug *plug;
 
-    const Socket_vtable *sockvt;
+    Socket sock;
 } HandleSocket;
 
 static int handle_gotdata(struct handle *h, void *data, int len)
@@ -107,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, sockvt);
+    HandleSocket *hs = container_of(s, HandleSocket, sock);
     Plug *ret = hs->plug;
     if (p)
 	hs->plug = p;
@@ -116,7 +115,7 @@ static Plug *sk_handle_plug(Socket *s, Plug *p)
 
 static void sk_handle_close(Socket *s)
 {
-    HandleSocket *hs = FROMFIELD(s, HandleSocket, sockvt);
+    HandleSocket *hs = container_of(s, HandleSocket, sock);
 
     if (hs->defer_close) {
         hs->deferred_close = TRUE;
@@ -136,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, sockvt);
+    HandleSocket *hs = container_of(s, HandleSocket, sock);
 
     return handle_write(hs->send_h, data, len);
 }
@@ -152,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, sockvt);
+    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, sockvt); */
+    /* HandleSocket *hs = container_of(s, HandleSocket, sock); */
     /* do nothing */
 }
 
@@ -191,7 +190,7 @@ static void handle_socket_unfreeze(void *hsv)
     bufchain_consume(&hs->inputdata, len);
     hs->defer_close = FALSE;
     if (hs->deferred_close) {
-        sk_handle_close(&hs->sockvt);
+        sk_handle_close(&hs->sock);
         return;
     }
 
@@ -212,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, sockvt);
+    HandleSocket *hs = container_of(s, HandleSocket, sock);
 
     if (is_frozen) {
         switch (hs->frozen) {
@@ -267,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, sockvt);
+    HandleSocket *hs = container_of(s, HandleSocket, sock);
     return hs->error;
 }
 
 static char *sk_handle_peer_info(Socket *s)
 {
-    HandleSocket *hs = FROMFIELD(s, HandleSocket, sockvt);
+    HandleSocket *hs = container_of(s, HandleSocket, sock);
     ULONG pid;
     static HMODULE kernel32_module;
     DECL_WINDOWS_FUNCTION(static, BOOL, GetNamedPipeClientProcessId,
@@ -306,7 +305,7 @@ static char *sk_handle_peer_info(Socket *s)
     return NULL;
 }
 
-static const Socket_vtable HandleSocket_sockvt = {
+static const SocketVtable HandleSocket_sockvt = {
     sk_handle_plug,
     sk_handle_close,
     sk_handle_write,
@@ -325,7 +324,7 @@ Socket *make_handle_socket(HANDLE send_H, HANDLE recv_H, HANDLE stderr_H,
     int flags = (overlapped ? HANDLE_FLAG_OVERLAPPED : 0);
 
     hs = snew(HandleSocket);
-    hs->sockvt = &HandleSocket_sockvt;
+    hs->sock.vt = &HandleSocket_sockvt;
     hs->plug = plug;
     hs->error = NULL;
     hs->frozen = UNFROZEN;
@@ -343,5 +342,5 @@ Socket *make_handle_socket(HANDLE send_H, HANDLE recv_H, HANDLE stderr_H,
 
     hs->defer_close = hs->deferred_close = FALSE;
 
-    return &hs->sockvt;
+    return &hs->sock;
 }

+ 4 - 4
source/putty/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;
 

+ 0 - 1
source/putty/be_misc.c

@@ -5,7 +5,6 @@
 #include <assert.h>
 #include <string.h>
 
-#define DEFINE_PLUG_METHOD_MACROS
 #include "putty.h"
 #include "network.h"
 

+ 0 - 1
source/putty/cproxy.c

@@ -9,7 +9,6 @@
 #include <ctype.h>
 #include <string.h>
 
-#define DEFINE_PLUG_METHOD_MACROS
 #include "putty.h"
 #include "ssh.h" /* For MD5 support */
 #include "network.h"

+ 4 - 7
source/putty/defs.h

@@ -42,11 +42,11 @@ typedef struct IdempotentCallback IdempotentCallback;
 
 typedef struct SockAddr SockAddr;
 
-typedef struct Socket_vtable Socket_vtable;
-typedef struct Plug_vtable Plug_vtable;
+typedef struct Socket Socket;
+typedef struct Plug Plug;
 
 typedef struct Backend Backend;
-typedef struct Backend_vtable Backend_vtable;
+typedef struct BackendVtable BackendVtable;
 
 typedef struct Ldisc_tag Ldisc;
 typedef struct LogContext_tag LogContext;
@@ -74,9 +74,6 @@ typedef struct settings_e settings_e;
 
 typedef struct SessionSpecial SessionSpecial;
 
-typedef const Socket_vtable *Socket;
-typedef const Plug_vtable *Plug;
-
 /*
  * A small structure wrapping up a (pointer, length) pair so that it
  * can be conveniently passed to or from a function.
@@ -100,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))))
 

+ 7 - 8
source/putty/errsock.c

@@ -5,7 +5,6 @@
 #include <stdio.h>
 #include <assert.h>
 
-#define DEFINE_PLUG_METHOD_MACROS
 #include "tree234.h"
 #include "putty.h"
 #include "network.h"
@@ -14,12 +13,12 @@ typedef struct {
     char *error;
     Plug *plug;
 
-    const Socket_vtable *sockvt;
+    Socket sock;
 } ErrorSocket;
 
 static Plug *sk_error_plug(Socket *s, Plug *p)
 {
-    ErrorSocket *es = FROMFIELD(s, ErrorSocket, sockvt);
+    ErrorSocket *es = container_of(s, ErrorSocket, sock);
     Plug *ret = es->plug;
     if (p)
 	es->plug = p;
@@ -28,7 +27,7 @@ static Plug *sk_error_plug(Socket *s, Plug *p)
 
 static void sk_error_close(Socket *s)
 {
-    ErrorSocket *es = FROMFIELD(s, ErrorSocket, sockvt);
+    ErrorSocket *es = container_of(s, ErrorSocket, sock);
 
     sfree(es->error);
     sfree(es);
@@ -36,7 +35,7 @@ static void sk_error_close(Socket *s)
 
 static const char *sk_error_socket_error(Socket *s)
 {
-    ErrorSocket *es = FROMFIELD(s, ErrorSocket, sockvt);
+    ErrorSocket *es = container_of(s, ErrorSocket, sock);
     return es->error;
 }
 
@@ -45,7 +44,7 @@ static char *sk_error_peer_info(Socket *s)
     return NULL;
 }
 
-static const Socket_vtable ErrorSocket_sockvt = {
+static const SocketVtable ErrorSocket_sockvt = {
     sk_error_plug,
     sk_error_close,
     NULL /* write */,
@@ -60,8 +59,8 @@ static const Socket_vtable ErrorSocket_sockvt = {
 Socket *new_error_socket(const char *errmsg, Plug *plug)
 {
     ErrorSocket *es = snew(ErrorSocket);
-    es->sockvt = &ErrorSocket_sockvt;
+    es->sock.vt = &ErrorSocket_sockvt;
     es->plug = plug;
     es->error = dupstr(errmsg);
-    return &es->sockvt;
+    return &es->sock;
 }

+ 1 - 1
source/putty/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;

+ 5 - 5
source/putty/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);
 }

+ 34 - 20
source/putty/network.h

@@ -15,7 +15,14 @@
 
 #include "defs.h"
 
-struct Socket_vtable {
+typedef struct SocketVtable SocketVtable;
+typedef struct PlugVtable PlugVtable;
+
+struct Socket {
+    const struct SocketVtable *vt;
+};
+
+struct SocketVtable {
     Plug *(*plug) (Socket *s, Plug *p);
     /* use a different plug (return the old one) */
     /* if p is NULL, it doesn't change the plug */
@@ -34,7 +41,11 @@ struct Socket_vtable {
 typedef union { void *p; int i; } accept_ctx_t;
 typedef Socket *(*accept_fn_t)(accept_ctx_t ctx, Plug *plug);
 
-struct Plug_vtable {
+struct Plug {
+    const struct PlugVtable *vt;
+};
+
+struct PlugVtable {
     void (*log)(Plug *p, int type, SockAddr *addr, int port,
 		const char *error_msg, int error_code);
     /*
@@ -138,20 +149,23 @@ Socket *sk_new(SockAddr *addr, int port, int privport, int oobinline,
 Socket *sk_newlistener(const char *srcaddr, int port, Plug *plug,
                        int local_host_only, int address_family);
 
-#define sk_plug(s,p) (((*s)->plug) (s, p))
-#define sk_close(s) (((*s)->close) (s))
-#define sk_write(s,buf,len) (((*s)->write) (s, buf, len))
-#define sk_write_oob(s,buf,len) (((*s)->write_oob) (s, buf, len))
-#define sk_write_eof(s) (((*s)->write_eof) (s))
-#define sk_flush(s) (((*s)->flush) (s))
-
-#ifdef DEFINE_PLUG_METHOD_MACROS
-#define plug_log(p,type,addr,port,msg,code) (((*p)->log) (p, type, addr, port, msg, code))
-#define plug_closing(p,msg,code,callback) (((*p)->closing) (p, msg, code, callback))
-#define plug_receive(p,urgent,buf,len) (((*p)->receive) (p, urgent, buf, len))
-#define plug_sent(p,bufsize) (((*p)->sent) (p, bufsize))
-#define plug_accepting(p, constructor, ctx) (((*p)->accepting)(p, constructor, ctx))
-#endif
+#define sk_plug(s,p) (((s)->vt->plug) (s, p))
+#define sk_close(s) (((s)->vt->close) (s))
+#define sk_write(s,buf,len) (((s)->vt->write) (s, buf, len))
+#define sk_write_oob(s,buf,len) (((s)->vt->write_oob) (s, buf, len))
+#define sk_write_eof(s) (((s)->vt->write_eof) (s))
+#define sk_flush(s) (((s)->vt->flush) (s))
+
+#define plug_log(p,type,addr,port,msg,code) \
+    (((p)->vt->log) (p, type, addr, port, msg, code))
+#define plug_closing(p,msg,code,callback) \
+    (((p)->vt->closing) (p, msg, code, callback))
+#define plug_receive(p,urgent,buf,len) \
+    (((p)->vt->receive) (p, urgent, buf, len))
+#define plug_sent(p,bufsize) \
+    (((p)->vt->sent) (p, bufsize))
+#define plug_accepting(p, constructor, ctx) \
+    (((p)->vt->accepting)(p, constructor, ctx))
 
 /*
  * Special error values are returned from sk_namelookup and sk_new
@@ -159,7 +173,7 @@ Socket *sk_newlistener(const char *srcaddr, int port, Plug *plug,
  * or return NULL if there's no problem.
  */
 const char *sk_addr_error(SockAddr *addr);
-#define sk_socket_error(s) (((*s)->socket_error) (s))
+#define sk_socket_error(s) (((s)->vt->socket_error) (s))
 
 /*
  * Set the `frozen' flag on a socket. A frozen socket is one in
@@ -178,14 +192,14 @@ const char *sk_addr_error(SockAddr *addr);
  *    associated local socket in order to avoid unbounded buffer
  *    growth.
  */
-#define sk_set_frozen(s, is_frozen) (((*s)->set_frozen) (s, is_frozen))
+#define sk_set_frozen(s, is_frozen) (((s)->vt->set_frozen) (s, is_frozen))
 
 /*
  * Return a (dynamically allocated) string giving some information
  * about the other end of the socket, suitable for putting in log
  * files. May be NULL if nothing is available at all.
  */
-#define sk_peer_info(s) (((*s)->peer_info) (s))
+#define sk_peer_info(s) (((s)->vt->peer_info) (s))
 
 /*
  * Simple wrapper on getservbyname(), needed by ssh.c. Returns the
@@ -211,7 +225,7 @@ Socket *new_error_socket(const char *errmsg, Plug *plug);
 /*
  * Trivial plug that does absolutely nothing. Found in nullplug.c.
  */
-extern Plug *nullplug;
+extern Plug *const nullplug;
 
 /* ----------------------------------------------------------------------
  * Functions defined outside the network code, which have to be

+ 3 - 3
source/putty/nullplug.c

@@ -25,7 +25,7 @@ static void nullplug_sent(Plug *plug, int bufsize)
 {
 }
 
-static const Plug_vtable nullplug_plugvt = {
+static const PlugVtable nullplug_plugvt = {
     nullplug_socket_log,
     nullplug_closing,
     nullplug_receive,
@@ -33,10 +33,10 @@ static const Plug_vtable nullplug_plugvt = {
     NULL
 };
 
-static const Plug_vtable *nullplug_plugvt_ptr = &nullplug_plugvt;
+static Plug nullplug_plug = { &nullplug_plugvt };
 
 /*
  * There's a singleton instance of nullplug, because it's not
  * interesting enough to worry about making more than one of them.
  */
-Plug *nullplug = &nullplug_plugvt_ptr;
+Plug *const nullplug = &nullplug_plug;

+ 23 - 20
source/putty/portfwd.c

@@ -56,7 +56,7 @@ typedef struct PortForwarding {
     strbuf *socksbuf;
     size_t socksbuf_consumed;
 
-    const Plug_vtable *plugvt;
+    Plug plug;
     Channel chan;
 } PortForwarding;
 
@@ -71,7 +71,7 @@ struct PortListener {
     char *hostname;
     int port;
 
-    const Plug_vtable *plugvt;
+    Plug plug;
 };
 
 static struct PortForwarding *new_portfwd_state(void)
@@ -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, plugvt);
+    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, plugvt);
+    struct PortForwarding *pf =
+        container_of(plug, struct PortForwarding, plug);
 
     if (len == 0)
         return;
@@ -429,13 +431,14 @@ 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, plugvt);
+    struct PortForwarding *pf =
+        container_of(plug, struct PortForwarding, plug);
 
     if (pf->c)
 	sshfwd_unthrottle(pf->c, bufsize);
 }
 
-static const Plug_vtable PortForwarding_plugvt = {
+static const PlugVtable PortForwarding_plugvt = {
     pfd_log,
     pfd_closing,
     pfd_receive,
@@ -473,9 +476,9 @@ static int pfl_accepting(Plug *p, accept_fn_t constructor, accept_ctx_t ctx)
     Socket *s;
     const char *err;
 
-    pl = FROMFIELD(p, struct PortListener, plugvt);
+    pl = container_of(p, struct PortListener, plug);
     pf = new_portfwd_state();
-    pf->plugvt = &PortForwarding_plugvt;
+    pf->plug.vt = &PortForwarding_plugvt;
     pf->chan.initial_fixed_window_size = 0;
     pf->chan.vt = &PortForwarding_channelvt;
     pf->input_wanted = TRUE;
@@ -483,7 +486,7 @@ static int pfl_accepting(Plug *p, accept_fn_t constructor, accept_ctx_t ctx)
     pf->c = NULL;
     pf->cl = pl->cl;
 
-    pf->s = s = constructor(ctx, &pf->plugvt);
+    pf->s = s = constructor(ctx, &pf->plug);
     if ((err = sk_socket_error(s)) != NULL) {
 	free_portfwd_state(pf);
 	return err != NULL;
@@ -509,7 +512,7 @@ static int pfl_accepting(Plug *p, accept_fn_t constructor, accept_ctx_t ctx)
     return 0;
 }
 
-static const Plug_vtable PortListener_plugvt = {
+static const PlugVtable PortListener_plugvt = {
     pfl_log,
     pfl_closing,
     NULL,                          /* recv */
@@ -536,7 +539,7 @@ static char *pfl_listen(char *desthost, int destport, char *srcaddr,
      * Open socket.
      */
     pl = *pl_ret = new_portlistener_state();
-    pl->plugvt = &PortListener_plugvt;
+    pl->plug.vt = &PortListener_plugvt;
     if (desthost) {
 	pl->hostname = dupstr(desthost);
 	pl->port = destport;
@@ -545,7 +548,7 @@ static char *pfl_listen(char *desthost, int destport, char *srcaddr,
 	pl->is_dynamic = TRUE;
     pl->cl = cl;
 
-    pl->s = new_listener(srcaddr, port, &pl->plugvt,
+    pl->s = new_listener(srcaddr, port, &pl->plug,
                          !conf_get_int(conf, CONF_lport_acceptall),
                          conf, address_family);
     if ((err = sk_socket_error(pl->s)) != NULL) {
@@ -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",
@@ -1042,7 +1045,7 @@ char *portfwdmgr_connect(PortFwdManager *mgr, Channel **chan_ret,
      */
     pf = new_portfwd_state();
     *chan_ret = &pf->chan;
-    pf->plugvt = &PortForwarding_plugvt;
+    pf->plug.vt = &PortForwarding_plugvt;
     pf->chan.initial_fixed_window_size = 0;
     pf->chan.vt = &PortForwarding_channelvt;
     pf->input_wanted = TRUE;
@@ -1052,7 +1055,7 @@ char *portfwdmgr_connect(PortFwdManager *mgr, Channel **chan_ret,
     pf->socks_state = SOCKS_NONE;
 
     pf->s = new_connection(addr, dummy_realhost, port,
-                           0, 1, 0, 0, &pf->plugvt, mgr->conf);
+                           0, 1, 0, 0, &pf->plug, mgr->conf);
     sfree(dummy_realhost);
     if ((err = sk_socket_error(pf->s)) != NULL) {
         char *err_ret = dupstr(err);

+ 23 - 24
source/putty/proxy.c

@@ -9,7 +9,6 @@
 #include <ctype.h>
 #include <string.h>
 
-#define DEFINE_PLUG_METHOD_MACROS
 #include "putty.h"
 #include "network.h"
 #include "proxy.h"
@@ -73,14 +72,14 @@ void proxy_activate (ProxySocket *p)
      * unfreezing the actual underlying socket.
      */
     if (!p->freeze)
-	sk_set_frozen(&p->sockvt, 0);
+	sk_set_frozen(&p->sock, 0);
 }
 
 /* basic proxy socket functions */
 
 static Plug *sk_proxy_plug (Socket *s, Plug *p)
 {
-    ProxySocket *ps = FROMFIELD(s, ProxySocket, sockvt);
+    ProxySocket *ps = container_of(s, ProxySocket, sock);
     Plug *ret = ps->plug;
     if (p)
 	ps->plug = p;
@@ -89,7 +88,7 @@ static Plug *sk_proxy_plug (Socket *s, Plug *p)
 
 static void sk_proxy_close (Socket *s)
 {
-    ProxySocket *ps = FROMFIELD(s, ProxySocket, sockvt);
+    ProxySocket *ps = container_of(s, ProxySocket, sock);
 
     sk_close(ps->sub_socket);
     sk_addr_free(ps->remote_addr);
@@ -98,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, sockvt);
+    ProxySocket *ps = container_of(s, ProxySocket, sock);
 
     if (ps->state != PROXY_STATE_ACTIVE) {
 	bufchain_add(&ps->pending_output_data, data, len);
@@ -109,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, sockvt);
+    ProxySocket *ps = container_of(s, ProxySocket, sock);
 
     if (ps->state != PROXY_STATE_ACTIVE) {
 	bufchain_clear(&ps->pending_output_data);
@@ -122,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, sockvt);
+    ProxySocket *ps = container_of(s, ProxySocket, sock);
 
     if (ps->state != PROXY_STATE_ACTIVE) {
         ps->pending_eof = 1;
@@ -133,7 +132,7 @@ static void sk_proxy_write_eof (Socket *s)
 
 static void sk_proxy_flush (Socket *s)
 {
-    ProxySocket *ps = FROMFIELD(s, ProxySocket, sockvt);
+    ProxySocket *ps = container_of(s, ProxySocket, sock);
 
     if (ps->state != PROXY_STATE_ACTIVE) {
 	ps->pending_flush = 1;
@@ -144,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, sockvt);
+    ProxySocket *ps = container_of(s, ProxySocket, sock);
 
     if (ps->state != PROXY_STATE_ACTIVE) {
 	ps->freeze = is_frozen;
@@ -183,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, sockvt);
+    ProxySocket *ps = container_of(s, ProxySocket, sock);
     if (ps->error != NULL || ps->sub_socket == NULL) {
 	return ps->error;
     }
@@ -195,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, plugvt);
+    ProxySocket *ps = container_of(plug, ProxySocket, plugimpl);
 
     plug_log(ps->plug, type, addr, port, error_msg, error_code);
 }
@@ -203,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, plugvt);
+    ProxySocket *ps = container_of(p, ProxySocket, plugimpl);
 
     if (ps->state != PROXY_STATE_ACTIVE) {
 	ps->closing_error_msg = error_msg;
@@ -217,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, plugvt);
+    ProxySocket *ps = container_of(p, ProxySocket, plugimpl);
 
     if (ps->state != PROXY_STATE_ACTIVE) {
 	/* we will lose the urgentness of this data, but since most,
@@ -236,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, plugvt);
+    ProxySocket *ps = container_of(p, ProxySocket, plugimpl);
 
     if (ps->state != PROXY_STATE_ACTIVE) {
 	ps->sent_bufsize = bufsize;
@@ -249,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, plugvt);
+    ProxySocket *ps = container_of(p, ProxySocket, plugimpl);
 
     if (ps->state != PROXY_STATE_ACTIVE) {
 	ps->accepting_constructor = constructor;
@@ -396,7 +395,7 @@ SockAddr *name_lookup(const char *host, int port, char **canonicalname,
     }
 }
 
-static const struct Socket_vtable ProxySocket_sockvt = {
+static const struct SocketVtable ProxySocket_sockvt = {
     sk_proxy_plug,
     sk_proxy_close,
     sk_proxy_write,
@@ -408,7 +407,7 @@ static const struct Socket_vtable ProxySocket_sockvt = {
     NULL, /* peer_info */
 };
 
-static const struct Plug_vtable ProxySocket_plugvt = {
+static const struct PlugVtable ProxySocket_plugvt = {
     plug_proxy_log,
     plug_proxy_closing,
     plug_proxy_receive,
@@ -438,8 +437,8 @@ Socket *new_connection(SockAddr *addr, const char *hostname,
 	    return sret;
 
 	ret = snew(ProxySocket);
-	ret->sockvt = &ProxySocket_sockvt;
-	ret->plugvt = &ProxySocket_plugvt;
+	ret->sock.vt = &ProxySocket_sockvt;
+	ret->plugimpl.vt = &ProxySocket_plugvt;
 	ret->conf = conf_copy(conf);
 	ret->plug = plug;
 	ret->remote_addr = addr;       /* will need to be freed on close */
@@ -473,7 +472,7 @@ Socket *new_connection(SockAddr *addr, const char *hostname,
             proxy_type = "Telnet";
 	} else {
 	    ret->error = "Proxy error: Unknown proxy method";
-	    return &ret->sockvt;
+	    return &ret->sock;
 	}
 
         {
@@ -501,7 +500,7 @@ Socket *new_connection(SockAddr *addr, const char *hostname,
 	if (sk_addr_error(proxy_addr) != NULL) {
 	    ret->error = "Proxy error: Unable to resolve proxy host name";
             sk_addr_free(proxy_addr);
-	    return &ret->sockvt;
+	    return &ret->sock;
 	}
 	sfree(proxy_canonical_name);
 
@@ -521,15 +520,15 @@ Socket *new_connection(SockAddr *addr, const char *hostname,
 	ret->sub_socket = sk_new(proxy_addr,
 				 conf_get_int(conf, CONF_proxy_port),
 				 privport, oobinline,
-				 nodelay, keepalive, &ret->plugvt);
+				 nodelay, keepalive, &ret->plugimpl);
 	if (sk_socket_error(ret->sub_socket) != NULL)
-	    return &ret->sockvt;
+	    return &ret->sock;
 
 	/* start the proxy negotiation process... */
 	sk_set_frozen(ret->sub_socket, 0);
 	ret->negotiate(ret, PROXY_CHANGE_NEW);
 
-	return &ret->sockvt;
+	return &ret->sock;
     }
 
     /* no proxy, so just return the direct socket */

+ 2 - 2
source/putty/proxy.h

@@ -87,8 +87,8 @@ struct ProxySocket {
     int chap_current_attribute;
     int chap_current_datalen;
 
-    const Socket_vtable *sockvt;
-    const Plug_vtable *plugvt;
+    Socket sock;
+    Plug plugimpl;
 };
 
 extern void proxy_activate (ProxySocket *);

+ 11 - 11
source/putty/putty.h

@@ -476,9 +476,9 @@ enum {
 };
 
 struct Backend {
-    const Backend_vtable *vt;
+    const BackendVtable *vt;
 };
-struct Backend_vtable {
+struct BackendVtable {
     const char *(*init) (Frontend *frontend, Backend **backend_out,
 			 Conf *conf, const char *host, int port,
                          char **realhost, int nodelay, int keepalive);
@@ -535,7 +535,7 @@ struct Backend_vtable {
 #define backend_unthrottle(be, bufsize) ((be)->vt->unthrottle(be, bufsize))
 #define backend_cfg_info(be) ((be)->vt->cfg_info(be))
 
-extern const struct Backend_vtable *const backends[];
+extern const struct BackendVtable *const backends[];
 
 /*
  * Suggested default protocol provided by the backend link module.
@@ -1099,8 +1099,8 @@ void random_destroy_seed(void);
 /*
  * Exports from settings.c.
  */
-const struct Backend_vtable *backend_vt_from_name(const char *name);
-const struct Backend_vtable *backend_vt_from_proto(int proto);
+const struct BackendVtable *backend_vt_from_name(const char *name);
+const struct BackendVtable *backend_vt_from_proto(int proto);
 char *get_remote_username(Conf *conf); /* dynamically allocated */
 char *save_settings(const char *section, Conf *conf);
 void save_open_settings(settings_w *sesskey, Conf *conf);
@@ -1195,31 +1195,31 @@ void log_packet(LogContext *logctx, int direction, int type,
  * Exports from testback.c
  */
 
-extern const struct Backend_vtable null_backend;
-extern const struct Backend_vtable loop_backend;
+extern const struct BackendVtable null_backend;
+extern const struct BackendVtable loop_backend;
 
 /*
  * Exports from raw.c.
  */
 
-extern const struct Backend_vtable raw_backend;
+extern const struct BackendVtable raw_backend;
 
 /*
  * Exports from rlogin.c.
  */
 
-extern const struct Backend_vtable rlogin_backend;
+extern const struct BackendVtable rlogin_backend;
 
 /*
  * Exports from telnet.c.
  */
 
-extern const struct Backend_vtable telnet_backend;
+extern const struct BackendVtable telnet_backend;
 
 /*
  * Exports from ssh.c.
  */
-extern const struct Backend_vtable ssh_backend;
+extern const struct BackendVtable ssh_backend;
 
 /*
  * Exports from ldisc.c.

+ 27 - 27
source/putty/ssh.c

@@ -37,7 +37,7 @@ struct Ssh {
     struct ssh_version_receiver version_receiver;
     int remote_bugs;
 
-    const Plug_vtable *plugvt;
+    Plug plug;
     Backend backend;
 
     Ldisc *ldisc;
@@ -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, plugvt);
+    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, plugvt);
+    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, plugvt);
+    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, plugvt);
+    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
@@ -599,7 +599,7 @@ static int ssh_test_for_upstream(const char *host, int port, Conf *conf)
     return ret;
 }
 
-static const Plug_vtable Ssh_plugvt = {
+static const PlugVtable Ssh_plugvt = {
     ssh_socket_log,
     ssh_closing,
     ssh_receive,
@@ -624,7 +624,7 @@ static const char *connect_to_host(Ssh *ssh, const char *host, int port,
     ssh_hostport_setup(host, port, ssh->conf,
                        &ssh->savedhost, &ssh->savedport, &loghost);
 
-    ssh->plugvt = &Ssh_plugvt;
+    ssh->plug.vt = &Ssh_plugvt;
 
     /*
      * Try connection-sharing, in case that means we don't open a
@@ -639,7 +639,7 @@ static const char *connect_to_host(Ssh *ssh, const char *host, int port,
     ssh->attempting_connshare = TRUE;  /* affects socket logging behaviour */
     ssh->s = ssh_connection_sharing_init(
         ssh->savedhost, ssh->savedport, ssh->conf, ssh->frontend,
-        &ssh->plugvt, &ssh->connshare);
+        &ssh->plug, &ssh->connshare);
     ssh->attempting_connshare = FALSE;
     if (ssh->s != NULL) {
         /*
@@ -677,7 +677,7 @@ static const char *connect_to_host(Ssh *ssh, const char *host, int port,
 
         ssh->s = new_connection(addr, *realhost, port,
                                 0, 1, nodelay, keepalive,
-                                &ssh->plugvt, ssh->conf);
+                                &ssh->plug, ssh->conf);
         if ((err = sk_socket_error(ssh->s)) != NULL) {
             ssh->s = NULL;
             notify_remote_exit(ssh->frontend);
@@ -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;
 }
 
@@ -1087,7 +1087,7 @@ void ssh_got_fallback_cmd(Ssh *ssh)
     ssh->fallback_cmd = TRUE;
 }
 
-const struct Backend_vtable ssh_backend = {
+const struct BackendVtable ssh_backend = {
     ssh_init,
     ssh_free,
     ssh_reconfig,

+ 4 - 4
source/putty/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) {

+ 19 - 19
source/putty/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);

+ 8 - 6
source/putty/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);
 }

+ 3 - 3
source/putty/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) {

+ 5 - 5
source/putty/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) {

+ 37 - 37
source/putty/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);

+ 9 - 9
source/putty/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);

+ 6 - 6
source/putty/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);
 }

+ 6 - 6
source/putty/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);
 }
 

+ 3 - 3
source/putty/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);
 }
 

+ 10 - 10
source/putty/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);
 }
 

+ 11 - 10
source/putty/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);
 }

+ 3 - 3
source/putty/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)

+ 19 - 19
source/putty/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);
 }
 

+ 9 - 9
source/putty/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;

+ 10 - 10
source/putty/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];

+ 8 - 4
source/putty/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];
 

+ 10 - 10
source/putty/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)

+ 8 - 8
source/putty/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];
 

+ 5 - 5
source/putty/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);
 }

+ 8 - 8
source/putty/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];
 

+ 18 - 17
source/putty/sshshare.c

@@ -147,7 +147,7 @@ struct ssh_sharing_state {
     ConnectionLayer *cl;             /* instance of the ssh connection layer */
     char *server_verstring;          /* server version string after "SSH-" */
 
-    const Plug_vtable *plugvt;
+    Plug plug;
 };
 
 struct share_globreq;
@@ -200,7 +200,7 @@ struct ssh_sharing_connstate {
     /* Global requests we've sent on to the server, pending replies. */
     struct share_globreq *globreq_head, *globreq_tail;
 
-    const Plug_vtable *plugvt;
+    Plug plug;
 };
 
 struct share_halfchannel {
@@ -950,8 +950,8 @@ 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(
-        plug, struct ssh_sharing_connstate, plugvt);
+    struct ssh_sharing_connstate *cs = container_of(
+        plug, struct ssh_sharing_connstate, plug);
 
     if (error_msg) {
 #ifdef BROKEN_PIPE_ERROR_CODE
@@ -1766,8 +1766,8 @@ 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(
-        plug, ssh_sharing_connstate, plugvt);
+    ssh_sharing_connstate *cs = container_of(
+        plug, ssh_sharing_connstate, plug);
     static const char expected_verstring_prefix[] =
         "[email protected]";
     unsigned char c;
@@ -1842,8 +1842,8 @@ 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(
-        plug, ssh_sharing_connstate, plugvt); */
+    /* ssh_sharing_connstate *cs = container_of(
+        plug, ssh_sharing_connstate, plug); */
 
     /*
      * We do nothing here, because we expect that there won't be a
@@ -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, plugvt);
+    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);
@@ -1910,7 +1911,7 @@ void share_activate(ssh_sharing_state *sharestate,
     }
 }
 
-static const Plug_vtable ssh_sharing_conn_plugvt = {
+static const PlugVtable ssh_sharing_conn_plugvt = {
     NULL, /* no log function, because that's for outgoing connections */
     share_closing,
     share_receive,
@@ -1921,8 +1922,8 @@ static const Plug_vtable 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(
-        plug, struct ssh_sharing_state, plugvt);
+    struct ssh_sharing_state *sharestate = container_of(
+        plug, struct ssh_sharing_state, plug);
     struct ssh_sharing_connstate *cs;
     const char *err;
     char *peerinfo;
@@ -1931,7 +1932,7 @@ static int share_listen_accepting(Plug *plug,
      * A new downstream has connected to us.
      */
     cs = snew(struct ssh_sharing_connstate);
-    cs->plugvt = &ssh_sharing_conn_plugvt;
+    cs->plug.vt = &ssh_sharing_conn_plugvt;
     cs->parent = sharestate;
 
     if ((cs->id = share_find_unused_id(sharestate, sharestate->nextid)) == 0 &&
@@ -1943,7 +1944,7 @@ static int share_listen_accepting(Plug *plug,
     if (sharestate->nextid == 0)
         sharestate->nextid++; /* only happens in VERY long-running upstreams */
 
-    cs->sock = constructor(ctx, &cs->plugvt);
+    cs->sock = constructor(ctx, &cs->plug);
     if ((err = sk_socket_error(cs->sock)) != NULL) {
         sfree(cs);
 	return err != NULL;
@@ -2054,7 +2055,7 @@ int ssh_share_test_for_upstream(const char *host, int port, Conf *conf)
     }
 }
 
-static const Plug_vtable ssh_sharing_listen_plugvt = {
+static const PlugVtable ssh_sharing_listen_plugvt = {
     NULL, /* no log function, because that's for outgoing connections */
     share_listen_closing,
     NULL, /* no receive function on a listening socket */
@@ -2104,7 +2105,7 @@ Socket *ssh_connection_sharing_init(
      * to be an upstream.
      */
     sharestate = snew(struct ssh_sharing_state);
-    sharestate->plugvt = &ssh_sharing_listen_plugvt;
+    sharestate->plug.vt = &ssh_sharing_listen_plugvt;
     sharestate->listensock = NULL;
     sharestate->cl = NULL;
 
@@ -2118,7 +2119,7 @@ Socket *ssh_connection_sharing_init(
     sock = NULL;
     logtext = ds_err = us_err = NULL;
     result = platform_ssh_share(
-        sockname, conf, sshplug, &sharestate->plugvt, &sock, &logtext,
+        sockname, conf, sshplug, &sharestate->plug, &sock, &logtext,
         &ds_err, &us_err, can_upstream, can_downstream);
     switch (result) {
       case SHARE_NONE:

+ 5 - 5
source/putty/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;
 }
 

+ 4 - 4
source/putty/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[] = {

+ 24 - 25
source/putty/windows/winnet.c

@@ -11,7 +11,6 @@
 #include <stdlib.h>
 #include <assert.h>
 
-#define DEFINE_PLUG_METHOD_MACROS
 #define NEED_DECLARATION_OF_SELECT     /* in order to initialise it */
 
 #include "putty.h"
@@ -76,7 +75,7 @@ struct NetSocket {
      */
     NetSocket *parent, *child;
 
-    const Socket_vtable *sockvt;
+    Socket sock;
 };
 
 struct SockAddr {
@@ -910,7 +909,7 @@ SockAddr *sk_addr_dup(SockAddr *addr)
 
 static Plug *sk_net_plug(Socket *sock, Plug *p)
 {
-    NetSocket *s = FROMFIELD(sock, NetSocket, sockvt);
+    NetSocket *s = container_of(sock, NetSocket, sock);
     Plug *ret = s->plug;
     if (p)
 	s->plug = p;
@@ -935,7 +934,7 @@ static char *sk_net_peer_info(Socket *s);
 
 extern char *do_select(SOCKET skt, int startup);
 
-static const Socket_vtable NetSocket_sockvt = {
+static const SocketVtable NetSocket_sockvt = {
     sk_net_plug,
     sk_net_close,
     sk_net_write,
@@ -957,7 +956,7 @@ static Socket *sk_net_accept(accept_ctx_t ctx, Plug *plug)
      * Create NetSocket structure.
      */
     ret = snew(NetSocket);
-    ret->sockvt = &NetSocket_sockvt;
+    ret->sock.vt = &NetSocket_sockvt;
     ret->error = NULL;
     ret->plug = plug;
     bufchain_init(&ret->output_data);
@@ -976,7 +975,7 @@ static Socket *sk_net_accept(accept_ctx_t ctx, Plug *plug)
     if (ret->s == INVALID_SOCKET) {
 	err = p_WSAGetLastError();
 	ret->error = winsock_error_string(err);
-	return &ret->sockvt;
+	return &ret->sock;
     }
 
     ret->oobinline = 0;
@@ -986,12 +985,12 @@ static Socket *sk_net_accept(accept_ctx_t ctx, Plug *plug)
     errstr = do_select(ret->s, 1);
     if (errstr) {
 	ret->error = errstr;
-	return &ret->sockvt;
+	return &ret->sock;
     }
 
     add234(sktree, ret);
 
-    return &ret->sockvt;
+    return &ret->sock;
 }
 
 static DWORD try_connect(NetSocket *sock)
@@ -1202,7 +1201,7 @@ Socket *sk_new(SockAddr *addr, int port, int privport, int oobinline,
      * Create NetSocket structure.
      */
     ret = snew(NetSocket);
-    ret->sockvt = &NetSocket_sockvt;
+    ret->sock.vt = &NetSocket_sockvt;
     ret->error = NULL;
     ret->plug = plug;
     bufchain_init(&ret->output_data);
@@ -1229,7 +1228,7 @@ Socket *sk_new(SockAddr *addr, int port, int privport, int oobinline,
         err = try_connect(ret);
     } while (err && sk_nextaddr(ret->addr, &ret->step));
 
-    return &ret->sockvt;
+    return &ret->sock;
 }
 
 Socket *sk_newlistener(const char *srcaddr, int port, Plug *plug,
@@ -1253,7 +1252,7 @@ Socket *sk_newlistener(const char *srcaddr, int port, Plug *plug,
      * Create NetSocket structure.
      */
     ret = snew(NetSocket);
-    ret->sockvt = &NetSocket_sockvt;
+    ret->sock.vt = &NetSocket_sockvt;
     ret->error = NULL;
     ret->plug = plug;
     bufchain_init(&ret->output_data);
@@ -1295,7 +1294,7 @@ Socket *sk_newlistener(const char *srcaddr, int port, Plug *plug,
     if (s == INVALID_SOCKET) {
 	err = p_WSAGetLastError();
 	ret->error = winsock_error_string(err);
-	return &ret->sockvt;
+	return &ret->sock;
     }
 
     SetHandleInformation((HANDLE)s, HANDLE_FLAG_INHERIT, 0);
@@ -1381,14 +1380,14 @@ Socket *sk_newlistener(const char *srcaddr, int port, Plug *plug,
     if (err) {
 	p_closesocket(s);
 	ret->error = winsock_error_string(err);
-	return &ret->sockvt;
+	return &ret->sock;
     }
 
 
     if (p_listen(s, SOMAXCONN) == SOCKET_ERROR) {
         p_closesocket(s);
 	ret->error = winsock_error_string(p_WSAGetLastError());
-	return &ret->sockvt;
+	return &ret->sock;
     }
 
     /* Set up a select mechanism. This could be an AsyncSelect on a
@@ -1397,7 +1396,7 @@ Socket *sk_newlistener(const char *srcaddr, int port, Plug *plug,
     if (errstr) {
 	p_closesocket(s);
 	ret->error = errstr;
-	return &ret->sockvt;
+	return &ret->sock;
     }
 
     add234(sktree, ret);
@@ -1412,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, sockvt);
+            NetSocket *ns = container_of(other, NetSocket, sock);
 	    if (!ns->error) {
 		ns->parent = ret;
 		ret->child = ns;
@@ -1423,16 +1422,16 @@ Socket *sk_newlistener(const char *srcaddr, int port, Plug *plug,
     }
 #endif
 
-    return &ret->sockvt;
+    return &ret->sock;
 }
 
 static void sk_net_close(Socket *sock)
 {
     extern char *do_select(SOCKET skt, int startup);
-    NetSocket *s = FROMFIELD(sock, NetSocket, sockvt);
+    NetSocket *s = container_of(sock, NetSocket, sock);
 
     if (s->child)
-	sk_net_close(&s->child->sockvt);
+	sk_net_close(&s->child->sock);
 
     del234(sktree, s);
     do_select(s->s, 0);
@@ -1540,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, sockvt);
+    NetSocket *s = container_of(sock, NetSocket, sock);
 
     assert(s->outgoingeof == EOF_NO);
 
@@ -1560,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, sockvt);
+    NetSocket *s = container_of(sock, NetSocket, sock);
 
     assert(s->outgoingeof == EOF_NO);
 
@@ -1583,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, sockvt);
+    NetSocket *s = container_of(sock, NetSocket, sock);
 
     assert(s->outgoingeof == EOF_NO);
 
@@ -1786,13 +1785,13 @@ const char *sk_addr_error(SockAddr *addr)
 }
 static const char *sk_net_socket_error(Socket *sock)
 {
-    NetSocket *s = FROMFIELD(sock, NetSocket, sockvt);
+    NetSocket *s = container_of(sock, NetSocket, sock);
     return s->error;
 }
 
 static char *sk_net_peer_info(Socket *sock)
 {
-    NetSocket *s = FROMFIELD(sock, NetSocket, sockvt);
+    NetSocket *s = container_of(sock, NetSocket, sock);
 #ifdef NO_IPV6
     struct sockaddr_in addr;
 #else
@@ -1824,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, sockvt);
+    NetSocket *s = container_of(sock, NetSocket, sock);
     if (s->frozen == is_frozen)
 	return;
     s->frozen = is_frozen;

+ 0 - 1
source/putty/windows/winproxy.c

@@ -7,7 +7,6 @@
 #include <stdio.h>
 #include <assert.h>
 
-#define DEFINE_PLUG_METHOD_MACROS
 #include "tree234.h"
 #include "putty.h"
 #include "network.h"

+ 1 - 1
source/putty/windows/winstuff.h

@@ -596,7 +596,7 @@ void agent_schedule_callback(void (*callback)(void *, void *, int),
 /*
  * Exports from winser.c.
  */
-extern const struct Backend_vtable serial_backend;
+extern const struct BackendVtable serial_backend;
 
 /*
  * Exports from winjump.c.

+ 14 - 14
source/putty/x11fwd.c

@@ -42,7 +42,7 @@ typedef struct X11Connection {
     SshChannel *c;               /* channel structure held by SSH backend */
     Socket *s;
 
-    const Plug_vtable *plugvt;
+    Plug plug;
     Channel chan;
 } X11Connection;
 
@@ -634,8 +634,8 @@ 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(
-        plug, struct X11Connection, plugvt);
+    struct X11Connection *xconn = container_of(
+        plug, struct X11Connection, plug);
 
     if (error_msg) {
         /*
@@ -666,8 +666,8 @@ 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(
-        plug, struct X11Connection, plugvt);
+    struct X11Connection *xconn = container_of(
+        plug, struct X11Connection, plug);
 
     xconn->no_data_sent_to_x_client = FALSE;
     sshfwd_write(xconn->c, data, len);
@@ -675,8 +675,8 @@ static void x11_receive(Plug *plug, int urgent, char *data, int len)
 
 static void x11_sent(Plug *plug, int bufsize)
 {
-    struct X11Connection *xconn = FROMFIELD(
-        plug, struct X11Connection, plugvt);
+    struct X11Connection *xconn = container_of(
+        plug, struct X11Connection, plug);
 
     sshfwd_unthrottle(xconn->c, bufsize);
 }
@@ -699,7 +699,7 @@ int x11_get_screen_number(char *display)
     return atoi(display + n + 1);
 }
 
-static const Plug_vtable X11Connection_plugvt = {
+static const PlugVtable X11Connection_plugvt = {
     x11_log,
     x11_closing,
     x11_receive,
@@ -738,7 +738,7 @@ Channel *x11_new_channel(tree234 *authtree, SshChannel *c,
      * Open socket.
      */
     xconn = snew(struct X11Connection);
-    xconn->plugvt = &X11Connection_plugvt;
+    xconn->plug.vt = &X11Connection_plugvt;
     xconn->chan.vt = &X11Connection_channelvt;
     xconn->chan.initial_fixed_window_size =
         (connection_sharing_possible ? 128 : 0);
@@ -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;
 
     /*
@@ -945,7 +945,7 @@ static int x11_send(Channel *chan, int is_stderr, const void *vdata, int len)
         xconn->disp = auth_matched->disp;
         xconn->s = new_connection(sk_addr_dup(xconn->disp->addr),
                                   xconn->disp->realhost, xconn->disp->port, 
-                                  0, 1, 0, 0, &xconn->plugvt,
+                                  0, 1, 0, 0, &xconn->plug,
                                   sshfwd_get_conf(xconn->c));
         if ((err = sk_socket_error(xconn->s)) != NULL) {
             char *err_message = dupprintf("unable to connect to"
@@ -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);