11월, 2012의 게시물 표시

android ip check

1. prepare project/jni project/AndoroidMainfest.xml Native C or C++ Code manifest sample <?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android"     package="com.mycompany.mynativeapp"     android:versionCode="1"     android:versionName="1.0" >     <uses-sdk android:minSdkVersion="7" android:targetSdkVersion="8" />          <uses-permission android:name="android.permission.INTERNET" /> <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>   <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>     <!-- This .apk has no Java code itself, so set hasCode to false. -->     <application android:label="@string/app_name" android:hasCode="false">         <!-- Our activity is the built-in NativeActi

linux / unix 에서 자기 IP 얻어오기 ( android 포함 )

linux / unix 에서 자기 IP 얻어오기 ( android 포함 ) ( C, C++ ) ( get my ip in android native NDK ) 내용 : 로컬의 IP를 찾아 표시한다.  - 외부 IP를 얻는 방법은 따로... 펌 : http://yegam400.tistory.com/71 보통 자기 ip 알아보는데는 gethostbyname을 많이 사용하지만, 이것은 디바이스의 ethernet(eth0, eth1,...)를 바로 가지고 오므로 정확합니다. Loop back도 가지고 오네요. 리눅스/유닉스 소스코드입니다. #include <sys/ioctl.h> #include <sys/types.h> #include <sys/stat.h> #include <sys/socket.h> #include <unistd.h> #include <netinet/in.h> #include <arpa/inet.h> #include <stdio.h> #include <stdlib.h> #include <string.h> #include <net/if.h> #include <arpa/inet.h> int main() {     // 이더넷 데이터 구조체     struct ifreq *ifr;     struct sockaddr_in *sin;     struct sockaddr *sa;     // 이더넷 설정 구조체     struct ifconf ifcfg;     int fd;     int n;     int numreqs = 30;     fd = socket(AF_INET, SOCK_DGRAM, 0);     // 이더넷 설정정보를 가지고오기 위해서     // 설정 구조체를 초기화하고     // ifreq데이터는 ifc_buf에 저장되며