1

I'm trying to capture the data destined for a "networked printer" so it can be processed locally or forwarded to another system. It looks like Linux as a network printer device (Raw, port 9100) will do what I want and only requires: 9100 stream tcp nowait cat > some_file but I'd like to be able to test it on my Macbook and that does not have inetd.

Potentially I could use launchd as it is the replacement for inetd on OSX, but reading the docs, it is not clear how to do the equivalent to the above. So either solution--how to get inetd for OSX or how to create a plist file for launchd do that does the equivalent is what I'm looking for.

1

The existing launch XML files in /Library/LaunchDaemons or /System/Library/LaunchDaemons deserve study; from one of these and with some grepping about in /etc/services

$ grep 9100 /etc/services
hp-pdl-datastr  9100/udp     # PDL Data Streaming Port
hp-pdl-datastr  9100/tcp     # PDL Data Streaming Port

one might adapt one of the existing files to what I've saved to /Library/LaunchDaemons/cattery.plist

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
    <key>Disabled</key>
    <false/>
    <key>Label</key>
    <string>com.exampe.cattery</string>
    <key>ProgramArguments</key>
    <array>
        <string>/var/root/cattery</string>
    </array>
    <key>inetdCompatibility</key>
    <dict>
        <key>Wait</key>
        <false/>
    </dict>
    <key>InitGroups</key>
    <true/>
    <key>Sockets</key>
    <dict>
        <key>Listeners</key>
        <dict>
            <key>SockServiceName</key>
            <string>hp-pdl-datastr</string>
            <key>SockType</key>
            <string>stream</string>
        </dict>
    </dict>
</dict>
</plist>

Where /var/root/cattery here is the bad test script (what happens if clients connect two or more times per second?):

$ sudo cat /var/root/cattery
#!/bin/sh
cat > "/var/root/out.$(date +%s)"
$ sudo chmod +x /var/root/cattery

And then we enable our new service

$ sudo launchctl load -w /Library/LaunchDaemons/cattery.plist

And feed some test data to it

$ echo foo | nc localhost 9100
$ sudo find /var/root -name out\* -maxdepth 1
/var/root/out.1511845970
$ sudo cat /var/root/out.1511845970
foo
$ 

NOTE this code probably should not run as root, a

    <key>UserName</key>
    <string>_lp</string>

line as seen in /System/Library/LaunchDaemons/org.cups.cups-lpd.plist may help to not run the above as root, in which case the output directory for data saved must be writable by that user, and the program run executable (and perhaps also readable) by that user.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.