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.

############

rpmcheck.sh

############

#!/bin/bash
rpm -qa "*$1*" > r1
line_no=$( wc -l < r1 )
echo "$line_no"
if [ $line_no == 0 ]
then
echo "rpm not installed "
else
echo "rpm installed "
fi


Output:

[root@home linux]# ./rpmcheck.sh milton
0
rpm not installed
[root@home linux]# ./rpmcheck.sh boost
2
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.

Example:

[root@home linux]# rpm -qf /usr/lib/libpython2.3.so
python-2.3.4-14.1

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

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 ( xxx.xxx.xxx.xxx. )

#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

http://www.paisagate.com/index.htm

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.

example:

in main_folder make file,

HOST_OS = "SunOS"

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

in Sub_folder make file,

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