title: Binding/Listening to privileged port on OSX
body: <p>I have a requirement to bind a "<em>server type</em>" application to a privileged port (&lt;1024) on OS X 10.6 and higher. The application is normally executed by a user who doesn't have root privileges.</p>
  
  <p>Having read through many threads on this site I found this option to be the most current and secure way:</p>
  
  <p>1) write a helper app to open the privileged port.<br>
  2) use SMJobBless to "install" the helper app to launchd.<br>
  3) call the helper app from main app (via IPC) to retrieve the opened privileged port.</p>
  
  <p>From <a href="https://developer.apple.com/library/mac/#documentation/security/conceptual/SecureCodingGuide/Articles/AccessControl.html" rel="noreferrer">Apple documentation</a>:</p>
  
  <blockquote>
    <p>Because launchd itself runs as the root user, if your only reason for
    using a privileged process is to run a daemon on a low-numbered port,
    you can let launchd open that port on your daemon’s behalf and pass
    the open socket to your daemon, thus eliminating the need for your
    code to run as the root user.</p>
  </blockquote>
  
  <p>I'm not running a daemon just a user app but the same principles apply.</p>
  
  <p>I have
  found the <a href="http://developer.apple.com/library/mac/#samplecode/SMJobBless/Introduction/Intro.html" rel="noreferrer">code example for SMJobBless</a> and read <a href="http://atnan.com/blog/2012/02/29/modern-privileged-helper-tools-using-smjobbless-plus-xpc/" rel="noreferrer">Nathan de Vries' blog</a>.
  (can't use XPC - not available on OSX 10.6).</p>
  
  <p>I'm pretty clear on the SMJobBless / launchd coding. </p>
  
  <p><strong>My Question:</strong>
  Please point me to code example that demonstrates how to open a port in another application (i.e. helper) and pass a port handle (CFSocketRef?) back to the main application. Maybe someone can  point me to a code example that implements this via SMJobBless.</p>
  
  <p>Many Thanks</p>