Saturday, March 3, 2012
Merging “C” module into C++ project
Compile the C module alone with C++ compiler. For that we can put the following line in top and bottom of the file
// In the top of the file
#ifdef __cplusplus
extern "C" {
#endif
// in the bottom
#ifdef __cplusplus
}
#endif
OR
If you have only one header file going to include in C++ module than,
extern "C" {
// Get declaration for fun(int i, char c, float x)
#include "C_MOD_code.h"
}
Step-2
If the C module going to access the functions from C++ module, then declare like below
extern "C" void fun(int i, char c, float x);
step-3
Once the compilation get successes than link with C++ linker
Wednesday, August 24, 2011
Call the destructor more than one time
class Shape
{
public:
Shape(){ cout<<" Shape"<
virtual ~Shape(){ cout<<" ~ Shape"<
};
class Circle : public Shape
{
public:
Circle() { cout<<"Circle"<< endl; }
~Circle(){ cout<<" ~ Circle" << endl; }
};
int main()
{
Circle *ptr = new Circle();
ptr->~Circle();
ptr->~Circle();
return 1;
}
Tuesday, August 9, 2011
How to resolve the IPv6 Address from domain name in C++ ?
For resolve IPv6Address from domain name, we need to use gethostbyname2_r function.
struct in6_addr aadrv6;
struct hostent *host;
char* pszHostName = “localhost6.localdomain6”;
char strIPAddr[50];
char buffer[2048];
int iError = 0,hrr;
iError = gethostbyname2_r( pszHostName, AF_INET6, &hostbuf,buffer, 2048,&host,&hrr );
if( iError == 0 && host != NULL )
{
memcpy( &aadrv6 , host->h_addr_list[0], sizeof( in6_addr ) );
if( inet_ntop ( AF_INET6, &aadrv6, strIPAddr, INET6_ADDRSTRLEN ) != NULL )
{
printf("IPv6Address: %s\n", strIPAddr);
}
}
output:
#./a.out
IPv6Address: ::1
Thursday, October 14, 2010
In Linux anything is equivalent to windows registry?
The RPM package information stored in the below location
The RPM database is used to keep track of all files that are changed and created when a user installs a package. If the database gets corrupted, the index databases can be recreated with the rpm --rebuilddb command.
If you issues the rpm- qa ( query ) command then, it will read from the DB and list out the package names.
If you delete the installation directory directly, it won’t delete the record from the RPM DB. For that you need to execute the rpm –ivh (uninstall ) command , otherwise you can’t install the same package.
Thursday, July 8, 2010
How to check CPU and memory Hardware detials in RHEL system?
#cat /proc/meminfo
#cat /proc/cpuinfo
Wednesday, June 9, 2010
How to write / setup SCTP client server program in RHEL system?
Before run any SCTP application, we need to install SCTP libs from
http://lksctp.sourceforge.net/
Using the below command, register the SCTP module into kernel.
#modprobe sctp
http://linux.about.com/od/commands/l/blcmdl8_modprob.htm
SCTP Application writing:-
SCTP client and server system call follow same as TCP. ( like socket,bind,listen and accept )
Creating SCTP socket
Sock = socket( AF_INET, SOCK_STREAM, IPPROTO_SCTP );
Before listen, we need to set the value for the no.of stream for the socket using setsockopt system call.
struct sctp_initmsg startupsctp;
startupsctp.sinit_num_ostreams = 3;
startupsctp.sinit_max_instreams = 3;
startupsctp.sinit_max_attempts = 4;
ret = setsockopt( listen_Socket, IPPROTO_SCTP, SCTP_INITMSG, & startupsctp, sizeof(startupsctp) );
Using sctp_sendmsg() and sctp_recvmsg() system calls , we can send/receive data over the SCTP socket.
Example code:-
Please refer : http://www.ibm.com/developerworks/linux/library/l-sctp/
Tuesday, May 25, 2010
How to decompress the tar.bz2 format file?
tmp/test.txt
Options:
* x - extract
* c - create to create
* v - verbose
* z - gzip
* j - bzip2 ( .bz2 )
* f - file name ( after the “f” indicate the input/output file name )
