chiark / gitweb /
udp: Provide st->addr_configured
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Sat, 25 Oct 2014 14:00:38 +0000 (15:00 +0100)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Sat, 25 Oct 2014 17:13:43 +0000 (18:13 +0100)
We are going to use it in udp_phase_hook.

Rewrite the tests on caddrl in terms of this new boolean.

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
udp.c

diff --git a/udp.c b/udp.c
index 4119235..c526765 100644 (file)
--- a/udp.c
+++ b/udp.c
@@ -30,6 +30,7 @@ static comm_sendmsg_fn udp_sendmsg;
 struct udp {
     struct udpcommon uc;
     struct udpsocks socks;
+    bool_t addr_configured;
 };
 
 /*
@@ -433,14 +434,16 @@ static list_t *udp_apply(closure_t *self, struct cloc loc, dict_t *context,
     };
 
     caddrl=dict_lookup(d,"address");
-    socks->n_socks=caddrl ? list_length(caddrl) : (int)ARRAY_SIZE(defaultaddrs);
+    st->addr_configured=!!caddrl;
+    socks->n_socks=st->addr_configured ? list_length(caddrl)
+       : (int)ARRAY_SIZE(defaultaddrs);
     if (socks->n_socks<=0 || socks->n_socks>UDP_MAX_SOCKETS)
        cfgfatal(cc->loc,"udp","`address' must be 1..%d addresses",
                 UDP_MAX_SOCKETS);
 
     for (i=0; i<socks->n_socks; i++) {
        struct udpsock *us=&socks->socks[i];
-       if (!list_length(caddrl)) {
+       if (!st->addr_configured) {
            us->addr=defaultaddrs[i];
        } else {
            string_item_to_iaddr(list_elem(caddrl,i),uc->port,&us->addr,"udp");