TSG-7784 PacketAdapter支持CI自动构建RPM; 修改代码结构

This commit is contained in:
卢文朋
2021-09-13 02:12:29 +00:00
committed by luwenpeng
parent aa887fd382
commit ba21a53bb7
35 changed files with 2878 additions and 915 deletions

53
platform/src/inject_pkt.c Normal file
View File

@@ -0,0 +1,53 @@
#include "inject_pkt.h"
int inject_ipv4_pkt(char *ip4_addr, uint8_t *data, uint32_t len)
{
int fd = 0;
struct sockaddr_in saddr4 = {0};
saddr4.sin_family = PF_INET;
saddr4.sin_addr.s_addr = inet_addr(ip4_addr);
fd = socket(PF_INET, SOCK_RAW, IPPROTO_RAW);
if (fd == -1)
{
LOG_ERROR("Failed at socket(PF_INET, SOCK_RAW), %d: %s", errno, strerror(errno));
return -1;
}
if (sendto(fd, data, len, 0, (struct sockaddr *)&saddr4, sizeof(saddr4)) == -1)
{
LOG_ERROR("Failed at send(), %d: %s", errno, strerror(errno));
close(fd);
return -1;
}
close(fd);
return 0;
}
int inject_ipv6_pkt(char *ip6_addr, uint8_t *data, uint32_t len)
{
int fd = 0;
struct sockaddr_in6 saddr6 = {0};
saddr6.sin6_family = PF_INET6;
inet_pton(AF_INET6, ip6_addr, &saddr6.sin6_addr);
fd = socket(PF_INET6, SOCK_RAW, IPPROTO_RAW);
if (fd == -1)
{
LOG_ERROR("Failed at socket(PF_INET6, SOCK_RAW), %d: %s", errno, strerror(errno));
return -1;
}
if (sendto(fd, data, len, 0, (struct sockaddr *)&saddr6, sizeof(saddr6)) == -1)
{
LOG_ERROR("Failed at send(), %d: %s", errno, strerror(errno));
close(fd);
return -1;
}
close(fd);
return 0;
}