Android系统 无法绑定1024以下端口问题

一,前言

在Android系统中,默认情况下,普通应用程序无法绑定到1024以下的端口(即特权端口),这是出于安全考虑而设计的。这种限制是为了防止普通应用程序伪装成系统服务或者使用系统服务的特权端口,从而提高系统的安全性。只有具有足够权限的应用程序(例如系统服务或者root权限)才能绑定到1024以下的端口。
注: 不建议去修改这个端口号, 最好还是apk内部可以去申请其它端口, 这样也会减少一些冲突。

二,平台修改方法

适用于所有Android版本(userdebug和user版本)。

1,Rockchip平台

Android5.1 - Android11:kernel/include/net/sock.h
Android12 + :kernel-5.10/include/net/sock.h

bash 复制代码
/* Sockets 0-1023 can't be bound to unless you are superuser */
#define PROT_SOCK   1024

2,全志平台

Android4.4 - Android7.1: lichee/linux-3.10/include/net/sock.h
Android10 - Android13: longan/kernel/linux-4.9/include/net/sock.h

bash 复制代码
/* Sockets 0-1023 can't be bound to unless you are superuser */
#define PROT_SOCK   1024

3,海思平台

Android9.0:device/hisilicon/bigfish/sdk/source/kernel/linux-4.9.y/include/net/sock.h

bash 复制代码
/* Sockets 0-1023 can't be bound to unless you are superuser */
#define PROT_SOCK   1024

文件中已声明, 0 - 1023 端仅su用户能使用.所以, 修改的方法是把限制的端口号改低或直接改为0。

相关推荐
睡觉待开机44 分钟前
【Android】03-Android 开发机器配置要求
android
Rverdoser2 小时前
非线性优化--NLopt算法(Android版本和Python示例)
android·python·算法
大胃粥3 小时前
Android V app 冷启动(6) Transition 数据化
android
帅次3 小时前
Flutter:StatelessWidget vs StatefulWidget 深度解析
android·flutter·ios·小程序·swift·webview·android-studio
好看资源平台4 小时前
安卓逆向环境搭建(Windows/Linux双平台)
android·linux·windows
林奋斗同学4 小时前
Android GMS集成
android
_一条咸鱼_5 小时前
Android Glide 框架线程管理模块原理的源码级别深入分析
android
_一条咸鱼_5 小时前
Android Retrofit 框架注解定义与解析模块深度剖析(一)
android
法欧特斯卡雷特5 小时前
Kotlin Sequence 真的如此不堪吗?
android·后端·编程语言
pengyu5 小时前
系统化掌握Flutter开发之GestureDetector(一):筑基之旅
android·flutter·dart