ADB server does not ACK if it is launched inside Linux chrooted / jailed / emulated with the Linuxulator

From: Mario Marietto <marietto2008_at_gmail.com>
Date: Fri, 22 Nov 2024 20:49:37 UTC
Hello.

I'm trying to connect to my mobile phone using adb over wifi using the
Linuxulator because I want to install a specific java application that
requires Linux to work. I have already used Linux virtualized with bhyve
and it worked. But I prefer to save some memory by trying to use the
Linuxulator instead of starting a vm,if possible. I've already tried to run
the app using java installed natively on FreeBSD,but it fails because it
wasn't designed for this. So :

[root@noble /]==> adb connect 192.168.1.2:5555

* daemon not running. starting it now on port 5037 *
cannot bind 'tcp:5037'
ADB server didn't ACK
* failed to start daemon *
error: cannot connect to daemon

that's the error that I get. I'm not sure if I can use some trick or if
there is anything that I can do because the Linuxulator does not support
that in any way. Instead,if I launch it directly in FreeBSD,it works :

[root@marietto /home/marietto]==> adb connect 192.168.1.2:5555

* daemon not running; starting now at tcp:5037
* daemon started successfully
connected to 192.168.1.2:5555

The problem is that the java app does not recognizes that the adb server is
working :

[root@noble /home/marietto/Desktop/Files/OS/Linux/Tools/DeskDockServer_1.3.0]==>
java -jar DeskDockServer_1.3.0.jar

Program: DeskDockServer 1.3.0
System: Linux 5.15.0, amd64
JRE: 21.0.5+11-Ubuntu-1ubuntu124.04
AdbLocator: Found ADB in env PATH
class com.floriandraschbacher.deskdockserver.Main:
Using ADB from /usr/bin/adb
ab@3f95b479: Error getting devices:
ADB server didn't ACK
q$b@31524dfb: Error getting ADB devices:
java.io.IOException: java.io.IOException:
ADB server didn't ACK

but it is working :

[root@noble /home/marietto/Desktop/Files/OS/Linux/Tools/DeskDockServer_1.3.0]==>
ps ax

  PID TTY      STAT   TIME COMMAND
 6089 pts/0    R+     0:00 ps ax
 5979 pts/0    S      0:00 adb -P 5037 fork-server server
 5952 pts/0    S      0:00 /bin/zsh

According with this thread :

https://forums.freebsd.org/threads/make-jail-available-to-bind-only-certain-ports.85609/

I want to create a Jail with a public IP address. But as we have an IPv4
address shortage. I want to only make the jail able to bind to a range of
ports (say 700 to 750). I asked in the IRC and one answer was to use pf to
NAT ports from/to the jail.

this is what I tried to do :

nano /etc/pf.conf

nat on $ext_if from 127.0.0.0/24 to any -> 192.168.1.2
rdr on $ext_if proto tcp from any to any port 5037:5555 -> 127.0.0.255

root@noble:/home/marietto/Desktop/Files/OS/Linux/Tools/DeskDockServer_1.3.0#
./adb connect

* daemon not running. starting it now on port 5037 *
* daemon started successfully *
** daemon still not running
error: cannot connect to daemon

root@noble:/home/marietto/Desktop/Files/OS/Linux/Tools/DeskDockServer_1.3.0#
ps ax

  PID TTY      STAT   TIME COMMAND
 8759 pts/2    R+     0:00 ps ax
 8758 pts/2    S      0:00 adb -P 5037 fork-server server
 8739 pts/2    S      0:00 /bin/bash

but it didn't work :

root@noble:/home/marietto/Desktop/Files/OS/Linux/Tools/DeskDockServer_1.3.0#
java -jar DeskDockServer_1.3.0.jar

2024-11-22 17:33:02.348   Program: DeskDockServer 1.3.0
2024-11-22 17:33:02.348   System: Linux 5.15.0, amd64
2024-11-22 17:33:02.348   JRE: 21.0.5+11-Ubuntu-1ubuntu124.04
2024-11-22 17:33:02.469   AdbLocator: Found ADB in env PATH
2024-11-22 17:33:02.469   class
com.floriandraschbacher.deskdockserver.Main: Using ADB from
/usr/bin/adb
2024-11-22 17:33:02.508   ab@c703a44: Error getting devices: ADB
server didn't ACK
2024-11-22 17:33:02.508   q$b@2b7d5ba: Error getting ADB devices:
java.io.IOException: java.io.IOException:
ADB server didn't ACK127.0.0.255192.168.1.2:5555

-- 
Mario.