diff options
author | Volker Lendecke <vl@samba.org> | 2010-12-29 08:46:08 +0100 |
---|---|---|
committer | Volker Lendecke <vl@samba.org> | 2010-12-29 22:44:06 +0100 |
commit | 65f4f22cb4a201fb3f4f4adbb576d3a8909d4bfd (patch) | |
tree | 1a4ee0957bf3eb56bcb4cf0e627caaff698a7293 /lib/async_req | |
parent | b222615b5978aa78e82af79359b7cc3baec0bc87 (diff) | |
download | samba-65f4f22cb4a201fb3f4f4adbb576d3a8909d4bfd.tar.gz samba-65f4f22cb4a201fb3f4f4adbb576d3a8909d4bfd.tar.bz2 samba-65f4f22cb4a201fb3f4f4adbb576d3a8909d4bfd.zip |
Use sockaddr_storage in async sendto/recvfrom
Diffstat (limited to 'lib/async_req')
-rw-r--r-- | lib/async_req/async_sock.c | 33 | ||||
-rw-r--r-- | lib/async_req/async_sock.h | 6 |
2 files changed, 28 insertions, 11 deletions
diff --git a/lib/async_req/async_sock.c b/lib/async_req/async_sock.c index 9b2a625bbe..7ea66f57fe 100644 --- a/lib/async_req/async_sock.c +++ b/lib/async_req/async_sock.c @@ -41,7 +41,7 @@ struct sendto_state { const void *buf; size_t len; int flags; - const struct sockaddr *addr; + const struct sockaddr_storage *addr; socklen_t addr_len; ssize_t sent; }; @@ -52,8 +52,7 @@ static void sendto_handler(struct tevent_context *ev, struct tevent_req *sendto_send(TALLOC_CTX *mem_ctx, struct tevent_context *ev, int fd, const void *buf, size_t len, int flags, - const struct sockaddr *addr, - socklen_t addr_len) + const struct sockaddr_storage *addr) { struct tevent_req *result; struct sendto_state *state; @@ -68,7 +67,23 @@ struct tevent_req *sendto_send(TALLOC_CTX *mem_ctx, struct tevent_context *ev, state->len = len; state->flags = flags; state->addr = addr; - state->addr_len = addr_len; + + switch (addr->ss_family) { + case AF_INET: + state->addr_len = sizeof(struct sockaddr_in); + break; +#if defined(HAVE_IPV6) + case AF_INET6: + state->addr_len = sizeof(struct sockaddr_in6); + break; +#endif + case AF_UNIX: + state->addr_len = sizeof(struct sockaddr_un); + break; + default: + state->addr_len = sizeof(struct sockaddr_storage); + break; + } fde = tevent_add_fd(ev, state, fd, TEVENT_FD_WRITE, sendto_handler, result); @@ -89,7 +104,7 @@ static void sendto_handler(struct tevent_context *ev, tevent_req_data(req, struct sendto_state); state->sent = sendto(state->fd, state->buf, state->len, state->flags, - state->addr, state->addr_len); + (struct sockaddr *)state->addr, state->addr_len); if ((state->sent == -1) && (errno == EINTR)) { /* retry */ return; @@ -117,7 +132,7 @@ struct recvfrom_state { void *buf; size_t len; int flags; - struct sockaddr *addr; + struct sockaddr_storage *addr; socklen_t *addr_len; ssize_t received; }; @@ -129,7 +144,8 @@ static void recvfrom_handler(struct tevent_context *ev, struct tevent_req *recvfrom_send(TALLOC_CTX *mem_ctx, struct tevent_context *ev, int fd, void *buf, size_t len, int flags, - struct sockaddr *addr, socklen_t *addr_len) + struct sockaddr_storage *addr, + socklen_t *addr_len) { struct tevent_req *result; struct recvfrom_state *state; @@ -165,7 +181,8 @@ static void recvfrom_handler(struct tevent_context *ev, tevent_req_data(req, struct recvfrom_state); state->received = recvfrom(state->fd, state->buf, state->len, - state->flags, state->addr, state->addr_len); + state->flags, (struct sockaddr *)state->addr, + state->addr_len); if ((state->received == -1) && (errno == EINTR)) { /* retry */ return; diff --git a/lib/async_req/async_sock.h b/lib/async_req/async_sock.h index d87b2c1445..8d98886e2b 100644 --- a/lib/async_req/async_sock.h +++ b/lib/async_req/async_sock.h @@ -29,14 +29,14 @@ struct tevent_req *sendto_send(TALLOC_CTX *mem_ctx, struct tevent_context *ev, int fd, const void *buf, size_t len, int flags, - const struct sockaddr *addr, - socklen_t addr_len); + const struct sockaddr_storage *addr); ssize_t sendto_recv(struct tevent_req *req, int *perrno); struct tevent_req *recvfrom_send(TALLOC_CTX *mem_ctx, struct tevent_context *ev, int fd, void *buf, size_t len, int flags, - struct sockaddr *addr, socklen_t *addr_len); + struct sockaddr_storage *addr, + socklen_t *addr_len); ssize_t recvfrom_recv(struct tevent_req *req, int *perrno); struct tevent_req *async_connect_send(TALLOC_CTX *mem_ctx, |