Showing posts with label IP address. Show all posts
Showing posts with label IP address. Show all posts

Sunday, October 14, 2012

TO get/set an IP address from Linux over the socket:
 
int s;
    struct ifreq ifr = {};

    s = socket(PF_INET, SOCK_DGRAM, 0);

    strncpy(ifr.ifr_name, "eth0", sizeof(ifr.ifr_name));

    if (ioctl(s, SIOCGIFADDR, &ifr) >= 0)
        printf("%s\n",
          inet_ntoa(((struct sockaddr_in *)&ifr.ifr_addr)->sin_addr));


ioctl call receives data from the kernel for SIOCGIFADDR for IP address.

In case of static IP address, we will set the IP address with ioctl( SIOCGIFADDR, socketDetails) call.
 
 
ioctl is the module which can be used for kernel/user or user to kernel communication. 
 
 For more, read Richard Steven's Unix Network Programming book
 
 
 

Thursday, October 04, 2012

How to detect IP address change in Linux:

http://stackoverflow.com/questions/579783/how-to-detect-ip-address-change-programmatically-in-linux

Tuesday, October 02, 2012


How to get logcat from the android device which is having IP address:

we can connect to the device with IP address by adb command.
If we are runnign the below command from system,

adb connect 10.1.20.100 #will makes the system to connect with device.

Afterwards if we are giving “adb logcat”, this will prints the logs in your system.So with adb command, we can connect to any emulator or device which is having IP address. It is possible that we can connect to any remote device and can take logs from another remote place.