Android使用ethtool工具查询/设置以太网网卡状态

http://blog.csdn.net/u013686019/article/details/51491364

一、编译ethtool工具

Android命令行中不含ethtool工具,所以需要自己编译。
1、下载最新源码:ethtool-4.5.tar.xz

源码地址:

https://www.kernel.org/pub/software/network/ethtool/

2、解压
把ethtool-4.5.tar.xz拷贝到Android/external/目录,解压:

 

tar xvf ethtool-4.5.tar.xz

3、编译
编写Android.mk文件:

LOCAL_PATH:= $(call my-dir)
include $(CLEAR_VARS)

define all-c-files-under
	$(patsubst ./%,%, $(shell find $(LOCAL_PATH) -name "platform" -prune -o -name "*.c" -and -not -name ".*"))
endef
  
define all-subdir-c-files
$(call all-c-files-under,.)
endef

C_FILES := $(call all-subdir-c-files)


LOCAL_SRC_FILES := $(C_FILES:$(LOCAL_PATH)/%=%)

LOCAL_SHARED_LIBRARIES := \
		libcutils\
		libutils\
		libcrypto


LOCAL_C_INCLUDES :=  $(KERNEL_HEADERS)

LOCAL_CFLAGS := -DANDROID_CHANGES -DCHAPMS=1 -DMPPE=1 -Iexternal/openssl/include

LOCAL_MODULE :=ethtool
LOCAL_MODULE_TAGS := optional

include $(BUILD_EXECUTABLE)

执行mm命令即可。

 

 

Install: out/target/product/ProductName/system/bin/ethtool


二、ethtool工具基本使用
查询以太网卡当前工作状态:ethtool eth0
Android使用ethtool工具查询/设置以太网网卡状态_第1张图片

 

 

 

 

设置以太网卡工作状态为半双工100M:ethtool -s eth0 speed 100 duplex half

Android使用ethtool工具查询/设置以太网网卡状态_第2张图片

三、编译过程中的问题
编译过程中肯定会报错,不过都是些简单问题,很好解决。
其中报错误的文件有test-cmdline.c、test-common.c、test-features.c,既然是test工具,不编它们即可。

你可能感兴趣的:(Android源码,Linux网络)