From cdcfbb2280fc6b247ea44243bb6c719dffe8c145 Mon Sep 17 00:00:00 2001
From: Christophe Massiot <massiot@videolan.org>
Date: Wed, 21 Dec 2016 17:34:53 +0000
Subject: [PATCH] Set IP_HDRINCL on raw socket - we supply our own IP header

commit 4bc7d9cf77864ea32367cd80e37daa2ea1c630eb
Author: Dmitry Marakasov <amdmi3@amdmi3.ru>
Date:   Fri Oct 7 17:30:42 2016 +0300
---
 util.c | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/util.c b/util.c
index ea3a9d3..d6007d9 100644
--- a/util.c
+++ b/util.c
@@ -555,6 +555,7 @@ int OpenSocket( const char *_psz_arg, int i_ttl, uint16_t i_bind_port,
     in_addr_t i_raw_srcaddr = INADDR_ANY; 
     int i_raw_srcport = 0;
     char *psz_ifname = NULL;
+    int hincl = 1;
 
     bind_addr.ss.ss_family = AF_UNSPEC;
     connect_addr.ss.ss_family = AF_UNSPEC;
@@ -709,6 +710,13 @@ int OpenSocket( const char *_psz_arg, int i_ttl, uint16_t i_bind_port,
                 i_raw_srcaddr, connect_addr.sin.sin_addr.s_addr, i_raw_srcport,
                 ntohs(connect_addr.sin.sin_port), i_ttl, i_tos, 0);
             i_fd = socket( AF_INET, SOCK_RAW, IPPROTO_RAW );
+#ifdef __FreeBSD__
+            if ( setsockopt( i_fd, IPPROTO_IP, IP_HDRINCL, &hincl, sizeof(hincl)) == -1 )
+            {
+                msg_Err( NULL, "unable to set socket (%s)", strerror(errno) );
+                exit(EXIT_FAILURE);
+            }
+#endif
         } else
             i_fd = socket( i_family, *pb_tcp ? SOCK_STREAM : SOCK_DGRAM, 0);
 
-- 
GitLab