Index: multicat.c =================================================================== --- multicat.c (revision 76) +++ multicat.c (working copy) @@ -44,6 +44,10 @@ #include #include +#ifdef __FreeBSD__ +# include +#endif + #ifdef SIOCGSTAMPNS # define HAVE_TIMESTAMPS #endif @@ -276,12 +280,12 @@ ssize_t i_ret; struct iovec iov[2]; - #ifdef __FAVOR_BSD + #if defined(__FreeBSD__) || defined(__FAVOR_BSD) pktheader.udph.uh_ulen #else pktheader.udph.len #endif - = htons(sizeof(struct udphdr) + i_len); + = htons(sizeof(struct udphdr) + i_len); iov[0].iov_base = &pktheader; iov[0].iov_len = sizeof(struct udprawpkt); Index: util.c =================================================================== --- util.c (revision 76) +++ util.c (working copy) @@ -451,7 +451,11 @@ uint8_t ttl, uint8_t tos, uint16_t len) { #ifndef __APPLE__ +# if defined(__FreeBSD__) + struct ip *iph = &(dgram->iph); +# else struct iphdr *iph = &(dgram->iph); +# endif struct udphdr *udph = &(dgram->udph); #ifdef DEBUG_SOCKET @@ -464,7 +468,27 @@ printf("Filling raw header (%p) (%s:%u -> %s:%u)\n", dgram, ipsrc_str, portsrc, ipdst_str, portdst); #endif + #if defined(__FreeBSD__) || defined(__FAVOR_BSD) // Fill ip header + iph->ip_hl = 5; // ip header with no specific option + iph->ip_v = 4; + iph->ip_tos = tos; + iph->ip_len = sizeof(struct udprawpkt) + len; // auto-htoned ? + iph->ip_id = htons(0); // auto-generated if frag_off (flags) = 0 ? + iph->ip_off = 0; + iph->ip_ttl = ttl; + iph->ip_p = IPPROTO_UDP; + iph->ip_sum = 0; + iph->ip_src.s_addr = ipsrc; + iph->ip_dst.s_addr = ipdst; + + // Fill udp header + udph->uh_sport = htons(portsrc); + udph->uh_dport = htons(portdst); + udph->uh_ulen = htons(sizeof(struct udphdr) + len); + udph->uh_sum = 0; + #else + // Fill ip header iph->ihl = 5; // ip header with no specific option iph->version = 4; iph->tos = tos; @@ -478,12 +502,6 @@ iph->daddr = ipdst; // Fill udp header - #ifdef __FAVOR_BSD - udph->uh_sport = htons(portsrc); - udph->uh_dport = htons(portdst); - udph->uh_ulen = htons(sizeof(struct udphdr) + len); - udph->uh_sum = 0; - #else udph->source = htons(portsrc); udph->dest = htons(portdst); udph->len = htons(sizeof(struct udphdr) + len); @@ -721,7 +739,7 @@ if ( bind_addr.ss.ss_family != AF_UNSPEC ) { - #ifndef __APPLE__ + #if !defined(__APPLE__) && !defined(__FreeBSD__) if ( IN6_IS_ADDR_MULTICAST( &bind_addr.sin6.sin6_addr ) ) { struct ipv6_mreq imr; Index: util.h =================================================================== --- util.h (revision 76) +++ util.h (working copy) @@ -24,7 +24,7 @@ #include #include -#ifdef __APPLE__ +#if defined(__APPLE__) || defined(__FreeBSD__) #define POLLRDHUP 0 /* uClibc may does not have clock_nanosleep() */ #elif !defined (__UCLIBC__) || \ @@ -58,11 +58,15 @@ * Raw udp packet structure with flexible-array payload *****************************************************************************/ struct udprawpkt { -#ifndef __APPLE__ +#if !defined(__APPLE__) +# if defined(__FreeBSD__) + struct ip iph; +# else struct iphdr iph; +# endif struct udphdr udph; +#endif uint8_t payload[]; -#endif } __attribute__((packed));