libpcap icon indicating copy to clipboard operation
libpcap copied to clipboard

sendpacket on socket cooked mode

Open ghost opened this issue 7 years ago • 3 comments

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:

  1. sll_ifindex with the index of interface, we have in handlep->ifindex
  2. 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.

ghost avatar Mar 17 '18 14:03 ghost

Yes, I think that is correct. @guyharris, can you confirm?

mcr avatar Apr 18 '19 18:04 mcr

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.

Oppen avatar Oct 04 '19 04:10 Oppen

@etmatrix, could you please explain the practical problem you were trying to solve?

infrastation avatar Nov 11 '21 23:11 infrastation

Closing as abandoned.

infrastation avatar Dec 29 '22 00:12 infrastation