Android环境下移植busybox-1.21.1

前言:本移植主要是为了实现安卓环境下DHCP服务器和telnetd服务器功能。

Dhcp服务器主要修改缓存文件路径“/tmp/leases,telnetd主要添加登陆验证,这个牵扯到login命令。


1.首先下载busybox-1.21.1.tar.bz2

2.解压,进入busybox-1.21.1执行:

#cp configs/android2_defconfig .config

3.因添加dhcp服务器需要,修改busybox-1.21.1\networking\udhcp\dhcpc.c

添加:

#ifndef PACKET_AUXDATA
# define PACKET_AUXDATA 8
struct tpacket_auxdata {
uint32_t tp_status;
uint32_t tp_len;
uint32_t tp_snaplen;
uint16_t tp_mac;
uint16_t tp_net;
uint16_t tp_vlan_tci;
uint16_t tp_padding;
};
#endif


修改busybox-1.21.1\networking\udhcp\files.c

扫描二维码关注公众号,回复: 14977858 查看本文章

#include <features.h>
#include <ctype.h>
#include <stdio.h>
#include <stdlib.h>
 
struct ether_addr *ether_aton_r(const char *asc, struct ether_addr *addr)
{
size_t cnt;
for (cnt = 0; cnt < 6; ++cnt) {
unsigned int number;
char ch;
ch = _tolower(*asc++);
if ((ch < '0' || ch > '9') && (ch < 'a' || ch > 'f'))
return NULL;
number = isdigit(ch) ? (ch - '0') : (ch - 'a' + 10);
ch = _tolower(*asc);
if ((cnt < 5 && ch != ':')
|| (cnt == 5 && ch != ' ' && !isspace(ch)))
{
++asc;
if ((ch < '0' || ch > '9') && (ch < 'a' || ch > 'f'))
return NULL;
number <<= 4;
number += isdigit(ch) ? (ch - '0') : (ch - 'a' + 10);
ch = *asc;
if (cnt < 5 && ch != ':')
return NULL;
}
/* Store result.  */
addr->ether_addr_octet[cnt] = (unsigned char) number;
/* Skip ':'.  */
++asc;
}
return addr;
}

4.因添加passwd命令需要,修改

android-ndk-r10b\platforms\android-9\arch-arm\usr\include\pwd.h

添加:

struct passwd
{
    char* pw_name;
    char* pw_passwd;
    uid_t pw_uid;
    gid_t pw_gid;
    char* pw_gecos; /* Real Name or Comment field for mac busybox*/  
    char* pw_dir;
    char* pw_shell;
};


5.修改telnetd.c

<span style="font-size:18px;">#define INIT_G() do { \
    G.loginpath = "/system/bin/login"; \
    G.issuefile = "/etc/issue.net"; \
} while (0)</span>

6.添加login选项

屏蔽tcdrain(STDOUT_FILENO);

 

7.编译busybox 执行

#make menuconfig

说明:

添加编译器和路径、用户密码命令、dhcp等,详见配置文件(.config)。

#make

8.安装

#make install


9.telnetd服务器实现

将生成的busybox拷贝到机器中(我们的机器是/system/bin/)。

在使用telnetd服务器登录添加账户密码中,先讲解一下生成账户密码方法,首先在/system/etc下生成一个passwd文件,然后使用生成的busybox工具执行命令:

#busybox touch /system/etc/passwd

#busybox adduser root

这里或许会出现错误:“passwd : unknown uid 0”,这里需要修改一下passwd 文件内容,如:

root:x:1000:1000:Linux User,,,:/home/root:/system/bin/sh

将用户ID和组ID都改为0,如:

root:x:0:0:Linux User,,,:/home/root:/system/bin/sh

执行添加命令:

#busybox passwd root  -- 输入命令

最后还是要改一下passwd 文件,如:

root:9VMsMcbCRjKI2:0:0:Linux User,,,:/:/system/bin/sh”

在机器中执行:

#busybox telnetd&

这样一个telnetd服务器流程就完成了!


10.DHCP服务器

首先需要在/tmp目录下创建一个leases文件,将配置文件udhcpd.conf位于“busybox-1.21.1\examples\udhcp”

根据自己的需求修改一下文件并拷贝到机器的“/system/etc”目录下。

修改内容如路由IP地址、DNS、路由网关等:

start192.168.0.20
end 192.168.0.254

启动dhcp服务器:

#busybox udhcpd -fS /etc/udhcpd.conf &

这样一个dhcp服务器流程就完成了。


针对以上busybox-1.21.1的目录文件修改这里附上补丁文件,直接打上补丁就可以直接编译安装了。

补丁链接:http://download.csdn.net/detail/edw200/9635041






猜你喜欢

转载自blog.csdn.net/edw200/article/details/52597025