View Antoni Milton's profile on LinkedIn

Monday, March 29, 2010

How to find the particular package installed or not?

Using “rpm –qa ” command, we can find whether the package installed or not.

Below shell script use the command for determine the given string/name package rpm installed or not installed.



rpm -qa "*$1*" > r1
line_no=$( wc -l < r1 )
echo "$line_no"
if [ $line_no == 0 ]
echo "rpm not installed "
echo "rpm installed "


[root@home linux]# ./ milton
rpm not installed
[root@home linux]# ./ boost
rpm installed

How to find which rpm (package) install the particular file?

Using “rpm –qf” command, we can find the rpm package name for the lib file.


[root@home linux]# rpm -qf /usr/lib/

[root@home linux]# rpm -qf /usr/include/boost/blank.hpp

Sunday, March 14, 2010

How to check the given string is valid IPAddress or Domain Name?

Using inet_pton function we can determine, whether given string is a valid IPv4/v6 Address or Domain name.

In below example,

first check the given string is a valid Ipv4 address not then check valid Ipv6 address and check the input string as a valid domain name.

int CheckIPAddress( const char* pszHostName)
int iResult =0; // 1 - Ipv4,2-Ipv6, 3- domain name, 0-invalid ip

struct sockaddr_in sockAddr;
struct in_addr addr;
struct in6_addr aadrv6;
struct hostent *host;
int iTemp = inet_pton(AF_INET, pszHostName, &(sockAddr.sin_addr));
if( iTemp == 1 ) // vaild IPv4 Address
iResult = 1;
else if( inet_pton(AF_INET6,pszHostName,&aadrv6 ) == 1)
iResult = 2;
else // may be a domain name. try convert in to Ipv4 Address
if (( host = gethostbyname( pszHostName )) != NULL )
addr.s_addr = *(u_long *) host->h_addr_list[0];
printf("IPAddress: %s\n", inet_ntoa( addr) );
iResult = 3;
return iResult;

Thursday, March 11, 2010

How to convert domain name to IPAddress in C++?

Using the gethostbyname() system call we can get the IPAddress from domain name. Below given example program , convert the domain name to IPAddress and print the IPAddress in "." format ( )

#include "stdio.h"
#include "sys/types.h"
#include "sys/socket.h"
#include "netdb.h"
#include "netinet/in.h"
#include "arpa/inet.h"

int main(int argc,char * argv[])

struct hostent *host;
struct in_addr addr;
if( argc != 2 )
printf("usage: ./a.out "domainname" ");
return 0;

if ((host = gethostbyname(argv[1])) == NULL) {
printf("error resolving hostname..\n");
return -1;

addr.s_addr = *(u_long *) host->h_addr_list[0];
printf("IP: %s\n", inet_ntoa( addr ) );
return 0;

Tuesday, March 9, 2010

Track your expense in online – simple personal accounting online software

How to pass arguments for make file?

we can pass the arguments to makefile like below,

make -f Makefile HOST_OS="Linux"

in Makefile,we can use HOST_OS macro as usual.


in main_folder make file,


cd Sub_folder && make -f Makefile HOST_OS=$(HOST_OS)

in Sub_folder make file,

ifeq ($(HOST_OS),Linux)
[ tab] g++ main.cpp
[tab] cc main.cpp