From 7d6be0d616cebf7de81ba721d2d0899aa03be0f4 Mon Sep 17 00:00:00 2001 From: Corinna Vinschen Date: Sat, 19 Jan 2002 16:11:00 +0000 Subject: [PATCH] * cygwin.din: Add recvmsg and sendmsg. * net.cc: Add cygwin_recvmsg and cygwin_sendmsg. * /usr/include/sys/socket.h: Add recvmsg and sendmsg. --- winsup/cygwin/ChangeLog | 6 +++ winsup/cygwin/cygwin.din | 2 + winsup/cygwin/include/sys/socket.h | 2 + winsup/cygwin/net.cc | 61 ++++++++++++++++++++++++++++++ 4 files changed, 71 insertions(+) diff --git a/winsup/cygwin/ChangeLog b/winsup/cygwin/ChangeLog index 02544ea46..f25090f71 100644 --- a/winsup/cygwin/ChangeLog +++ b/winsup/cygwin/ChangeLog @@ -1,3 +1,9 @@ +2002-01-19 Mark Bradshaw + + * cygwin.din: Add recvmsg and sendmsg. + * net.cc: Add cygwin_recvmsg and cygwin_sendmsg. + * /usr/include/sys/socket.h: Add recvmsg and sendmsg. + 2002-01-19 Corinna Vinschen * security.cc (create_token): Close processes token handle as soon diff --git a/winsup/cygwin/cygwin.din b/winsup/cygwin/cygwin.din index cff55aeaa..4f98f2828 100644 --- a/winsup/cygwin/cygwin.din +++ b/winsup/cygwin/cygwin.din @@ -1036,6 +1036,8 @@ setsockopt = cygwin_setsockopt inet_aton = cygwin_inet_aton inet_ntoa = cygwin_inet_ntoa recvfrom = cygwin_recvfrom +recvmsg = cygwin_recvmsg +sendmsg = cygwin_sendmsg sendto = cygwin_sendto shutdown = cygwin_shutdown sethostent diff --git a/winsup/cygwin/include/sys/socket.h b/winsup/cygwin/include/sys/socket.h index ca76419eb..51ed54e54 100644 --- a/winsup/cygwin/include/sys/socket.h +++ b/winsup/cygwin/include/sys/socket.h @@ -35,7 +35,9 @@ extern "C" int recv (int, void *__buff, int __len, unsigned int __flags); int recvfrom (int, char *__buff, int __len, int __flags, struct sockaddr *__from, int *__fromlen); + int recvmsg(int s, struct msghdr *msg, int flags); int send (int, const void *__buff, int __len, unsigned int __flags); + int sendmsg(int s, const struct msghdr *msg, int flags); int sendto (int, const void *, int, unsigned int, const struct sockaddr *, int); int setsockopt (int __s, int __level, int __optname, const void *optval, int __optlen); int getsockopt (int __s, int __level, int __optname, void *__optval, int *__optlen); diff --git a/winsup/cygwin/net.cc b/winsup/cygwin/net.cc index c73a5af18..790b0990e 100644 --- a/winsup/cygwin/net.cc +++ b/winsup/cygwin/net.cc @@ -34,6 +34,7 @@ details. */ #include "sigproc.h" #include "pinfo.h" #include "registry.h" +#include extern "C" { int h_errno; @@ -2519,3 +2520,63 @@ extern "C" void endhostent (void) { } + +/* exported as recvmsg: standards? */ +extern "C" int +cygwin_recvmsg(int s, struct msghdr *msg, int flags) +{ + int ret, nb; + size_t tot = 0; + int i; + char *buf, *p; + struct iovec *iov = msg->msg_iov; + + for(i = 0; i < msg->msg_iovlen; ++i) + tot += iov[i].iov_len; + buf = (char *) malloc(tot); + if (tot != 0 && buf == NULL) { + errno = ENOMEM; + return -1; + } + nb = ret = cygwin_recvfrom (s, buf, tot, flags, + (struct sockaddr *) msg->msg_name, (int *) &msg->msg_namelen); + p = buf; + while (nb > 0) { + ssize_t cnt = min(nb, iov->iov_len); + + memcpy (iov->iov_base, p, cnt); + p += cnt; + nb -= cnt; + ++iov; + } + free(buf); + return ret; +} + +/* exported as sendmsg: standards? */ +extern "C" int +cygwin_sendmsg(int s, const struct msghdr *msg, int flags) +{ + int ret; + size_t tot = 0; + int i; + char *buf, *p; + struct iovec *iov = msg->msg_iov; + + for(i = 0; i < msg->msg_iovlen; ++i) + tot += iov[i].iov_len; + buf = (char *) malloc(tot); + if (tot != 0 && buf == NULL) { + errno = ENOMEM; + return -1; + } + p = buf; + for (i = 0; i < msg->msg_iovlen; ++i) { + memcpy (p, iov[i].iov_base, iov[i].iov_len); + p += iov[i].iov_len; + } + ret = cygwin_sendto (s, buf, tot, flags, + (struct sockaddr *) msg->msg_name, msg->msg_namelen); + free (buf); + return ret; +} \ No newline at end of file -- 2.43.5