]> git.ipfire.org Git - thirdparty/openssl.git/commitdiff
packet: add new utility function PACKET_get_4_len()
authorPauli <ppzgs1@gmail.com>
Wed, 25 Jun 2025 23:03:38 +0000 (09:03 +1000)
committerPauli <ppzgs1@gmail.com>
Thu, 10 Jul 2025 09:04:37 +0000 (19:04 +1000)
Get 4 bytes in network order from |pkt| and store the value in |*data|
Similar to PACKET_get_net_4() except the data is uint32_t

Reviewed-by: Viktor Dukhovni <viktor@openssl.org>
Reviewed-by: Matt Caswell <matt@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/27885)

include/internal/packet.h

index 6fcd345ce28def8728ea84be59fff9bafd9c381c..7720167fca878615791280859e9b2fd41da8ba2c 100644 (file)
@@ -274,6 +274,25 @@ __owur static ossl_inline int PACKET_get_net_4_len(PACKET *pkt, size_t *data)
     return ret;
 }
 
+/**
+ * @brief Get 4 bytes in network order from |pkt| and store the value in |*data|
+ * Similar to PACKET_get_net_4() except the data is uint32_t
+ *
+ * @param pkt Contains a buffer to read from
+ * @param data The object to write the data to.
+ * @returns 1 on success, or 0 otherwise.
+ */
+static ossl_unused ossl_inline
+int PACKET_get_net_4_len_u32(PACKET *pkt, uint32_t *data)
+{
+    size_t i = 0;
+    int ret = PACKET_get_net_4_len(pkt, &i);
+
+    if (ret)
+        *data = (uint32_t)i;
+    return ret;
+}
+
 /* Get 8 bytes in network order from |pkt| and store the value in |*data| */
 __owur static ossl_inline int PACKET_get_net_8(PACKET *pkt, uint64_t *data)
 {