upload tizen1.0 source
[framework/multimedia/gst-plugins-good0.10.git] / gst / udp / gstudpnetutils.h
1 /* GStreamer UDP network utility functions
2  * Copyright (C) 2006 Tim-Philipp Müller <tim centricular net>
3  * Copyright (C) 2006 Joni Valtanen <joni.valtanen@movial.fi>
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Library General Public
7  * License as published by the Free Software Foundation; either
8  * version 2 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  * Library General Public License for more details.
14  *
15  * You should have received a copy of the GNU Library General Public
16  * License along with this library; if not, write to the
17  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18  * Boston, MA 02111-1307, USA.
19  */
20
21 #ifndef __GST_UDP_NET_UTILS_H__
22 #define __GST_UDP_NET_UTILS_H__
23
24 #include <sys/types.h>
25
26 /* Needed for G_OS_XXXX */
27 #include <glib.h>
28
29 #ifdef G_OS_WIN32
30 /* ws2_32.dll has getaddrinfo and freeaddrinfo on Windows XP and later.
31  * minwg32 headers check WINVER before allowing the use of these */
32 #define WINVER 0x0501
33 #include <winsock2.h>
34 #include <ws2tcpip.h>
35 #ifndef socklen_t
36 #define socklen_t int
37 #endif
38
39 /* Needed for GstObject and GST_WARNING_OBJECT */
40 #include <gst/gstobject.h>
41 #include <gst/gstinfo.h>
42
43 #else
44 #include <sys/time.h>
45 #include <sys/socket.h>
46 #include <netinet/in.h>
47 #include <net/if.h>
48 #include <netdb.h>
49 #include <sys/wait.h>
50 #include <arpa/inet.h>
51 #include <unistd.h>
52 #include <sys/ioctl.h>
53 #endif
54
55 #include <fcntl.h>
56
57 #ifdef G_OS_WIN32
58
59 #define IOCTL_SOCKET ioctlsocket
60 #define CLOSE_SOCKET(sock) closesocket(sock)
61 #define setsockopt(sock,l,opt,val,len) setsockopt(sock,l,opt,(char *)(val),len)
62 #define WSA_STARTUP(obj) gst_udp_net_utils_win32_wsa_startup(GST_OBJECT(obj))
63 #define WSA_CLEANUP(obj) WSACleanup ()
64
65 #else
66
67 #define IOCTL_SOCKET ioctl
68 #define CLOSE_SOCKET(sock) close(sock)
69 #define setsockopt(sock,l,opt,val,len) setsockopt(sock,l,opt,(void *)(val),len)
70 #define WSA_STARTUP(obj)
71 #define WSA_CLEANUP(obj)
72
73 #endif
74
75 #ifdef G_OS_WIN32
76
77 gboolean gst_udp_net_utils_win32_wsa_startup (GstObject * obj);
78
79 #endif
80
81 typedef struct {
82   gchar    *host;
83   gint      port;
84   gboolean  is_ipv6;
85 } GstUDPUri;
86
87 int     gst_udp_get_sockaddr_length  (struct sockaddr_storage *addr);
88
89 int     gst_udp_get_addr             (const char *hostname, int port, struct sockaddr_storage *addr);
90 int     gst_udp_is_multicast         (struct sockaddr_storage *addr);
91
92 int     gst_udp_set_loop             (int sockfd, guint16 ss_family, gboolean loop);
93 int     gst_udp_set_ttl              (int sockfd, guint16 ss_family, int ttl, gboolean is_multicast);
94
95 /* multicast groups */
96 int     gst_udp_join_group           (int sockfd, struct sockaddr_storage *addr,
97                                       gchar *iface);
98 int     gst_udp_leave_group          (int sockfd, struct sockaddr_storage *addr);
99
100 /* uri handling */
101 void    gst_udp_uri_init             (GstUDPUri *uri, const gchar *host, gint port);
102 int     gst_udp_uri_update           (GstUDPUri *uri, const gchar *host, gint port);
103 int     gst_udp_parse_uri            (const gchar *uristr, GstUDPUri *uri);
104 gchar * gst_udp_uri_string           (GstUDPUri *uri);
105 void    gst_udp_uri_free             (GstUDPUri *uri);
106
107 #endif /* __GST_UDP_NET_UTILS_H__*/
108