Code Blog

Displaying 16-20 of 46 results.
2016/09/05 MacOSX,Network,iOS


PortTCP or UDPService or Protocol NameRFCService NameUsed by / Additional information
192 UDP OSU Network Monitoring System - osu-nms AirPort Base Station PPP status or discovery (certain configurations), AirPort Admin Utility, AirPort Express Assistant

UDP Wi-Fi Calling 5996 IKEv2 Wi-Fi Calling
515 TCP Line Printer (LPR), Line Printer Daemon (LPD) - printer Used for printing to a network printer, Printer Sharing in Mac OS X
554 TCP/UDP Real Time Streaming Protocol (RTSP) 2326 rtsp QuickTime Streaming Server (QTSS), streaming media players, AirPlay
631 TCP Internet Printing Protocol (IPP) 2910 ipp Mac OS X Printer Sharing, Printing to many common printers
1900 UDP SSDP - ssdp Bonjour, Back to My Mac
3689 TCP Digital Audio Access Protocol (DAAP) - daap iTunes Music Sharing, AirPlay



Bonjour is Apple's implementation of zero-configuration networking (zeroconf), a group of technologies that includes service discovery, address assignment, and hostname resolution. Bonjour locates devices such as printers, other computers, and the services that those devices offer on a local network using multicast Domain Name System (mDNS) service records.


AirDrop is a handy method of sharing data with any Mac equipped with OS X Lion (or later) and a Wi-Fi connection that supports PAN (Personal Area Networking). PAN is a somewhat recent standard that has been added to the Wi-Fi alphabet soup of capabilities. The idea of PAN is that two or more devices that come within range of each other can communicate using a peer-to-peer connection method. Apple's implementation of AirDrop relies on WiFi chipsets that have built-in PAN support. This reliance on hardware-based PAN capabilities in WiFi chipsets has the unfortunate consequences of limiting the use of AirDrop to Macs from late 2008 or later.

AirDrop uses Apple's Bonjour technology to listen in on a WiFi connection for another Mac to announce AirDrop capabilities. It seems AirDrop will announce itself over any available network connection, but when AirDrop listens, it only pays attention to Wi-Fi connections, even if AirDrop announcements are present on other network interfaces.

defaults write BrowseAllInterfaces 1

// Enable AirDrop Over Any Network Connection

To use AirDrop, both Bluetooth and Wi-Fi must be turned on. AirDrop uses Bluetooth to locate other AirDrop-enabled devices nearby and uses the faster Wi-Fi network to transfer the files. Because AirDrop uses Bluetooth, it adheres to a common Bluetooth range, which requires devices to be within 33 feet/10 meters of each other.

When AirDrop is enabled, it triggers Bluetooth to look for other AirDrop-enabled iOS devices that are in the area. This process is similar to pairing your iPhone with your car’s Bluetooth system. The devices “advertise” that they are open for business, and if they are within range of each other, then they start the connection process. Once the connection is made, a simple device-to-device Wi-Fi link, called Wi-Fi Direct, is created between the two. The Wi-Fi Direct link can be created even if you are in the middle of nowhere, without a Wi-Fi network. So, you get the fast file transfer speed of Wi-Fi without a router or an internet connection.

To limit who can see your device to only the people in your Contacts, you’ll need to sign in to iCloud with your Apple ID.

Only some Apple iOS devices have both Bluetooth 4.0 and Wi-Fi Direct capabilities: i.e. iPhone 5 (and later) iPad (4th generation and later). iOS 8 and OS X Yosemite (10.10) allowed the use of AirDrop between Macs and iOS devices.

I had some problems to get the iphone/macbook AirDrop connection to work. I think the main reason is that I turned on "contact only" on the Macbook. When I use a router with VPN it works good, but not with another router. As the connection is setup via an independent PAN network, the router shouldn't be a factor at all. But maybe for getting the contacts list from iCloud it is?

Some other tips I found online for troubleshooting AirDrop (and Handoff)

  1. Turn off Bluetooth on your Mac
  2. Delete /Library/Preferences/
  3. Turn Bluetooth back on 

 In your WiFi router, change it from Wireless Encryption WPA2 (Mixed) to Wireless Encryption WPA2(AES).


AirDrop information from:

See full port numbers listing at



2016/08/11 MacOSX,iOS

I've got a lot of trouble accessing Apple's servers from work/home here in Shanghai. Maybe the servers are too busy, but in any case, most of the time the iTunes update operation (downloading the file) disconnects before it's completed. The same happens often with XCode simulator downloads btw.

So a better way is to download the firmware first and then install it via iTunes. You need to first check which firmware file to download for the iPhone, it is either GSM or GLOBAL (CDMA + GSM) version. You can check the model number at the back of the phone and just google it to find out which type you have got.

In my case it is: iPhone 5s Model A1533 (GSM)
iPhone 5s is encoded as model nr 6 for the IPSW filename, where 6.1 is for GSM and 6.2 is for GLOBAL.

Next step is to download the IPSW file, for example:,1_9.3.2_13F69_Restore.ipsw

9.3.4 is a jailbreak security patch, so I rather just install 9.3.2.

Install IPSW on iPhone

Always make a backup before upgrading iOS.

  1. Connect your iPhone to your computer
  2. Select the device in iTunes
  3. Hold down the "Option" key and click on "Update" ("Shift" key on Windows)
  4. Select the IPSW file you downloaded
  5. iOS installation runs as normal

You can also click on "Restore" and select an IPSW file but this will lose all existing files and settings on the iPhone.

2016/07/31 Raspberry-Pi

Had been thinking about how to stream music at home in a convenient way, the Sonos products look quite nice, but also quite expensive. Started to look for alternatives and found out this can be done on a Raspberry Pi board. This also has the advantage I can keep using my old speaker. Seemed like a fun project so I went ahead and bought the following:

  • HIFI DAC+ sound card I2S interface (for Raspberry Pi B+/2B )
  • Raspberry Pi 2 model B (900 MHz quad-core ARM CPU, 1GB RAM) (it replaced Raspberry Pi 1 Model B+ in February 2015)
  • Power adapter (Mitsumi, 5.0V 1.8A) with USB cable
  • Black plastic box for fitting the HIFI DAC board
  • Heat sinks for the Raspberry board (for CPU and GPU)

I put the Volumio OS ( on the microSD card. Volumio is built on Linux and is open-source/free software. Another alternative is using RuneAudio. At the time I installed it I choose Volumio for better support of the hardware (I2S DAC support). Volumio is developed from RaspyFi but is supporting more embedded platforms than RaspFi did (UDOO, CuBox and Beaglebone Black and Raspberry PI).

Raspberry Pi also can do audio output via USB, but for good reliable sound output using a DAC connected to the internal I2S bus (a specialized chip-to-chip audio bus available on the board) is much better.

Volumio supports AirPlay and it can also be remotely controlled via MPoD iOS app to play locally stored music (I connect a USB-stick with music to the Raspberry Pi).

I have been running it 24/7 from Nov 2015 to July 2016, and it has been working without any problems all this time, but it just died at the end of July. Wonder if it got overheated in the Shanghai summer heat ..

Debugging steps:

  • Check incoming voltage on micro-usb
  • Change SD card (seems SD card can easily become damaged during power breaks etc)

So I will probably upgrade to Raspberry 3 now. The I2S DAC board is compatible with Raspberry Pi 3. One good thing is that Raspberry 3 looks the same as Raspbery 2 so the same case can still be used. Raspberry 3 comes with Wifi and bluetooth builtin which Raspberry 2 lacked.

Below is a script to monitor CPU and GPU temperatures on the Raspberry Pi Linux OS. Might be good to improve this and send an email or other warning if the temperature gets too high. I think I should also fit a small fan for active cooling the next time.

cpuTemp0=$(cat /sys/class/thermal/thermal_zone0/temp) 
cpuTempM=$(($cpuTemp2 % $cpuTemp1)) 
gpuTemp0=$(/opt/vc/bin/vcgencmd measure_temp) 
echo CPU Temp: $cpuTemp1"."$cpuTempM"ºC" 
echo GPU Temp: $gpuTemp0

The output comes out as following:

$ ./temp 
CPU Temp: 56.2ºC 
GPU Temp: 56.2ºC 

(Script from

2016/07/01 MacOSX

I've been trying to find a solution to stop my cat from turning off my Macbook Air. I normally leave the computer in the screen saver / login screen mode so that the cat can't mess up any open documents etc (this happened before). However, sometimes when I get back the computer has been completely powered off!

So obviously just running the screen saver won't be enough, instead I need a way to disable the power button on the keyboard. Unfortunately Apple hasn't designed their system with this in mind.

I found some tips at for protecting the keyboard from one's cat but that doesn't really work for me. It is more about locking down the keyboard from unintentional input, but if I turn on the screensaver (I use a hot corner with my mouse to start the screensaver btw) before leaving the computer I already don't have that problem. The power button is still active though.


Next I downloaded and installed Karabiner ( which is a free tool for remapping the Mac keyboard.


I discovered that Karabiner doesn't remap the power button any longer! (I'm running 10.11 El Capitan).

Before 10.9 pressing the power button for 1.5 would display this dialog window:

It turns out the way Karabiner remapped the power button was to detect this popup dialog. After Apple changed the behaviour in 10.9 (no popup window) it wasn't any longer possible to intercept it (it is possible to detect the key event but not stopping it from going to sleep).

Turns out this behaviour was disabled in OS X 10.9 but was later added back on as an option in 10.9.2. The following command can restore the old behaviour:

defaults write PowerButtonSleepsSystem -bool NO

Power button old behaviour (from the Apple documentation)

Power button • Tap to turn on your Mac or wake your Mac from sleep.  
• Hold for 1.5 seconds while your Mac is awake to display a dialog asking if you want to restart, sleep, or shut down. If you don't want to wait 1.5 seconds, press Control–Power button or Control–Media Eject  .
• Hold for 5 seconds to force your Mac to turn off.


There is another free tool called PowerKey ( that got broken off from Karabiner to only deal with the power button. I downloaded the code and built it in XCode.


This worked after I changed the deployment target to my current system.

Turns out Karabiner and PowerKey never were able to to what I wanted. It's useful for typing as you can re-map the powerkey to for example a forward delete. But it was never able to totally disable the power button. Maybe I should have realized this earlier, because the power button is the only way to reset / turn off the computer, so it shouldn't really be possible to easily change in software (virus/malware could really mess up the computer).

I found some good information at
Running the following command can unload (totally disable) the internal keyboard kernel extension:

sudo kextunload /System/Library/Extensions/AppleACPIPlatform.kext/Contents/PlugIns/AppleACPIButtons.kext

But even running the command above (you will preferably also need an external keyboard to reload the internal keyboard kernel extension later) will not disable the power button! The power button is the only way to reset the computer so it's actually not part of the internal keyboard. It's a very special key indeed.

In the end it might actually be better to prevent the Mac from sleeping when folding it (so it will keep downloading files or playing a movie etc). Folding the computer will for sure prevent my cat from sitting on the power button. There are some free tools available that does just that (I installed InsomniaX) but I also read some warnings that this may restrict the air flow and overheat the macbook, so this solution is also not without it's own problems. But it is still the best option I could find, as its the only way to actually protecting the power key button (physically protecting it with the screen cover).

Karabiner, PowerKey and InsomniaX are all quite useful pieces of software, so it's worth checking them out.

The new Macbook Pro (still no release date, maybe end of 2016?) is rumoured to have a TouchID function integrated with the power button, which would be great, as that will hopefully prevent my cat from powering off the computer in the future! 

2016/06/14 PHP,Joomla

Had to upgrade and re-install a Joomla-site. One thing that is a bit annoying is how to get the "log" and "tmp" folder variables in system configuration set correctly. Joomla needs the absolute physical path, so a relative path will not work. And if the "tmp" folder is not writable (easy to check under "System Information" -> "Folder Permissions") then its not possible to install new extensions (which I needed to do).

One way to get the full path is to upload a php file and just type it out:

<?php echo "cwd: " . getcwd(); ?>

Not ideal but it will work. I wish the Joomla system configuration UI could have an info button that would display the current path and I could just copy and paste from there. 

I suppose if I log in to the hosting company's administration website I may also be able to find the full path from there but its also a bit of a hassle.

One way that I found that seems to be an easy way to find the path is to use Akeeba backup and click "Configuration". The "Output Directory" will contain the full path to the joomla base directory. Another way (if Akeeba isn't installed) is to go to "System Information" and select "PHP Environment". Scroll down to "Apache Environment" and the OVERWRITE_DOCUMENT_ROOT variable will contain the full physical path.