diff options
author | Sebastian Dröge <sebastian@centricular.com> | 2023-06-09 10:28:43 +0300 |
---|---|---|
committer | Tim-Philipp Müller <tim@centricular.com> | 2023-06-12 14:08:23 +0100 |
commit | 74cb9a90addf51ace4b4b0328a355fb5ab6950bc (patch) | |
tree | 452f076749c2d9fc326c6f339e323fe76d290265 | |
parent | 14f0d6c18da0cf3ccdf2ce080052d0c158994c85 (diff) |
ptp: Correctly parse clock ID from the commandline parameters in the helper
Fixes https://gitlab.freedesktop.org/gstreamer/gstreamer/-/issues/2652
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/4838>
-rw-r--r-- | subprojects/gstreamer/libs/gst/helpers/gst-ptp-helper.c | 29 |
1 files changed, 28 insertions, 1 deletions
diff --git a/subprojects/gstreamer/libs/gst/helpers/gst-ptp-helper.c b/subprojects/gstreamer/libs/gst/helpers/gst-ptp-helper.c index 4e8ab3624f..05319443ca 100644 --- a/subprojects/gstreamer/libs/gst/helpers/gst-ptp-helper.c +++ b/subprojects/gstreamer/libs/gst/helpers/gst-ptp-helper.c @@ -71,10 +71,37 @@ static gboolean verbose = FALSE; static guint64 clock_id = (guint64) - 1; static guint8 clock_id_array[8]; +static gboolean +parse_clock_id (const gchar * option_name, const gchar * value, gpointer data, + GError ** err) +{ + gchar *endptr; + guint64 v; + + errno = 0; + v = g_ascii_strtoull (value, &endptr, 16); + if (endptr == NULL || *endptr != '\0') { + g_set_error (err, G_OPTION_ERROR, G_OPTION_ERROR_UNKNOWN_OPTION, + "Cannot parse integer value \"%s\" for --clock-id", value); + return FALSE; + } + + if (errno != 0) { + g_set_error (err, G_OPTION_ERROR, G_OPTION_ERROR_UNKNOWN_OPTION, + "Cannot parse integer value \"%s\" for --clock-id: %s", value, + g_strerror (errno)); + return FALSE; + } + + clock_id = v; + + return TRUE; +} + static GOptionEntry opt_entries[] = { {"interface", 'i', 0, G_OPTION_ARG_STRING_ARRAY, &ifaces, "Interface to listen on", NULL}, - {"clock-id", 'c', 0, G_OPTION_ARG_INT64, &clock_id, + {"clock-id", 'c', 0, G_OPTION_ARG_CALLBACK, parse_clock_id, "PTP clock id", NULL}, {"verbose", 'v', 0, G_OPTION_ARG_NONE, &verbose, "Be verbose", NULL}, |