sendpacket on socket cooked mode
I developing a patch for support sendpacket on socket cooked mode in Linux OS, but I have a doubt. In source file pcap-linux.c there is the function pcap_inject_linux where the variable cooked is checked. We can use the api sendto for send packet in an interface cooked, this api require 2 arguments more of send. First arguments are a struct sockaddr_ll and second is it length. In the struct we must set 2 fields:
- sll_ifindex with the index of interface, we have in handlep->ifindex
- sll_protocol is the protocol to use in link layer for example ETH_P_IP for ip packets
My doubt is for field sll_protocol, can I use the value returned by pcap_protocol? I have already tested this patch
if (handlep->cooked) {
struct sockaddr_ll sockaddr;
sockaddr.sll_ifindex = handlep->ifindex;
sockaddr.sll_protocol = pcap_protocol(handle);
ret = sendto(handle->fd, buf, size, 0,(struct sockaddr *)&sockaddr, sizeof(struct sockaddr_ll));
} else {
ret = send(handle->fd, buf, size, 0);
}
and injection of packets is working.
Yes, I think that is correct. @guyharris, can you confirm?
pcap_protocol returns the link layer protocol you used to open the socket, and from what I've quickly read, it seems that's what sockaddr_ll.sll_protocol expects.
@etmatrix, could you please explain the practical problem you were trying to solve?
Closing as abandoned.