Merge branch 'master' into 0.11
[platform/upstream/gstreamer.git] / libs / gst / net / gstnetaddressmeta.h
1 /* GStreamer
2  * Copyright (C) <2011> Wim Taymans <wim.taymans@gmail.com>
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Library General Public
6  * License as published by the Free Software Foundation; either
7  * version 2 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * Library General Public License for more details.
13  *
14  * You should have received a copy of the GNU Library General Public
15  * License along with this library; if not, write to the
16  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17  * Boston, MA 02111-1307, USA.
18  */
19
20 #ifndef __GST_NET_ADDRESS_META_H__
21 #define __GST_NET_ADDRESS_META_H__
22
23 #include <gst/gst.h>
24
25 G_BEGIN_DECLS
26
27 typedef struct _GstNetAddress GstNetAddress;
28
29 /**
30  * GstNetType:
31  * @GST_NET_TYPE_UNKNOWN: unknown address type
32  * @GST_NET_TYPE_IP4: an IPv4 address type
33  * @GST_NET_TYPE_IP6: and IPv6 address type
34  *
35  * The Address type used in #GstNetAddress.
36  */
37 typedef enum {
38   GST_NET_TYPE_UNKNOWN,
39   GST_NET_TYPE_IP4,
40   GST_NET_TYPE_IP6,
41 } GstNetType;
42
43 /**
44  * GST_NETADDRESS_MAX_LEN:
45  *
46  * The maximum length of a string representation of a GstNetAddress as produced
47  * by gst_net_address_to_string().
48  *
49  * Since: 0.10.24
50  */
51 #define GST_NETADDRESS_MAX_LEN  64
52
53 /**
54  * GstNetAddress:
55  *
56  * An opaque network address as used in #GstNetAddressMeta.
57  */
58 struct _GstNetAddress {
59   /*< private >*/
60   GstNetType    type;
61   union {
62     guint8        ip6[16];
63     guint32       ip4;
64   } address;
65   guint16       port;
66   /*< private >*/
67   gpointer _gst_reserved[GST_PADDING];
68 };
69
70 typedef struct _GstNetAddressMeta GstNetAddressMeta;
71
72 /**
73  * GstNetAddressMeta:
74  *
75  * Buffer metadata for network addresses.
76  */
77 struct _GstNetAddressMeta {
78   GstMeta       meta;
79
80   GstNetAddress naddr;
81 };
82
83 const GstMetaInfo *gst_net_address_meta_get_info (void);
84 #define GST_NET_ADDRESS_META_INFO (gst_net_address_meta_get_info())
85
86 #define gst_buffer_get_net_address_meta(b) \
87   ((GstNetAddressMeta*)gst_buffer_get_meta((b),GST_NET_ADDRESS_META_INFO))
88 #define gst_buffer_add_net_address_meta(b) \
89   ((GstNetAddressMeta*)gst_buffer_add_meta((b),GST_NET_ADDRESS_META_INFO,NULL))
90
91 /* address operations */
92 void            gst_net_address_set_ip4_address   (GstNetAddress *naddr, guint32 address, guint16 port);
93 void            gst_net_address_set_ip6_address   (GstNetAddress *naddr, guint8 address[16], guint16 port);
94 gint            gst_net_address_set_address_bytes (GstNetAddress *naddr, GstNetType type,
95                                                    guint8 address[16], guint16 port);
96
97 GstNetType      gst_net_address_get_net_type      (const GstNetAddress *naddr);
98 gboolean        gst_net_address_get_ip4_address   (const GstNetAddress *naddr,
99                                                    guint32 *address, guint16 *port);
100 gboolean        gst_net_address_get_ip6_address   (const GstNetAddress *naddr,
101                                                    guint8 address[16], guint16 *port);
102 gint            gst_net_address_get_address_bytes (const GstNetAddress *naddr,
103                                                    guint8 address[16], guint16 *port);
104
105 gboolean        gst_net_address_equal             (const GstNetAddress *naddr1,
106                                                    const GstNetAddress *naddr2);
107
108 gint            gst_net_address_to_string         (const GstNetAddress *naddr,
109                                                    gchar *dest, gsize len);
110
111 G_END_DECLS
112
113 #endif /* __GST_NET_ADDRESS_META_H__ */
114