Fix memcpy

This commit is contained in:
Vadim Vetrov 2024-09-19 22:28:32 +03:00
parent 5415bc37ec
commit 2fd3107401
No known key found for this signature in database
GPG Key ID: E8A308689D7A73A5
3 changed files with 7 additions and 18 deletions

View File

@ -65,16 +65,8 @@ static int send_raw_ipv4(const uint8_t *pkt, uint32_t pktlen) {
memset(&msg, 0, sizeof(msg));
#if LINUX_VERSION_CODE >= KERNEL_VERSION(3, 19, 0)
iov.iov_base = (__u8 *)pkt;
iov.iov_len = pktlen;
iov_iter_kvec(&msg.msg_iter, READ, &iov, 1, 1);
#else
iov.iov_base = (__u8 *)pkt;
iov.iov_len = pktlen;
// msg.msg_iov = (struct iovec *)&iov;
// msg.msg_iovlen = iov.iov_len;
#endif
msg.msg_flags = 0;
msg.msg_name = &daddr;
@ -133,16 +125,8 @@ int send_raw_ipv6(const uint8_t *pkt, uint32_t pktlen) {
struct msghdr msg;
memset(&msg, 0, sizeof(msg));
#if LINUX_VERSION_CODE >= KERNEL_VERSION(3, 19, 0)
iov.iov_base = (__u8 *)pkt;
iov.iov_len = pktlen;
iov_iter_kvec(&msg.msg_iter, READ, &iov, 1, 1);
#else
iov.iov_base = (__u8 *)pkt;
iov.iov_len = pktlen;
// msg.msg_iov = (struct iovec *)&iov;
// msg.msg_iovlen = iov.iov_len;
#endif
msg.msg_flags = 0;
msg.msg_name = &daddr;

View File

@ -1037,7 +1037,12 @@ int fail_packet(uint8_t *payload, uint32_t *plen, uint32_t avail_buflen) {
return -1;
}
uint8_t *ndata = data + delta;
memcpy(ndata, data, dlen);
uint8_t *ndptr = ndata + dlen;
uint8_t *dptr = data + dlen;
for (size_t i = dlen + 1; i > 0; i--) {
*ndptr = *dptr;
--ndptr, --dptr;
}
data = ndata;
tcph_len = tcph_len + delta;
tcph->doff = tcph_len >> 2;

View File

@ -93,7 +93,7 @@ typedef __u64 uint64_t;
*/
#ifdef KERNEL_SPACE
#include <linux/gfp.h>
#define NETBUF_ALLOC(buf, buf_len) __u8* buf = kmalloc(buf_len, GFP_ATOMIC);
#define NETBUF_ALLOC(buf, buf_len) __u8* buf = kmalloc(buf_len, GFP_KERNEL);
#define NETBUF_CHECK(buf) ((buf) != NULL)
#define NETBUF_FREE(buf) kfree(buf);
#elif defined(ALLOC_MALLOC)