diff --git a/simulator.c b/simulator.c index 307efbe4..1d56a1ef 100644 --- a/simulator.c +++ b/simulator.c @@ -164,7 +164,7 @@ static void recv_packet(int fd, struct network *network, struct peer *destinatio return; } - unicast_addr.addrlen=sizeof unicast_addr.local.sun_family + strlen(unicast_addr.local.sun_path) + 1; + unicast_addr.addrlen=sizeof unicast_addr.local - sizeof unicast_addr.local.sun_path + strlen(unicast_addr.local.sun_path) + 1; peer = emalloc_zero(sizeof(struct peer)); if (!peer) { diff --git a/socket.c b/socket.c index ee031d4d..75f65c6d 100644 --- a/socket.c +++ b/socket.c @@ -55,7 +55,7 @@ int _make_local_sockaddr(struct __sourceloc __whence, struct socket_address *add va_end(ap); if (!r) return WHY("socket name overflow"); - addr->addrlen=sizeof addr->local.sun_family + strlen(addr->local.sun_path) + 1; + addr->addrlen=sizeof addr->local - sizeof addr->local.sun_path + strlen(addr->local.sun_path) + 1; // TODO perform real path transformation in making the serval instance path // if (real_sockaddr(addr, addr) == -1) // return -1; @@ -292,14 +292,14 @@ ssize_t _recv_message_frag(struct __sourceloc __whence, int fd, struct socket_ad struct cmsghdr cmsgs[16]; struct msghdr msg = { .msg_name = (void *)&address->addr, - .msg_namelen = address->addrlen, + .msg_namelen = sizeof(address->raw), .msg_iov = data->iov, .msg_iovlen = data->fragment_count, .msg_control = cmsgs, .msg_controllen = sizeof cmsgs, .msg_flags = 0 }; - bzero(&address->addr, address->addrlen); + bzero(address, sizeof(struct socket_address)); ssize_t ret = recvmsg(fd, &msg, 0); if (ret == -1 && errno != EAGAIN && errno != EWOULDBLOCK) WHYF_perror("recvmsg(%d,{name=%p,namelen=%u,iov=%s,control=%p,controllen=%u},0)",