chiark / gitweb /
comm: Move construction of comm_addr behind comm interface.
[secnet.git] / udp.c
diff --git a/udp.c b/udp.c
index f4206642fc15f44f1de6606bd970c6e2449797f4..a1d3b74f5b1b6d7d1963f9e38c8048622be7f844 100644 (file)
--- a/udp.c
+++ b/udp.c
@@ -68,10 +68,19 @@ static const char *addr_to_string(void *commst, const struct comm_addr *ca) {
     la.sin_port=htons(st->port);
 
     snprintf(sbuf, sizeof(sbuf), "udp:%s-%s",
-            saddr_to_string(&la), saddr_to_string(&ca->sin));
+            saddr_to_string(&la), saddr_to_string(&ca->priv.sin));
     return sbuf;
 }
 
+static bool_t addr_construct(void *commst, struct comm_addr *ca,
+                            const struct sockaddr_in *sin) {
+    struct udp *st=commst;
+    FILLZERO(*ca);
+    ca->comm=&st->ops;
+    ca->priv.sin=*sin;
+    return True;
+}
+
 static int udp_beforepoll(void *state, struct pollfd *fds, int *nfds_io,
                          int *timeout_io)
 {
@@ -125,7 +134,7 @@ static void udp_afterpoll(void *state, struct pollfd *fds, int nfds)
                    struct comm_addr ca;
                    FILLZERO(ca);
                    ca.comm=&st->ops;
-                   ca.sin=from;
+                   ca.priv.sin=from;
                    if (n->fn(n->state, st->rbuf, &ca)) {
                        done=True;
                        break;
@@ -194,14 +203,14 @@ static bool_t udp_sendmsg(void *commst, struct buffer_if *buf,
 
     if (st->use_proxy) {
        sa=buf->start-8;
-       memcpy(sa,&dest->sin.sin_addr,4);
+       memcpy(sa,&dest->priv.sin.sin_addr,4);
        memset(sa+4,0,4);
-       memcpy(sa+6,&dest->sin.sin_port,2);
+       memcpy(sa+6,&dest->priv.sin.sin_port,2);
        sendto(st->fd,sa,buf->size+8,0,(struct sockaddr *)&st->proxy,
               sizeof(st->proxy));
     } else {
        sendto(st->fd, buf->start, buf->size, 0,
-              (struct sockaddr *)&dest->sin, sizeof(dest->sin));
+              (struct sockaddr *)&dest->priv.sin, sizeof(dest->priv.sin));
     }
 
     return True;
@@ -293,6 +302,7 @@ static list_t *udp_apply(closure_t *self, struct cloc loc, dict_t *context,
     st->ops.request_notify=request_notify;
     st->ops.release_notify=release_notify;
     st->ops.sendmsg=udp_sendmsg;
+    st->ops.addr_construct=addr_construct;
     st->ops.addr_to_string=addr_to_string;
     st->port=0;
     st->use_proxy=False;