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 * Copyright (C) 2009 Jarkko Palviainen <jarkko.palviainen@sesca.com>
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Library General Public
8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Library General Public License for more details.
16 * You should have received a copy of the GNU Library General Public
17 * License along with this library; if not, write to the
18 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
19 * Boston, MA 02110-1301, USA.
29 #include "gstudpnetutils.h"
32 gst_udp_parse_uri (const gchar * uristr, gchar ** host, guint16 * port)
34 gchar *protocol, *location_start;
35 gchar *location, *location_end;
38 /* consider no protocol to be udp:// */
39 protocol = gst_uri_get_protocol (uristr);
42 if (strcmp (protocol, "udp") != 0)
46 location_start = gst_uri_get_location (uristr);
50 GST_DEBUG ("got location '%s'", location_start);
52 /* VLC compatibility, strip everything before the @ sign. VLC uses that as the
54 location = g_strstr_len (location_start, -1, "@");
56 location = location_start;
60 if (location[0] == '[') {
61 GST_DEBUG ("parse IPV6 address '%s'", location);
62 location_end = strchr (location, ']');
63 if (location_end == NULL)
66 *host = g_strndup (location + 1, location_end - location - 1);
67 colptr = strrchr (location_end, ':');
69 GST_DEBUG ("parse IPV4 address '%s'", location);
70 colptr = strrchr (location, ':');
73 *host = g_strndup (location, colptr - location);
75 *host = g_strdup (location);
78 GST_DEBUG ("host set to '%s'", *host);
81 *port = g_ascii_strtoll (colptr + 1, NULL, 10);
85 g_free (location_start);
92 GST_ERROR ("error parsing uri %s: no protocol", uristr);
97 GST_ERROR ("error parsing uri %s: wrong protocol (%s != udp)", uristr,
104 GST_ERROR ("error parsing uri %s", uristr);