Open steven-chien opened 7 years ago
Sending through a specific interface o py works when the packet you are trying to send contains a layer 2 PDU (e.g. Ethernet). When the lowest layer is 3 (e.g. IP), then it's the kernel the one that decides which interface the packet should go through.
Therefore, if you prepend an EthernetII layer before IP and use the right address, that should work as you expect it to
On Jul 30, 2017 09:39, "Steven" notifications@github.com wrote:
The follow dummy program is used to illustrate the issue. There are two interfaces on my device (Raspberry Pi): tun0 connecting to a VPN server and eth0 connecting to LAN.
I created a packet sender and explicitly ask for default interface to be eth0. (I used open_l3_socket() because in my project there are multiple writers sharing the socket from different threads). I also explicitly asked for send to deliver the packet through "eth0".
include
include <tins/tins.h>
int main(int argc, char argv[]) { Tins::PacketSender sender = new Tins::PacketSender(); sender->default_interface("eth0"); sender->open_l3_socket(Tins::PacketSender::IP_TCP_SOCKET);
Tins::IP ip_pkt("216.58.200.99", "192.168.1.210"); Tins::TCP tcp_pkt(80, 8888); tcp_pkt.set_flag(Tins::TCP::SYN, 1); tcp_pkt.seq(1733878791); tcp_pkt.ack_seq(0); ip_pkt = ip_pkt / tcp_pkt; sender->send(ip_pkt, "eth0"); return 0;
}
However the packet was still delivered through tun0 as shown from wireshare.
[image: alt text] https://camo.githubusercontent.com/ab011e480a06c709562d7792e697239eba2a6904/687474703a2f2f692e696d6775722e636f6d2f6d696364614e4c2e706e67
— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/mfontanini/libtins/issues/231, or mute the thread https://github.com/notifications/unsubscribe-auth/AA7JgkynAwPqTo7iMOuyDnL49paB2836ks5sTLG-gaJpZM4Onrrk .
The follow dummy program is used to illustrate the issue. There are two interfaces on my device (Raspberry Pi): tun0 connecting to a VPN server and eth0 connecting to LAN.
I created a packet sender and explicitly ask for default interface to be eth0. (I used open_l3_socket() because in my project there are multiple writers sharing the socket from different threads). I also explicitly asked for send to deliver the packet through "eth0".
However the packet was still delivered through tun0 as shown from wireshare.