summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorValery Ivanov <ivalery111@gmail.com>2021-05-08 13:55:34 +0300
committerValery Ivanov <ivalery111@gmail.com>2021-05-08 13:55:34 +0300
commit99902ca28e4c04697414451187298be3f70debb5 (patch)
tree2d8e375070e49c22075957bdae188640954bbbc7 /src
parent1aab3f56d237076f8cf515c6809847f30e09ec67 (diff)
downloadlibnet-99902ca28e4c04697414451187298be3f70debb5.tar.gz
feat(functions): add libnet_build_lldp_org_spec function
Diffstat (limited to 'src')
-rw-r--r--src/libnet_build_lldp.c59
1 files changed, 59 insertions, 0 deletions
diff --git a/src/libnet_build_lldp.c b/src/libnet_build_lldp.c
index c49fb8f..62c5885 100644
--- a/src/libnet_build_lldp.c
+++ b/src/libnet_build_lldp.c
@@ -257,6 +257,65 @@ bad:
return (-1);
}
+LIBNET_API
+libnet_ptag_t libnet_build_lldp_org_spec(const uint8_t *const value,
+const uint16_t value_s, libnet_t *l, libnet_ptag_t ptag)
+{
+ uint32_t n, h;
+ libnet_pblock_t *p;
+ struct libnet_lldp_hdr hdr;
+ memset(&hdr, 0, sizeof(struct libnet_lldp_hdr));
+
+ if (l == NULL) {
+ return (-1);
+ }
+
+ if(value == NULL)
+ {
+ snprintf(l->err_buf, LIBNET_ERRBUF_SIZE,
+ "%s(): Organization Specific string is NULL", __func__);
+ return (-1);
+ }
+
+ if((value_s < 4) || (value_s > 511))
+ {
+ snprintf(l->err_buf, LIBNET_ERRBUF_SIZE,
+ "%s(): Incorrect TLV information string length", __func__);
+ return (-1);
+ }
+
+ LIBNET_LLDP_TLV_SET_TYPE(hdr.tlv_info, LIBNET_LLDP_ORG_SPEC);
+ LIBNET_LLDP_TLV_SET_LEN(hdr.tlv_info, value_s);
+
+ /* size of memory block */
+ n = h = LIBNET_LLDP_TLV_HDR_SIZE + /* TLV Header size */
+ value_s; /* TLV Information length*/
+
+ /*
+ * Find the existing protocol block if a ptag is specified, or create
+ * a new one.
+ */
+ p = libnet_pblock_probe(l, ptag, n, LIBNET_PBLOCK_LLDP_ORG_SPEC_H);
+ if (p == NULL) {
+ return (-1);
+ }
+
+ const uint16_t type_and_len = htons(hdr.tlv_info);
+ if (libnet_pblock_append(l, p, &type_and_len, sizeof(type_and_len)) == -1)
+ {
+ goto bad;
+ }
+
+ if (libnet_pblock_append(l, p, value, value_s) == -1) {
+ goto bad;
+ }
+
+ return (ptag ? ptag : libnet_pblock_update(l, p, h, LIBNET_PBLOCK_LLDP_ORG_SPEC_H));
+bad:
+ libnet_pblock_delete(l, p);
+ return (-1);
+}
+
/**
* Local Variables:
* indent-tabs-mode: nil