aboutsummaryrefslogtreecommitdiff
path: root/net
diff options
context:
space:
mode:
authorMartin Peach <mrpeach@users.sourceforge.net>2010-08-06 23:15:53 +0000
committerMartin Peach <mrpeach@users.sourceforge.net>2010-08-06 23:15:53 +0000
commit759f8f8f80ae5d9c5e6cd4e500456bd388777f1f (patch)
tree8d154d59f96a55efccf73edce77b2fe4dfd33e50 /net
parent9dc956a29108c6d339884fc8687ad0ccdd4684d7 (diff)
Don't allow setting multicast ttl or loopback if not connected.
svn path=/trunk/externals/mrpeach/; revision=13765
Diffstat (limited to 'net')
-rw-r--r--net/udpsend.c40
1 files changed, 25 insertions, 15 deletions
diff --git a/net/udpsend.c b/net/udpsend.c
index 369edae..fe8943e 100644
--- a/net/udpsend.c
+++ b/net/udpsend.c
@@ -138,6 +138,11 @@ static void udpsend_set_multicast_loopback(t_udpsend *x, t_floatarg loop_state)
unsigned char multicast_loop_state = loop_state;
unsigned int size;
+ if (x->x_fd < 0)
+ {
+ pd_error(x, "udpsend_set_multicast_loopback: not connected");
+ return;
+ }
if (setsockopt(sockfd, IPPROTO_IP, IP_MULTICAST_LOOP,
&multicast_loop_state, sizeof(multicast_loop_state)) < 0)
udpsend_sock_err(x, "udpsend setsockopt IP_MULTICAST_LOOP");
@@ -151,6 +156,11 @@ static void udpsend_set_multicast_ttl(t_udpsend *x, t_floatarg ttl_hops)
unsigned char multicast_ttl = ttl_hops;
unsigned int size;
+ if (x->x_fd < 0)
+ {
+ pd_error(x, "udpsend_set_multicast_ttl: not connected");
+ return;
+ }
if (setsockopt(sockfd, IPPROTO_IP, IP_MULTICAST_TTL,
&multicast_ttl, sizeof(multicast_ttl)) < 0)
udpsend_sock_err(x, "udpsend setsockopt IP_MULTICAST_TTL");
@@ -380,24 +390,24 @@ static void udpsend_sock_err(t_udpsend *x, char *err_string)
{
/* prints the last error from errno or WSAGetLastError() */
#ifdef _WIN32
- LPVOID lpMsgBuf;
- DWORD dwRetVal = WSAGetLastError();
- int len = 0, i;
- char *cp;
+ void *lpMsgBuf;
+ unsigned long errornumber = 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))
+ , NULL, errornumber, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), (LPSTR)&lpMsgBuf, 0, NULL))
{
- 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);
+ 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, errornumber);
LocalFree(lpMsgBuf);
}
#else