I want to use raw socket to send a packet.
if I create a IP packet(icmp, tcp or udp packet), then the source and destination IP is in the IP packet. now I want to send it via the following lines:
memset(&sin, 0, sizeof(sin));
sin.sin_family = AF_INET;
sin.sin_addr.s_addr = inet_addr(dst_ip);
sendto(sd, packet, 60, 0, (struct sockaddr *)&sin, sizeof(sin));
of course, the dst_ip
should be the same as the destination IP in the packet.
I'm wondering what happens if the dst_ip
is not the same as the destination IP in the packet. It seems to me that the dst_ip
is used to decide for which NIC should be used to send the packet. while the destination IP in the crafted packet is not changed by dst_ip
and will be processed by in-network routers.
is my understanding correct or not? are there any other differences?
thanks!