Diary

[Mac] Port 5000 Unavailable in Monterey

1 Mins read

Developing with port 5000 but getting an error?

Error response from daemon: Ports are not available: exposing port TCP 0.0.0.0:5000 -> 0.0.0.0:0: listen tcp 0.0.0.0:5000: bind: address already in use

lsof -i:5000
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
ControlCe 85856 user10 26u IPv4 0x4ff853972c8bedd 0t0 TCP *:commplex-main (LISTEN)
ControlCe 85856 user10 27u IPv6 0x4ff85430b21e97d 0t0 TCP *:commplex-main (LISTEN)

What’s this thing?

Turns out Monterey added an AirPlay feature that’s hijacking the port.

System Preference > Sharing > AirPlay Receiver > Uncheck it

That’ll free it up, but thinking ahead, other people will hit the same issue. Better to just change the dev side to use a different port.

Read more
Diary

[Mac] Terminal and Operation not permitted – Configure for Developer Use

1 Mins read

macOS Monterey
Version 12.4

■1. Change “SIP” to disabled
(Disable System Integrity Protection: SIP)

Shut down Mac once
At startup, press “command + R”, release when the mark appears
Recovery mode starts
From the menu bar at the top, select “Open Terminal”

# Command: Check if "csrutil status" returns "enabled"
csrutil status

# Command: Run "csrutil disable" (changes take effect only after reboot!)
csrutil disable

# Command: Reboot Mac with "reboot"
reboot

■2. Set Terminal to full file access
After normal startup
Go to “System Preferences”

“Security & Privacy”

“Privacy” tab, then “Full Disk Access” on the right

Check the “Terminal” checkbox On

■3. Delete “.DS_Store” and prevent creation

# Delete all .DS_Store files
sudo find / -name ".DS_Store" -delete
# Restart Finder
Killall Finder

# Prevent .DS_Store files from being created at all
defaults write com.apple.desktopservices DSDontWriteNetworkStores True
# Restart Finder
Killall Finder

■4. If not needed, disable iCloud sync

Read more
Diary

[Mac] Limiting VPN Connection Destinations

1 Mins read

When connected to a VPN, route traffic destined for networks outside the VPN connection (non-VPN destination networks) directly through your local network instead of through the VPN tunnel. This keeps network traffic responsive.

※If you’re working remotely, check with your IT department first—some organizations require all traffic to route through internal networks.

※Be aware that many external servers are configured to allow access only through the VPN tunnel.

※If accessing the VPN destination by domain name, watch out for DNS settings. Depending on the VPN’s DNS configuration, you may need to edit the hosts file.

macOS Monterey
Version 12.3
VPN Connection Method: L2TP/IPsec (PPP tunneling)

■Open Network Settings and access VPN connection details
Uncheck “Send all traffic over VPN connection”
設定画像

■Create a routing addition script
The /etc/ppp/ip-up script is executed when the connection is established.
Add the following to this file to “add IP routes when VPN connects”.
In this example, “172.31.1.0/24” is the route you want to send through the VPN.

#Confirm ppp0 exists after VPN connection
$ ifconfig

#After disconnecting the VPN
#Edit the file with vi
$ sudo vi /etc/ppp/ip-up
#!/bin/sh

if [ "$1" = "ppp0" ]; then
    /sbin/route add -net 172.31.1.0/24 -interface ppp0
fi

#Save the file in vi
#Give the file execute permission
$ sudo chmod +x /etc/ppp/ip-up

#Check the routing table
$ netstat -rn

Notes
When routing multiple paths, you can add multiple entries:
/sbin/route add -net 172.31.1.0/22 -interface ppp0
/sbin/route add -net 172.31.4.0/22 -interface ppp0
/sbin/route add -net 172.31.8.0/22 -interface ppp0

Read more
Diary

[Mac] rbenv openssl [BUILD FAILED] [make: *** [all] Error 2]

1 Mins read

Needed an old environment so hit this issue setting up Xcode and Ruby on a legacy Mac. Leaving a note.

20220315

■Environment
macOS High Sierra 10.13.6
Homebrew 3.4.1-67-gb31d8e9
rbenv 1.2.0

Got this error:

Downloading openssl-1.1.1l.tar.gz...
-> https://dqw8nmjcqpjn7.cloudfront.net/0b7a3e5e59c34827fe0c3a74b7ec8baef302b98fa80088d7f9153aa16fa76bd1
Installing openssl-1.1.1l...

BUILD FAILED (Mac Os X 10.13.6 using ruby-build 20220218)

Inspect or clean up the working tree at /var/folders/rc/9hwgt2nd0rxgjzvt9kc0zgph0000gn/T/ruby-build.20220315231102.889.ggie1q
Results logged to /var/folders/rc/9hwgt2nd0rxgjzvt9kc0zgph0000gn/T/ruby-build.20220315231102.889.log

Last 10 log lines:
/usr/include/CommonCrypto/CommonRandom.h:35:9: error: unknown type name 'CCCryptorStatus'
typedef CCCryptorStatus CCRNGStatus;
        ^
crypto/rand/rand_unix.c:385:47: error: use of undeclared identifier 'kCCSuccess'
    if (CCRandomGenerateBytes(buf, buflen) == kCCSuccess)
                                              ^
2 errors generated.
make[1]: *** [crypto/rand/rand_unix.o] Error 1
make[1]: *** Waiting for unfinished jobs....
make: *** [all] Error 2

So you need OpenSSL 1.0. This command installs “rbenv/tap/openssl@1.0 1.0.2t”:

#Install OpenSSL1.0
brew install rbenv/tap/openssl@1.0

#Set environment variable [hoge is your username]
echo 'export PATH="/usr/local/opt/openssl@1.0/bin:$PATH"' >> /Users/hoge/.bash_profile
#Reflect environment variable
source .bash_profile

#If needed, reflect environment variable
export LDFLAGS="-L/usr/local/opt/openssl@1.0/lib"
export CPPFLAGS="-I/usr/local/opt/openssl@1.0/include"
export PKG_CONFIG_PATH="/usr/local/opt/openssl@1.0/lib/pkgconfig"

#This is needed for subsequent commands!
export RUBY_CONFIGURE_OPTS="--with-openssl-dir=`brew --prefix openssl@1.0`"

#Install whatever Ruby version you want
rbenv install 2.6.9

On macOS, OpenSSL affects other things too.

OpenSSL also impacts the mysql2 library used by Rails and others. Watch out if you’re using MySQL 5.6 or 5.7!

Before running bundle install, you need to set this in your .bundle/config file:

BUNDLE_BUILD__MYSQL2: "--with-ldflags=-L/usr/local/opt/openssl@1.0/lib --with-cppflags=-I/usr/local/opt/openssl@1.0/include"
Read more