I want to send a packet using write systemcall. I create the packet, it's size is 46 byte. when I send the packet in my program in wireshark the length is 60 byte, 14 byte is padding. How can I send the packet without padding.
I can not use socket commands.
struct x {
bool is_active;
bool is_owner;
int fd1;
int fd2;
char pkt_hdr[sizeof(struct ether_header) + sizeof(struct ip)];
struct interface *ifp;
int fd_bufflen;
struct ipaddr src;
uint8_t ibuf[IP_MAXPACKET];
int family;
struct vrrp_vrouter *vr;
struct list *addrs;
bool ad;
bool ga;
bool nd;
uint8_t priority;
uint16_t ma_val;
uint16_t sk_tm;
uint16_t ma_val;
struct ethaddr vmac;
struct {
int state;
} fsm;
struct {
uint32_t ad_cnt;
uint32_t ar_cnt;
uint32_t g_cnt;
uint32_t un_cnt;
uint32_t t_cnt;
} stats;
struct thread *t_ti;
struct thread *t_adti;
struct thread *t_read;
struct thread *t_write;
};
.
.
.
size_t buf_len = pktsz + sizeof r->pkt_hdr;
.
.
.
/* Ethernet Header */
struct ether_header *ether_hdr = (struct ether_header *)buf;
.
.
.
/* IP Header */
struct ip *ip_hdr = (struct ip *) (ether_hdr + 1);
ip_hdr->ip_len = htons(buf_len - sizeof(struct ether_header));
ip_hdr->ip_src = r->src.ipaddr_v4;
ip_hdr->ip_sum = in_cksum(ip_hdr, sizeof(struct ip));
/* Payload */
memcpy((void *)(buf + sizeof r->pkt_hdr), (const void *)pkt, pktsz);
ssize_t sent = write(fd, buf, buf_len);
free(buf);
buf_len is :46
pktsz : 12
sizeof r->pkt_hdr: 34
The length is 46.