2008年3月21日 星期五

Get IP address / Netmask / Broadcast C code

#include <sys/types.h>
#include <sys/socket.h>
#include <netdb.h>
#include <netinet/in.h>
#include <unistd.h>
#include <arpa/inet.h>
#include <stdio.h>
#include <ifaddrs.h>
#include <string.h>

int printLocalIps()
{
struct ifaddrs *ifa = NULL, *ifp = NULL;

if (getifaddrs (&ifp) < 0)
{
perror ("getifaddrs");
return 1;
}

for (ifa = ifp; ifa; ifa = ifa->ifa_next)
{
char ip[NI_MAXHOST];
socklen_t salen;

if (ifa->ifa_addr->sa_family == AF_INET) {
struct sockaddr_in *sin = (struct sockaddr_in *)(ifa->ifa_addr);
salen = sizeof (struct sockaddr_in);

/*printf("%s : %s\n", ifa->ifa_name, inet_ntoa(sin->sin_addr)); */

} else if (ifa->ifa_addr->sa_family == AF_INET6)
/*salen = sizeof (struct sockaddr_in6);*/
continue;
else
continue;
printf("<---------->\n");
printf("%s :\n", ifa->ifa_name);

if (getnameinfo (ifa->ifa_addr, salen,
ip, sizeof (ip), NULL, 0, NI_NUMERICHOST) < 0)
{
perror ("getnameinfo");
continue;
}
printf ("IP : %s\n", ip);

if (getnameinfo (ifa->ifa_netmask, salen,
ip, sizeof (ip), NULL, 0, NI_NUMERICHOST) < 0)
{
perror ("getnameinfo");
continue;
}
printf ("Netmask : %s\n", ip);

if (getnameinfo (ifa->ifa_broadaddr, salen,
ip, sizeof (ip), NULL, 0, NI_NUMERICHOST) < 0)
{
perror ("getnameinfo");
continue;
}
printf ("Broadcast : %s\n", ip);

}

freeifaddrs (ifp);

return 0;
}

int main(int argc, char **argv)
{
printLocalIps();
}






Result :

<---------->
lo :
IP : 127.0.0.1
Netmask : 255.0.0.0
Broadcast : 127.0.0.1
<---------->
eth0 :
IP : 192.168.168.67
Netmask : 255.255.255.0
Broadcast : 192.168.168.255











2008年3月10日 星期一

PHP + thttpd + MySQL

MySQL 5.0.18

CC=i386-linux-gcc CXX=i386-linux-g++ AR=i386-linux-ar ./configure --host=i386-linux --target=i386-linux --prefix=/opt/mysql-5.0.18 --disable-shared --enable-static --without-debug --enable-assembler --with-pthread --without-docs --without-man --without-bench --without-innodb --program-prefix= --cache-file=/dev/null

Fix clinet/Makefile -->> LDFLAGS = -s -static

make
make install

php-4.3.10

 CC=i386-linux-gcc CXX=i386-linux-g++ AR=i386-linux-ar ./configure --enable-static --build=i386-linux --host=i386-linux --with-thttpd=../thttpd-2.21b --with-mysql=/opt/mysql-5.0.18 --with-config-file-path=/opt/thttpd-2.21b/lib --prefix=/opt/php-4.3.10 --enable-memory-limit --disable-debug --without-gd --enable-sysvshm --cache-file=/dev/null

make
make install

cd thttpd-2.21b

CC=i386-linux-gcc CXX=i386-linux-g++ AR=i386-linux-ar ./configure --host=i386-linux --target=i386-linux --prefix=/opt/thttpd-2.21b --cache-file=/dev/null

make
make install