tizen 2.0 init
[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 #ifndef WINVER
33 #define WINVER 0x0501
34 #endif
35 #include <winsock2.h>
36 #include <ws2tcpip.h>
37 #ifndef socklen_t
38 #define socklen_t int
39 #endif
40
41 /* Needed for GstObject and GST_WARNING_OBJECT */
42 #include <gst/gstobject.h>
43 #include <gst/gstinfo.h>
44
45 #else
46 #include <sys/time.h>
47 #include <sys/socket.h>
48 #include <netinet/in.h>
49 #include <net/if.h>
50 #include <netdb.h>
51 #include <sys/wait.h>
52 #include <arpa/inet.h>
53 #include <unistd.h>
54 #include <sys/ioctl.h>
55 #endif
56
57 #include <fcntl.h>
58
59 #ifdef G_OS_WIN32
60
61 #define IOCTL_SOCKET ioctlsocket
62 #define CLOSE_SOCKET(sock) closesocket(sock)
63 #define setsockopt(sock,l,opt,val,len) setsockopt(sock,l,opt,(char *)(val),len)
64 #define WSA_STARTUP(obj) gst_udp_net_utils_win32_wsa_startup(GST_OBJECT(obj))
65 #define WSA_CLEANUP(obj) WSACleanup ()
66
67 #else
68
69 #define IOCTL_SOCKET ioctl
70 #define CLOSE_SOCKET(sock) close(sock)
71 #define setsockopt(sock,l,opt,val,len) setsockopt(sock,l,opt,(void *)(val),len)
72 #define WSA_STARTUP(obj)
73 #define WSA_CLEANUP(obj)
74
75 #endif
76
77 #ifdef G_OS_WIN32
78
79 gboolean gst_udp_net_utils_win32_wsa_startup (GstObject * obj);
80
81 #endif
82
83 typedef struct {
84   gchar    *host;
85   gint      port;
86   gboolean  is_ipv6;
87 } GstUDPUri;
88
89 int     gst_udp_get_sockaddr_length  (struct sockaddr_storage *addr);
90
91 int     gst_udp_get_addr             (const char *hostname, int port, struct sockaddr_storage *addr);
92 int     gst_udp_is_multicast         (struct sockaddr_storage *addr);
93
94 int     gst_udp_set_loop             (int sockfd, guint16 ss_family, gboolean loop);
95 int     gst_udp_set_ttl              (int sockfd, guint16 ss_family, int ttl, gboolean is_multicast);
96
97 /* multicast groups */
98 int     gst_udp_join_group           (int sockfd, struct sockaddr_storage *addr,
99                                       gchar *iface);
100 int     gst_udp_leave_group          (int sockfd, struct sockaddr_storage *addr);
101
102 /* uri handling */
103 void    gst_udp_uri_init             (GstUDPUri *uri, const gchar *host, gint port);
104 int     gst_udp_uri_update           (GstUDPUri *uri, const gchar *host, gint port);
105 int     gst_udp_parse_uri            (const gchar *uristr, GstUDPUri *uri);
106 gchar * gst_udp_uri_string           (GstUDPUri *uri);
107 void    gst_udp_uri_free             (GstUDPUri *uri);
108
109 #endif /* __GST_UDP_NET_UTILS_H__*/
110