aboutsummaryrefslogtreecommitdiff
path: root/net
diff options
context:
space:
mode:
authorMartin Peach <mrpeach@users.sourceforge.net>2010-08-05 18:52:27 +0000
committerMartin Peach <mrpeach@users.sourceforge.net>2010-08-05 18:52:27 +0000
commite235fd08762e573955760bcc82a65c88c75e1089 (patch)
treeb424e0387c91e31014024370f95460456106fb58 /net
parent929e553d64e8d52739a667445960b18452f685a3 (diff)
Fixed bugs in _WIN32 socket error reporting.
svn path=/trunk/externals/mrpeach/; revision=13755
Diffstat (limited to 'net')
-rw-r--r--net/udpsend.c36
1 files changed, 20 insertions, 16 deletions
diff --git a/net/udpsend.c b/net/udpsend.c
index 6890146..369edae 100644
--- a/net/udpsend.c
+++ b/net/udpsend.c
@@ -164,9 +164,7 @@ static void udpsend_set_multicast_interface (t_udpsend *x, t_symbol *s, int argc
int i, n_ifaces = 32;
PMIB_IPADDRTABLE pIPAddrTable;
DWORD dwSize;
- DWORD dwRetVal = 0;
IN_ADDR IPAddr;
- LPVOID lpMsgBuf;
int if_index = -1;
int found = 0;
t_symbol *interfacename = gensym("none");
@@ -204,15 +202,9 @@ static void udpsend_set_multicast_interface (t_udpsend *x, t_symbol *s, int argc
post("udpsend: unable to allocate %lu bytes for GetIpAddrTable", dwSize);
return;
}
- if ((dwRetVal = GetIpAddrTable(pIPAddrTable, &dwSize, 0)) != NO_ERROR)
+ if (GetIpAddrTable(pIPAddrTable, &dwSize, 0))
{
- post("udpsend: GetIpAddrTable failed with error %d", dwRetVal);
- if (FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, NULL, dwRetVal, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language
- (LPTSTR) & lpMsgBuf, 0, NULL))
- {
- post("udpsend: %s", lpMsgBuf);
- LocalFree(lpMsgBuf);
- }
+ udpsend_sock_err(x, "udpsend_set_multicast_interface: GetIpAddrTable");
return;
}
@@ -386,14 +378,26 @@ static void udpsend_set_multicast_interface (t_udpsend *x, t_symbol *s, int argc
static void udpsend_sock_err(t_udpsend *x, char *err_string)
{
-/* prints the last error from errno or WSAGetLasError() */
+/* prints the last error from errno or WSAGetLastError() */
#ifdef _WIN32
- LPVOID lpMsgBuf;
- if (FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS
- , NULL, dwRetVal, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), (LPTSTR) & lpMsgBuf, 0, NULL))
+ LPVOID lpMsgBuf;
+ DWORD dwRetVal = WSAGetLastError();
+ int len = 0, i;
+ char *cp;
+
+ if (len = FormatMessageA(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS
+ , NULL, dwRetVal, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), (LPSTR)&lpMsgBuf, 0, NULL))
{
- pd_error(x, "%s: %s (%d)", err_string, WSAGetLastError());
- post("udpsend: %s", lpMsgBuf);
+ cp = (char *)lpMsgBuf;
+ for(i = 0; i < len; ++i)
+ {
+ if (cp[i] < 0x20)
+ { /* end string at first weird character */
+ cp[i] = 0;
+ break;
+ }
+ }
+ pd_error(x, "%s: %s (%d)", err_string, lpMsgBuf, dwRetVal);
LocalFree(lpMsgBuf);
}
#else