]> git.meshlink.io Git - catta/blobdiff - src/compat/windows/wincompat.c
add wsa error code to errnostrsocket for easier error lookup
[catta] / src / compat / windows / wincompat.c
index 9aecac44340b1f204b8488e333c33f869581a7f8..63f3e7de1469a6cc71a348c796aee6b7655763be 100644 (file)
@@ -3,6 +3,7 @@
 #include <stdlib.h>
 #include <assert.h>
 #include <stdint.h>
+#include <stdio.h>
 
 #include <catta/log.h>
 
@@ -50,8 +51,10 @@ char *errnostrsocket(void)
 {
     static char buf[256];
 
+    int err = WSAGetLastError();
+    int len = snprintf(buf, sizeof(buf), "[%i] ", err);
     FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,
-                  NULL, WSAGetLastError(), 0, buf, sizeof(buf), NULL);
+                  NULL, err, 0, buf + len, sizeof(buf) - len, NULL);
 
     return buf;
 }
@@ -138,7 +141,6 @@ ssize_t recvmsg(int sockfd, struct msghdr *msg, int flags)
     msg->msg_flags = (int)wsamsg.dwFlags;
         // all flags that fit into dwFlags also fit into msg_flags (see above)
 
-    catta_log_debug("recvmsg: %u bytes received", (unsigned int)bytesrcvd);
     return bytesrcvd;
 }
 
@@ -215,23 +217,12 @@ ssize_t sendmsg(int sockfd, const struct msghdr *msg, int flags)
         return -1;
     }
 
-    // XXX debug, remove
-    {
-        char where[64];
-        struct sockaddr *sa = msg->msg_name;
-
-        if(sa->sa_family == AF_INET)
-            inet_ntop(sa->sa_family, &((struct sockaddr_in *)sa)->sin_addr, where, sizeof(where));
-        else
-            inet_ntop(sa->sa_family, &((struct sockaddr_in6 *)sa)->sin6_addr, where, sizeof(where));
-        catta_log_debug("sendmsg: %u bytes to %s", (unsigned int)bytessent, where);
-    }
     return bytessent;
 }
 
 int ioctl(int d, unsigned long request, int *p)
 {
-    u_long arg = 0;
+    u_long arg = *p;
 
     if(ioctlsocket(d, request, &arg) == SOCKET_ERROR) {
         errno = wsa_errno();
@@ -249,11 +240,11 @@ int ioctl(int d, unsigned long request, int *p)
 
 int pipe(int pipefd[2])
 {
-    int lsock = INVALID_SOCKET;
+    int lsock = (int)INVALID_SOCKET;
     struct sockaddr_in laddr;
     socklen_t laddrlen = sizeof(laddr);
 
-    pipefd[0] = pipefd[1] = INVALID_SOCKET;
+    pipefd[0] = pipefd[1] = (int)INVALID_SOCKET;
 
     // bind a listening socket to a TCP port on localhost
     laddr.sin_family = AF_INET;
@@ -306,7 +297,8 @@ int uname(struct utsname *buf)
     strncpy(buf->version, "unknown", sizeof(buf->sysname)-1);   // we don't need it
 
     // computer (node) name
-    if(GetComputerName(buf->nodename, sizeof(buf->nodename)-1) == 0) {
+    DWORD nodename_size = sizeof(buf->nodename)-1;
+    if(GetComputerName(buf->nodename, &nodename_size) == 0) {
         errno = EFAULT;
         return -1;
     }