소스 검색

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 년 전
부모
커밋
fb20a055a0
1개의 변경된 파일5개의 추가작업 그리고 1개의 파일을 삭제
  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 */
 	*buf=udp_payload;
 	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 */
 	dst_port=ntohs(udph.dest);
-	su_setport(to, dst_port);
+	ip_addr2su(to, &dst_ip, port);
 	/* fill src_port */
 	src_port=ntohs(udph.source);
 	su_setport(from, src_port);