]> git.puffer.fish Git - mirror/frr.git/commitdiff
tools: Add coccinelle script to replace inet_ntop inside JSON
authorDonatas Abraitis <donatas.abraitis@gmail.com>
Thu, 18 Nov 2021 08:55:13 +0000 (10:55 +0200)
committerDonatas Abraitis <donatas.abraitis@gmail.com>
Thu, 18 Nov 2021 09:32:46 +0000 (11:32 +0200)
Signed-off-by: Donatas Abraitis <donatas.abraitis@gmail.com>
tools/coccinelle/json_object_string_addf.cocci [new file with mode: 0644]

diff --git a/tools/coccinelle/json_object_string_addf.cocci b/tools/coccinelle/json_object_string_addf.cocci
new file mode 100644 (file)
index 0000000..d9f92e5
--- /dev/null
@@ -0,0 +1,19 @@
+@@
+identifier json;
+expression family, buf, value;
+constant key, buflen;
+@@
+
+(
+-json_object_string_add(json, key, inet_ntop(AF_INET, &value, buf, sizeof(buf)));
++json_object_string_addf(json, key, "%pI4", &value);
+|
+-json_object_string_add(json, key, inet_ntop(AF_INET, &value, buf, buflen));
++json_object_string_addf(json, key, "%pI4", &value);
+|
+-json_object_string_add(json, key, inet_ntop(AF_INET6, &value, buf, sizeof(buf)));
++json_object_string_addf(json, key, "%pI6", &value);
+|
+-json_object_string_add(json, key, inet_ntop(AF_INET6, &value, buf, buflen));
++json_object_string_addf(json, key, "%pI6", &value);
+)