Module: kamailio
Branch: master
Commit: 281e8e980c70f38218844d1da0c5e257399ffda3
URL: 
https://github.com/kamailio/kamailio/commit/281e8e980c70f38218844d1da0c5e257399ffda3

Author: Giacomo Vacca <giacomo.va...@gmail.com>
Committer: Giacomo Vacca <giacomo.va...@gmail.com>
Date: 2017-02-23T11:46:45+01:00

sipcapture: add macros to pack HEPv3 chunks

---

Modified: src/modules/sipcapture/hep.h

---

Diff:  
https://github.com/kamailio/kamailio/commit/281e8e980c70f38218844d1da0c5e257399ffda3.diff
Patch: 
https://github.com/kamailio/kamailio/commit/281e8e980c70f38218844d1da0c5e257399ffda3.patch

---

diff --git a/src/modules/sipcapture/hep.h b/src/modules/sipcapture/hep.h
index 10812a2..e4ff77b 100644
--- a/src/modules/sipcapture/hep.h
+++ b/src/modules/sipcapture/hep.h
@@ -177,5 +177,52 @@ struct hep_generic_recv {
 
 typedef struct hep_generic_recv hep_generic_recv_t;
 
+#define HEP3_PACK_INIT(buf) \
+               union { \
+                       hep_chunk_uint8_t chunk8; \
+                       hep_chunk_uint16_t chunk16; \
+                       hep_chunk_uint32_t chunk32; \
+                       hep_chunk_t chunkpl; \
+                       uint16_t len; \
+               } _tmpu; \
+               char *_tmp_p = (buf); \
+               memcpy(_tmp_p, "HEP3", 4); \
+               _tmp_p += 4 + 2/* skip length */;
+
+#define HEP3_PACK_FINALIZE(buf, lenp) \
+               do { \
+                       _tmpu.len = htons(_tmp_p - (char *)(buf)); \
+                       memcpy((void *)(&(((hep_ctrl_t *)(buf))->length)), 
(void*)&_tmpu.len, 2); \
+                       *lenp = _tmp_p - (char *)(buf); \
+               } while (0)
+
+#define _HEP3_PACK_CHUNK_GENERIC(type, tmpvar, vid, tid, val) \
+               do { \
+                       (tmpvar).chunk.vendor_id = htons(vid); \
+                       (tmpvar).chunk.type_id = htons(tid); \
+                       (tmpvar).chunk.length = htons(sizeof(type)); \
+                       (tmpvar).data = (val); \
+                       memcpy(_tmp_p, (void *) &(tmpvar), sizeof(type)); \
+                       _tmp_p += sizeof(type); \
+               } while (0)
+
+#define HEP3_PACK_CHUNK_UINT8(vid, tid, val) 
_HEP3_PACK_CHUNK_GENERIC(hep_chunk_uint8_t, _tmpu.chunk8, vid, tid, val)
+#define HEP3_PACK_CHUNK_UINT16(vid, tid, val) 
_HEP3_PACK_CHUNK_GENERIC(hep_chunk_uint16_t, _tmpu.chunk16, vid, tid, 
htons(val))
+#define HEP3_PACK_CHUNK_UINT16_NBO(vid, tid, val) 
_HEP3_PACK_CHUNK_GENERIC(hep_chunk_uint16_t, _tmpu.chunk16, vid, tid, (val))
+#define HEP3_PACK_CHUNK_UINT32(vid, tid, val) 
_HEP3_PACK_CHUNK_GENERIC(hep_chunk_uint32_t, _tmpu.chunk32, vid, tid, 
htonl(val))
+#define HEP3_PACK_CHUNK_UINT32_NBO(vid, tid, val) 
_HEP3_PACK_CHUNK_GENERIC(hep_chunk_uint32_t, _tmpu.chunk32, vid, tid, (val))
+
+#define HEP3_PACK_CHUNK_DATA(vid, tid, val, len) \
+               do { \
+                       _tmpu.chunkpl.vendor_id = htons(vid); \
+                       _tmpu.chunkpl.type_id = htons(tid); \
+                       _tmpu.chunkpl.length = htons(sizeof(hep_chunk_t) + 
(len)); \
+                       memcpy(_tmp_p, (void *) &_tmpu.chunkpl, 
sizeof(hep_chunk_t)); \
+                       _tmp_p += sizeof(hep_chunk_t); \
+                       memcpy(_tmp_p, (void *) (val), len); \
+                       _tmp_p += len; \
+               } while (0)
+
+#define HEP3_PACK_CHUNK_IP6(vid, tid, paddr) HEP3_PACK_CHUNK_DATA(vid, tid, 
paddr, sizeof(struct in6_addr))
 
 #endif


_______________________________________________
sr-dev mailing list
sr-dev@lists.sip-router.org
http://lists.sip-router.org/cgi-bin/mailman/listinfo/sr-dev

Reply via email to