class PcapDnsproxy < Formula desc "Powerful DNS proxy designed to anti DNS spoofing" homepage "https://github.com/chengr28/Pcap_DNSProxy" url "https://github.com/chengr28/Pcap_DNSProxy/archive/v0.4.7.6.tar.gz" sha256 "df213ff1523a8daf4fe3bb304aacdf2fa51125867b7d7d6f1bf0da1e54939517" head "https://github.com/chengr28/Pcap_DNSProxy.git" bottle do cellar :any_skip_relocation sha256 "c48a73109d3b0b8e9efdf60adf6ec6d38662883004c9b7cb054672cbff3985b3" => :sierra sha256 "7af6ebf40b738ea02e292ba13cfd2dd651aeff2280a1cd9735179e562bf5c03c" => :el_capitan sha256 "064af6d3ff5441e3673713323164ac3b09d0e22405896aabd507f06afa9c178a" => :yosemite end depends_on :macos => :yosemite depends_on :xcode => :build depends_on "libsodium" def install (buildpath/"Source/LibSodium").install_symlink Formula["libsodium"].opt_lib/"libsodium.a" => "LibSodium_Mac.a" xcodebuild "-project", "./Source/Pcap_DNSProxy.xcodeproj", "-target", "Pcap_DNSProxy", "-configuration", "Release", "SYMROOT=build" bin.install "Source/build/Release/Pcap_DNSProxy" (etc/"pcap_DNSproxy").install Dir["Source/ExampleConfig/*.{ini,txt}"] end plist_options :startup => true, :manual => "sudo #{HOMEBREW_PREFIX}/opt/pcap_dnsproxy/bin/Pcap_DNSProxy -c #{HOMEBREW_PREFIX}/etc/pcap_dnsproxy/" def plist; <<-EOS.undent Label #{plist_name} ProgramArguments #{opt_bin}/Pcap_DNSProxy -c #{etc}/pcap_dnsproxy/ RunAtLoad KeepAlive EOS end test do (testpath/"pcap_DNSproxy").mkpath cp Dir[etc/"pcap_DNSproxy/*"], testpath/"pcap_DNSproxy/" inreplace testpath/"pcap_DNSproxy/Config.ini" do |s| s.gsub! /^Direct Request.*/, "Direct Request = IPv4 + IPv6" s.gsub! /^Operation Mode.*/, "Operation Mode = Proxy" s.gsub! /^Listen Port.*/, "Listen Port = 9999" end pid = fork { exec bin/"Pcap_DNSProxy", "-c", testpath/"pcap_DNSproxy/" } begin system "dig", "google.com", "@127.0.0.1", "-p", "9999", "+short" ensure Process.kill 9, pid Process.wait pid end end end