aboutsummaryrefslogtreecommitdiffstats
path: root/wiretap/wtap_opttypes.c
diff options
context:
space:
mode:
authorMichael Mann <mmann78@netscape.net>2016-05-19 22:28:43 -0400
committerMichael Mann <mmann78@netscape.net>2016-05-22 23:39:14 +0000
commit81d65ccec65c9bbe972fcb64933fc34d9679562c (patch)
treec84fcfbb3befcd535b470310a8d8cf48b63dfc1e /wiretap/wtap_opttypes.c
parent6a992182ce47d721ce73eabf99983cea480dcf97 (diff)
Add wtap_optionblock_set_option_string_format
Also add a length parameter to wtap_optionblock_set_option_string Change-Id: I8c7bbc48aa96b5c2a91ab9a17980928d6894f1ee Reviewed-on: https://code.wireshark.org/review/15505 Reviewed-by: Anthony Coddington <anthony.coddington@endace.com> Reviewed-by: Michael Mann <mmann78@netscape.net>
Diffstat (limited to 'wiretap/wtap_opttypes.c')
-rw-r--r--wiretap/wtap_opttypes.c23
1 files changed, 21 insertions, 2 deletions
diff --git a/wiretap/wtap_opttypes.c b/wiretap/wtap_opttypes.c
index 7ae09a3669..9c53b48a9d 100644
--- a/wiretap/wtap_opttypes.c
+++ b/wiretap/wtap_opttypes.c
@@ -389,7 +389,7 @@ int wtap_optionblock_add_option(wtap_optionblock_t block, guint option_id, wtap_
return WTAP_OPTTYPE_SUCCESS;
}
-int wtap_optionblock_set_option_string(wtap_optionblock_t block, guint option_id, char* value)
+int wtap_optionblock_set_option_string(wtap_optionblock_t block, guint option_id, char* value, gsize value_length)
{
wtap_optblock_value_t* opt_value = wtap_optionblock_get_option(block, option_id);
@@ -401,7 +401,26 @@ int wtap_optionblock_set_option_string(wtap_optionblock_t block, guint option_id
return WTAP_OPTTYPE_TYPE_MISMATCH;
g_free(opt_value->option.stringval);
- opt_value->option.stringval = g_strdup(value);
+ opt_value->option.stringval = g_strndup(value, value_length);
+ return WTAP_OPTTYPE_SUCCESS;
+}
+
+int wtap_optionblock_set_option_string_format(wtap_optionblock_t block, guint option_id, const char *format, ...)
+{
+ va_list va;
+ wtap_optblock_value_t* opt_value = wtap_optionblock_get_option(block, option_id);
+
+ /* Didn't find the option */
+ if (opt_value == NULL)
+ return WTAP_OPTTYPE_NOT_FOUND;
+
+ if (opt_value->info->type != WTAP_OPTTYPE_STRING)
+ return WTAP_OPTTYPE_TYPE_MISMATCH;
+
+ g_free(opt_value->option.stringval);
+ va_start(va, format);
+ opt_value->option.stringval = g_strdup_vprintf(format, va);
+ va_end(va);
return WTAP_OPTTYPE_SUCCESS;
}