Bladeren bron

raw sockets: get dst. ip from the ip header

Get the destination ip from the packet header (when using
IP_HDRINCL we don't set PKT_INFO so we don't have the destination
information).
Andrei Pelinescu-Onciul 15 jaren geleden
bovenliggende
commit
fb20a055a0
1 gewijzigde bestanden met toevoegingen van 5 en 1 verwijderingen
  1. 5 1
      raw_sock.c

+ 5 - 1
raw_sock.c

@@ -284,9 +284,13 @@ int raw_udp4_recv(int rsock, char** buf, int len, union sockaddr_union* from,
 	/* advance buf */
 	/* advance buf */
 	*buf=udp_payload;
 	*buf=udp_payload;
 	n=(int)(end-*buf);
 	n=(int)(end-*buf);
+	/* fill ip from the packet (needed if no PKT_INFO is used) */
+	dst_ip.af=AF_INET;
+	dst_ip.len=4;
+	dst_ip.u.addr32[0]=iph.daddr;
 	/* fill dst_port */
 	/* fill dst_port */
 	dst_port=ntohs(udph.dest);
 	dst_port=ntohs(udph.dest);
-	su_setport(to, dst_port);
+	ip_addr2su(to, &dst_ip, port);
 	/* fill src_port */
 	/* fill src_port */
 	src_port=ntohs(udph.source);
 	src_port=ntohs(udph.source);
 	su_setport(from, src_port);
 	su_setport(from, src_port);