#endif
#include "gstdccp.h"
-#include <sys/types.h>
-#include <sys/socket.h>
-#include <netinet/in.h>
-#include <arpa/inet.h>
-#include <netdb.h>
-#include <unistd.h>
-#include <sys/ioctl.h>
-#include <string.h>
#ifdef HAVE_FIONREAD_IN_SYS_FILIO
#include <sys/filio.h>
GST_DEBUG_OBJECT (element, "resolving host %s", host);
/* first check if it already is an IP address */
+#ifndef G_OS_WIN32
if (inet_aton (host, &addr)) {
+#else
+ if ((addr.S_un.S_addr = inet_addr (host)) != INADDR_NONE) {
+#endif
ip = g_strdup (host);
GST_DEBUG_OBJECT (element, "resolved to IP %s", ip);
return ip;
int maxfdp1;
int ret;
ssize_t bytes_read;
+#ifndef G_OS_WIN32
int readsize;
struct msghdr mh;
struct iovec iov;
+#else
+ unsigned long readsize;
+#endif
*buf = NULL;
}
/* ask how much is available for reading on the socket */
+#ifndef G_OS_WIN32
if ((ret = ioctl (socket, FIONREAD, &readsize)) < 0) {
GST_ELEMENT_ERROR (this, RESOURCE, READ, (NULL),
("read FIONREAD value failed: %s", g_strerror (errno)));
+#else
+ if ((ret = ioctlsocket (socket, FIONREAD, &readsize)) == SOCKET_ERROR) {
+ GST_ELEMENT_ERROR (this, RESOURCE, READ, (NULL),
+ ("read FIONREAD value failed: %s", g_strerror (WSAGetLastError ())));
+#endif
return GST_FLOW_ERROR;
}
return GST_FLOW_UNEXPECTED;
}
- *buf = gst_buffer_new_and_alloc (readsize);
-
+ *buf = gst_buffer_new_and_alloc ((int) readsize);
+#ifndef G_OS_WIN32
memset (&mh, 0, sizeof (mh));
mh.msg_name = NULL;
mh.msg_namelen = 0;
mh.msg_iovlen = 1;
bytes_read = recvmsg (socket, &mh, 0);
+#else
+ bytes_read =
+ recvfrom (socket, (char *) GST_BUFFER_DATA (*buf), (int) readsize, 0,
+ NULL, 0);
+#endif
if (bytes_read != readsize) {
GST_DEBUG_OBJECT (this, ("Error while reading data"));
gst_dccp_connect_to_server (GstElement * element, struct sockaddr_in server_sin,
int sock_fd)
{
+#ifdef G_OS_WIN32
+ int errorCode;
+#endif
GST_DEBUG_OBJECT (element, "connecting to server");
if (connect (sock_fd, (struct sockaddr *) &server_sin, sizeof (server_sin))) {
+#ifdef G_OS_WIN32
+ errorCode = WSAGetLastError ();
+ switch (errorCode) {
+ case WSAECONNREFUSED:
+ GST_ELEMENT_ERROR (element, RESOURCE, OPEN_WRITE,
+ ("Connection to %s:%d refused.", inet_ntoa (server_sin.sin_addr),
+ ntohs (server_sin.sin_port)), (NULL));
+ return FALSE;
+ break;
+ default:
+ GST_ELEMENT_ERROR (element, RESOURCE, OPEN_READ, (NULL),
+ ("Connect to %s:%d failed: %s", inet_ntoa (server_sin.sin_addr),
+ ntohs (server_sin.sin_port), g_strerror (errorCode)));
+ return FALSE;
+ break;
+ }
+#else
switch (errno) {
case ECONNREFUSED:
GST_ELEMENT_ERROR (element, RESOURCE, OPEN_WRITE,
return FALSE;
break;
}
+#endif
}
return TRUE;
}
if ((client_sock_fd =
accept (server_sock_fd, (struct sockaddr *) &client_address,
+#ifndef G_OS_WIN32
&client_address_len)) == -1) {
+#else
+ (int *) &client_address_len)) == -1) {
+#endif
GST_ELEMENT_ERROR (element, RESOURCE, OPEN_WRITE, (NULL),
("Could not accept client on server socket %d: %s (%d)",
server_sock_fd, g_strerror (errno), errno));
size_t bytes_written = 0;
ssize_t wrote;
+#ifndef G_OS_WIN32
struct iovec iov;
struct msghdr mh;
+
memset (&mh, 0, sizeof (mh));
while (bytes_written < size) {
wrote = sendmsg (socket, &mh, 0);
} while (wrote == -1 && errno == EAGAIN);
+#else
+ int errorCode = 0;
+ while (bytes_written < size) {
+ do {
+ wrote = sendto (socket, (char *) buf + bytes_written,
+ MIN (packet_size, size - bytes_written), 0, NULL, 0);
+ errorCode = WSAGetLastError ();
+ } while (wrote == SOCKET_ERROR && errorCode == EAGAIN);
+#endif
/* TODO print the send error */
bytes_written += wrote;
/*
* Determine which CCIDs are available on the host
*/
+#ifndef G_OS_WIN32
ret = getsockopt (sock_fd, SOL_DCCP, DCCP_SOCKOPT_AVAILABLE_CCIDS, &ccids,
&len);
+#else
+ ret =
+ getsockopt (sock_fd, SOL_DCCP, DCCP_SOCKOPT_AVAILABLE_CCIDS,
+ (char *) &ccids, &len);
+#endif
if (ret < 0) {
GST_ERROR_OBJECT (element, "Can not determine available CCIDs");
return FALSE;
GST_ERROR_OBJECT (element, "CCID specified is not supported");
return FALSE;
}
-
+#ifndef G_OS_WIN32
if (setsockopt (sock_fd, SOL_DCCP, DCCP_SOCKOPT_CCID, &ccid,
+#else
+ if (setsockopt (sock_fd, SOL_DCCP, DCCP_SOCKOPT_CCID, (char *) &ccid,
+#endif
sizeof (ccid)) < 0) {
GST_ERROR_OBJECT (element, "Can not set CCID");
return FALSE;
}
ccidlen = sizeof (ccid);
+#ifndef G_OS_WIN32
ret = getsockopt (sock_fd, SOL_DCCP, tx_or_rx, &ccid, &ccidlen);
+#else
+ ret = getsockopt (sock_fd, SOL_DCCP, tx_or_rx, (char *) &ccid, &ccidlen);
+#endif
if (ret < 0) {
GST_ERROR_OBJECT (element, "Can not determine available CCIDs");
return -1;
{
int size;
socklen_t sizelen = sizeof (size);
+#ifndef G_OS_WIN32
if (getsockopt (sock, SOL_DCCP, DCCP_SOCKOPT_GET_CUR_MPS,
&size, &sizelen) < 0) {
+#else
+ if (getsockopt (sock, SOL_DCCP, DCCP_SOCKOPT_GET_CUR_MPS,
+ (char *) &size, &sizelen) < 0) {
+#endif
GST_ELEMENT_ERROR (element, RESOURCE, SETTINGS, (NULL),
("Could not get current MTU %d: %s", errno, g_strerror (errno)));
return -1;
--- /dev/null
+/* GStreamer\r
+ * Copyright (C) <2007> Leandro Melo de Sales <leandroal@gmail.com>\r
+ *\r
+ * This library is free software; you can redistribute it and/or\r
+ * modify it under the terms of the GNU Library General Public\r
+ * License as published by the Free Software Foundation; either\r
+ * version 2 of the License, or (at your option) any later version.\r
+ *\r
+ * This library is distributed in the hope that it will be useful,\r
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\r
+ * Library General Public License for more details.\r
+ *\r
+ * You should have received a copy of the GNU Library General Public\r
+ * License along with this library; if not, write to the\r
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,\r
+ * Boston, MA 02111-1307, USA.\r
+ */\r
+\r
+#ifndef __GST_DCCP_NET_H__\r
+#define __GST_DCCP_NET_H__\r
+\r
+#ifndef G_OS_WIN32\r
+# include <netdb.h>\r
+# include <sys/socket.h>\r
+# include <netinet/in.h> /* sockaddr_in */\r
+# include <arpa/inet.h>\r
+# include <sys/ioctl.h>\r
+#else\r
+/* ws2_32.dll has getaddrinfo and freeaddrinfo on Windows XP and later.\r
+ * minwg32 headers check WINVER before allowing the use of these */\r
+# define WINVER 0x0501\r
+# include <winsock2.h>\r
+# include <ws2tcpip.h>\r
+#endif\r
+#include <sys/types.h>\r
+#include <unistd.h>\r
+#include <string.h>\r
+\r
+#endif /* __GST_DCCP_NET_H__ */\r