用 Qt Creator 写一个 Android 程序,需要读取 DNS 。C 语言怎么读呢,研究了一下,原来在 Android 的 C 库里,就有读取系统属性的方法。用 objdump 看了一下 libc.so ,找到了其中的函数。如下:

000095f0 g     F .text00000014 __system_properties_init00009604 g     F .text00000014 __system_property_find00009618 g     F .text00000014 __system_property_find_nth0000962c g     F .text00000014 __system_property_get00009640 g     F .text00000014 __system_property_read00009654 g     F .text00000014 __system_property_wait

头文件是 system_properties.h ,在 usr/include/sys目录下面。

__system_property_get 可以用来获取一个属性值,函数原型如下:

/* Look up a system property by name, copying its value and a** \0 terminator to the provided pointer.  The total bytes** copied will be no greater than PROP_VALUE_MAX.  Returns** the string length of the value.  A property that is not** defined is identical to a property with a length 0 value.*/int __system_property_get(const char *name, char *value);

读取 DNS 的代码如下:

char buf[PROP_VALUE_MAX];__system_property_get("net.dns1", buf);__system_property_get("net.dns2", buf);

读取其他属性类似,设置的话可以查看 system_properties.h 看函数用法。


更多相关文章

  1. android:configChanges属性
  2. 我对android的第一印象
  3. android 电容屏(三):驱动调试之驱动程序分析篇
  4. UI控件--ImageView和ImageButton
  5. Android三角函数
  6. android警告——Buttons in button bars should be border
  7. [android] PhoneGap 在 android 下的实现原理
  8. 【Android(安卓)开发】:Android五种布局的使用方法
  9. Android(安卓)日志系统logcat内核代码分析

随机推荐

  1. Android开发EditText属性
  2. Android之ActivityManager与Proxy模式的
  3. Android Studio中使用android:src="@draw
  4. Android:控件布局(相对布局)RelativeLayout
  5. 【Android】附加Android源代码Androidand
  6. ANDROID:控件属性(很全)
  7. [置顶] NoHttp详解之Android使用Https
  8. Android异步处理三:Handler+Looper+Messag
  9. 《android 1: 创建一个安卓项目》
  10. Android(安卓)创建及调用自己的 ContentP