summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/libnet/libnet-functions.h12
-rw-r--r--src/libnet_build_lldp.c46
2 files changed, 58 insertions, 0 deletions
diff --git a/include/libnet/libnet-functions.h b/include/libnet/libnet-functions.h
index 28ec4eb..867ab0d 100644
--- a/include/libnet/libnet-functions.h
+++ b/include/libnet/libnet-functions.h
@@ -774,6 +774,18 @@ libnet_ptag_t libnet_build_lldp_ttl(const uint16_t ttl,
libnet_t *l, libnet_ptag_t ptag);
/**
+ * Builds a LLDP End of LLDPDU TLV.
+ * The End of LLDPDU TLV used to mark the end of the TLV sequence in LLDPDU.
+ * Is a 2 octet all-zero TLV
+ * @param l pointer to a libnet context
+ * @param ptag protocol tag to modify an existing header, 0 to build a new one
+ * @return protocol tag value on success
+ * @retval -1 on error
+ */
+LIBNET_API
+libnet_ptag_t libnet_build_lldp_end(libnet_t *l, libnet_ptag_t ptag);
+
+/**
* Builds an IP version 4 RFC 792 Internet Control Message Protocol (ICMP)
* echo request/reply header
* @param type type of ICMP packet (should be ICMP_ECHOREPLY or ICMP_ECHO)
diff --git a/src/libnet_build_lldp.c b/src/libnet_build_lldp.c
index b0ee5fa..c49fb8f 100644
--- a/src/libnet_build_lldp.c
+++ b/src/libnet_build_lldp.c
@@ -211,6 +211,52 @@ bad:
return (-1);
}
+
+LIBNET_API
+libnet_ptag_t libnet_build_lldp_end(libnet_t *l, libnet_ptag_t ptag)
+{
+ assert(LIBNET_LLDP_TLV_HDR_SIZE == 0x02 && "TLV header size must be a 2 bytes");
+ assert(LIBNET_LLDP_SUBTYPE_SIZE == 0x01 && "Subtype field size must be 1 byte");
+
+ 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);
+ }
+
+ /* size of memory block */
+ n = h = LIBNET_LLDP_TLV_HDR_SIZE; /* TLV Header size */
+
+ LIBNET_LLDP_TLV_SET_TYPE(hdr.tlv_info, LIBNET_LLDP_END_LLDPDU);
+ LIBNET_LLDP_TLV_SET_LEN(hdr.tlv_info, 0);
+
+ /*
+ * 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_TTL_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;
+ }
+
+ return (ptag ? ptag
+ : libnet_pblock_update(l, p, h, LIBNET_PBLOCK_LLDP_TTL_H));
+bad:
+ libnet_pblock_delete(l, p);
+ return (-1);
+}
+
/**
* Local Variables:
* indent-tabs-mode: nil