Tuesday, August 3, 2010

C Replace String Example

#include
#include

char *replace(char *st, char *orig, char *repl) {
static char buffer[4096];
char *ch;
if (!(ch = strstr(st, orig)))
return st;
strncpy(buffer, st, ch-st);
buffer[ch-st] = 0;
sprintf(buffer+(ch-st), "%s%s", repl, ch+strlen(orig));
return buffer;
}
void main() {
puts(replace("Hello world!", "world", "India"));
}

Detecting MAC Address using C application

#include 
#include
#include
#include
#include

#ifdef Linux
#include
#include
#include
#include
#include
#endif

#ifdef HPUX
#include
#endif

#ifdef AIX
#include
#include
#endif

long mac_addr_sys ( u_char *addr)
{
/* implementation for Linux */
#ifdef Linux
struct ifreq ifr;
struct ifreq *IFR;
struct ifconf ifc;
char buf[1024];
int s, i;
int ok = 0;

s = socket(AF_INET, SOCK_DGRAM, 0);
if (s==-1) {
return -1;
}

ifc.ifc_len = sizeof(buf);
ifc.ifc_buf = buf;
ioctl(s, SIOCGIFCONF, &ifc);

IFR = ifc.ifc_req;
for (i = ifc.ifc_len / sizeof(struct ifreq); --i >= 0; IFR++) {

strcpy(ifr.ifr_name, IFR->ifr_name);
if (ioctl(s, SIOCGIFFLAGS, &ifr) == 0) {
if (! (ifr.ifr_flags & IFF_LOOPBACK)) {
if (ioctl(s, SIOCGIFHWADDR, &ifr) == 0) {
ok = 1;
break;
}
}
}
}

close(s);
if (ok) {
bcopy( ifr.ifr_hwaddr.sa_data, addr, 6);
}
else {
return -1;
}
return 0;
#endif

/* implementation for HP-UX */
#ifdef HPUX

#define LAN_DEV0 "/dev/lan0"

intfd;
struct fisiocnt_block;
inti;
charnet_buf[sizeof(LAN_DEV0)+1];
char*p;

(void)sprintf(net_buf, "%s", LAN_DEV0);
p = net_buf + strlen(net_buf) - 1;

/*
* Get 802.3 address from card by opening the driver and interrogating it.
*/
for (i = 0; i < 10; i++, (*p)++) {
if ((fd = open (net_buf, O_RDONLY)) != -1) {
iocnt_block.reqtype = LOCAL_ADDRESS;
ioctl (fd, NETSTAT, &iocnt_block);
close (fd);

if (iocnt_block.vtype == 6)
break;
}
}

if (fd == -1 || iocnt_block.vtype != 6) {
return -1;
}

bcopy( &iocnt_block.value.s[0], addr, 6);
return 0;

#endif /* HPUX */

/* implementation for AIX */
#ifdef AIX

int size;
struct kinfo_ndd *nddp;

size = getkerninfo(KINFO_NDD, 0, 0, 0);
if (size <= 0) {
return -1;
}
nddp = (struct kinfo_ndd *)malloc(size);

if (!nddp) {
return -1;
}
if (getkerninfo(KINFO_NDD, nddp, &size, 0) < 0) {
free(nddp);
return -1;
}
bcopy(nddp->ndd_addr, addr, 6);
free(nddp);
return 0;
#endif

/* Not implemented platforms */
return -1;
}

/***********************************************************************/
/*
* Main (only for testing)
*/
#ifdef MAIN
int main( int argc, char **argv)
{
long stat;
int i;
u_char addr[6];

stat = mac_addr_sys( addr);
if (0 == stat) {
printf( "MAC address = ");
for (i=0; i<6; ++i) {
printf("%2.2x", addr[i]);
}
printf( "\n");
}
else {
fprintf( stderr, "can't get MAC address\n");
exit( 1);
}
return 0;
}
#endif

E.g you want to use on Linux, save it as file.c simply compile like this:

   gcc -O2 -DMAIN -DLinux file.c -o file

And run it

./file
MAC address = 0008c7e9e386

Compare with /sbin/ifconfig result:

/sbin/ifconfig eth0
eth0 Link encap:Ethernet HWaddr 00:08:C7:E9:E3:86
inet addr:***.***.***.*** Bcast:***.***.***.*** Mask:255.255.255.0
inet6 addr: ********************* Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:265555947 errors:0 dropped:0 overruns:0 frame:0
TX packets:50507373 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:4090310752 (3.8 GiB) TX bytes:1085018636 (1.0 GiB)

It’s the same :)

Tuesday, July 13, 2010

advanced programming in the Unix environment

Advanced Programming in the UNIX Environment, Addison-Wesley, 1992, ISBN 0-201-56317-7.
Here i added the example code please click here

Monday, June 7, 2010

RFID Card READER

we designed and built (and exhaustively tested) an RFID-based proximity security system for use with Cornell Identification cards, which have been RFID-embedded since fall of 2003. The idea for this project was sort of spawned from our general interest in RFID technologies and the near-simultaneous occurance of Lab 2 (Keypad Security System) and the antiquated lock system at our fraternity house breaking.

MORE DETAILS

Thursday, June 3, 2010

list of access control system manufacturer

I have a good list of access control system manufacturer. Below list will help you to select good device.

  1. SOLUS
  2. SYRIS
  3. ELECTRON INDIA
  4. BOSCH
  5. HONEYWELL

List of Online Shopping Electronic Product website

The below Website will help you to buy Electronic product.
  1. CHIPSILICON
  2. DIGIKEY
  3. ALIBABA
  4. TENET TECHNOLOGIES

HAND-HELD ELECTRONIC ENCLOSURE GAINTA

GAINTA, a privately owned Taiwan company, is one of the largest enclosure manufacturers in Asia, and is the market leader in thermoplastic enclosures used for protecting electrical and electronic components operating in hostile environments. GAINTA enclosures are manufactured in modern factories located in Taiwan

Whatever your application, the GAINTA enclosure family features the widest range of high quality enclosures for the packaging and protection of electrical and electronic components and systems. Enclosures can be delivered in standard off the shelf configurations or customized to your exact specifications. .

Continuous Product Development
The GAINTA enclosure range features over 700 different standard enclosures made of polycarbonate, ABS, fiberglass and aluminium. GAINTA is the industry leader in developing both new products and new technologies for molding thermoplastic enclosures. At GAINTA, we consider molding technology an essential part of product development.

But more important than technical leadership, is the GAINTA commitment to understanding the needs of its customers. All our products are designed in close cooperation with our customers. We use input from our global customer base to produce new enclosure ranges, useful accessories and on-going product improvements and enhancements.


Please click here to see enclosure.


Our local dealers will delivered in banglore.

Wednesday, May 26, 2010

Warning: Remote Host Identification Has Changed error and solution

When I run ssh command I get an error which read as follows:

@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@ WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED! @
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
IT IS POSSIBLE THAT SOMEONE IS DOING SOMETHING NASTY!
Someone could be eavesdropping on you right now (man-in-the-middle attack)!
It is also possible that the RSA host key has just been changed.
The fingerprint for the RSA key sent by the remote host is
5c:9b:16:56:a6:cd:11:10:3a:cd:1b:a2:91:cd:e5:1c.
Please contact your system administrator.
Add correct host key in /home/user/.ssh/known_hosts to get rid of this message.
Offending key in /home/user/.ssh/known_hosts:1
RSA host key for ras.mydomain.com has changed and you have requested strict checking.
Host key verification failed.

How do I get rid of this message?

If you have reinstalled Linux or UNIX with OpenSSH, you will get the above error. To get rid of this problem:

Solution #1: Remove keys

Use the -R option to removes all keys belonging to hostname from a known_hosts file. This option is useful to delete hashed hosts. If your remote hostname is server.example.com, enter:
$ ssh-keygen -R {server.name.com}
$ ssh-keygen -R {ssh.server.ip.address}
$ ssh-keygen -R server.example.com

Sample output:

/home/vivek/.ssh/known_hosts updated.
Original contents retained as /home/vivek/.ssh/known_hosts.old

Now, you can connect to the host without a problem.

Solution #2: Add correct host key in /home/user/.ssh/known_hosts

It is not necessary to delete the entire known_hosts file, just the offending line in that file. For example if you have 3 server as follows.
myserver1.com,64.2.5.111 ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAIEA11FV0EnGahT2EK8qElocjuHTsu1jaCfxkyIgBTlxlrOIRchb2pw8IzJLOs2bcuYYfa8nSXGEcWyaFD1ifUjfHelj94AAAAB3NzaC1yc2EAAAABIwAAAIEA11FV0E
nGahT2EK8qElocjuHTsu1jaCfxkyIgBTlxlrOIRchb2pw8IzJLOs2bcuYYfa8nSXGEcWyaFD1ifUjfHelj94H+uv304/ZDz6xZb9ZWsdm+264qReImZzruAKxnwTo4dcHkgKXKHeefnBKyEvvp/2ExMV9WT5DVe1viVwk=
myserver2.com,125.1.12.5 ssh-rsa
AAAAB3NzaC1yc2EAAAABIwAAAQEAtDiERucsZzJGx/1kUNIOYhJbczbZHN2Z1gCnTjvO/0mO2R6KiQUP4hOdLppIUc9GNvlp1kGc3w7B9tREH6kghXFiBjrIn6VzUO4uwrnsMbnAnscD5EktgI7fG4ZcNUP 5+J7sa3o+rtmOuiFxCA690DXUJ8nX8yDHaJfzMUTKTGxQz4M/H2P8L2R//qLj5s3ofzNmgSM9lSEhZL/IyI4NxHhhpltYZKW/Qz4M/H2P8L2R//qLj5s3ofzNmgSM9lSEhZL/M7L0vKeTObue1SgAsXADtK3162a/Z6MGnAazIviHBldxtGrFwvEnk82+GznkO3IBZt5vOK2heBnqQBfw=
myserver3.com,125.2.1.15 ssh-rsa
5+J7sa3o+rtmOuiFxCA690DXUJ8nX8yDHaJfzMUTKTGx0lVkphVsvYD5hJzm0eKHv+oUXRT9v+QMIL+um/IyI4NxHhhpltYZKW
as3533dka//sd33433////44632Z6MGnAazIviHBldxtGrFwvEnk82/Qz4M/H2P8L2R//qLj5s3ofzNmgSM9lSEhZL/M7L0vKeTObue1SgAsXADtK3162a/Z6MGnAazIviHBldxtGrFwvEnk82+GznkO3IBZt5vOK2heBnqQBfw==

To delete 2nd server (myserver.com), open file:
# vi +2 .ssh/known_hosts
And hit dd command to delete line. Save and close the file. Or use following
$ vi ~/.ssh/known_hosts
Now go to line # 2, type the following command
:2
Now delete line with dd and exit:
dd
:wq

Solution 3: Just delete the known_hosts file If you have only used one ssh server

$ cd
$ rm .ssh/known_hosts
$ ssh ras.mydomain.com

Now you should be able to connect your server via ssh.

Wednesday, May 19, 2010

AT91RM9200 Documents

Please check the below link. you will get all details.
http://opencircuits.com/Linuxstamp#Description

Linux driver source code

Below web site will help you to get source file.
http://www.mjmwired.net/kernel/Documentation/rtc.txt

Circuit and PCB

The Below website will help you to get PCB and circuit diagram.
http://www.microbuilder.eu

Thursday, May 6, 2010

GNOME2 IP Messenger

A few things about GNOME2 IP Messenger (g2ipmsg), though.

Make sure you have all dependencies installed:

  • libxml-parser-perl

  • libgnomeui-dev

  • libpanel-applet2-dev


(UPDATE 2008-07-06 2:35AM -- additional dependencies)

  • gettext

  • intltool


How to install these depends on the Linux distribution. The easiest way is to use the graphical Package Manager.

(MAJOR UPDATE 2008-07-07 5:27PM)
Randell reported that he couldn't find the dependencies in Fedora -- I was surprised! I did a search and found out that libxml-parser-perl was perl-XML-parser in Fedora! I suppose that the rest of the dependencies are only for Debian-based distros. Randell said that he'd look up the rest, and post a Fedora instructional soon. With that, I'm slapping the apt-get command back into the list below.

After assuring that you have the above dependencies, you can do a conventional build and install from source. Assuming that the current working directory is where g2ipmsg-0.9.5.tar.gz is located:

$ tar zxf g2ipmsg-0.9.5.tar.gz
$ cd g2ipmsg-0.9.5/
$ sudo apt-get install libxml-parser-perl libgnomeui-dev libpanel-applet2-dev gettext intltool
$ ./configure
$ make
$ sudo make install
$ sudo g2ipmsg

Make sure to execute sudo g2ipmsg right after installation. You'll only be able to run it without the sudo after a reboot -- I don't know why, though.

I suddenly posted something like this because while researching specifically about this, the search results with definite instructions were non-English sites.

Monday, April 26, 2010

Cross Compile SSH Server Dropbear For ARM

Requirements:
  • ubuntu 8.04
  • gcc 4.2.3
  • arm_v5t_le-gcc 3.4.3
Source:
Install Zlib:
  • wget http://www.zlib.net/zlib-1.2.3.tar.gz
  • tar zxvf zlib-1.2.3.tar.gz
  • mkdir zlib
  • cd zlib-1.2.3/
  • CC=arm_v5t_le-gcc ./configure --prefix=/home/border/work/SMG/build-tools/zlib
  • make
  • make install
Install Dropbear:
  • wget http://matt.ucc.asn.au/dropbear/releases/dropbear-0.51.tar.gz
  • tar zxvf dropbear-0.51.tar.gz
  • mkdir dropbear-build
  • cd dropbear-build/
  • mkdir build
  • ../dropbear-0.51/configure --prefix=/home/border/work/SMG/build-tools/dropbear-build/build/ \
    --with-zlib=/home/border/work/SMG/build-tools/zlib/ CC=arm_v5t_le-gcc --host=arm
  • make
  • make scp
  • sudo make install
  • sudo cp scp build/bin/

border@b0rder:~/work/SMG/build-tools/dropbear-build/build$ tree
.
|-- bin
| |-- dbclient
| |-- dropbearconvert
| |-- dropbearkey
| `-- scp
`-- sbin
`-- dropbear
Server Key:
  • cd /etc
  • mkdir dropbear
  • cd dropbear
  • dropbearkey -t rsa -f dropbear_rsa_host_key
  • dropbearkey -t dss -f dropbear_dss_host_key

How to run wireshark in Terminal

  1. Download wireshark and Install (http://linux.softpedia.com/get/Internet/HTTP-WWW-/Ethereal-1961.shtml)
  2. Open Terminal
  3. Run wireshark -i eth0 -k

Thursday, March 25, 2010

Set timezone using /etc/localtime configuration file [any Linux distro]

Often /etc/localtime is a symlink to the file localtime or to the correct time zone file in the system time zone directory.

Generic procedure to change timezone

Change directory to /etc
# cd /etc

Create a symlink to file localtime:
# ln -sf /usr/share/zoneinfo/EST localtime
OR some distro use /usr/share/zoneinfo/dirname/zonefile format (Red hat and friends)
# ln -sf /usr/share/zoneinfo/EST localtime
OR if you want to set up it to IST (Asia/Calcutta):
# ln -sf /usr/share/zoneinfo/Asia/Calcutta localtime
Please mote that in above example you need to use directory structure i.e. if you want to set the timezone to Calcutta (India) which is located in the Asia directory you will then have to setup using as above.

Use date command to verify that your timezone is changed:
$ date
Output:

Tue Aug 27 14:46:08 EST 2006

Use of environment variable

You can use TZ environment variable to display date and time according to your timezone:
$ export TZ=America/Los_Angeles
$ date

Sample Output:

Thu Aug 27 11:10:08 PST 2006

Wednesday, March 24, 2010

Linux Set Date and Time From a Command Prompt

Linux Set Date

Use the following syntax to set new data and time:
date set="STRING"

For example, set new data to 2 Oct 2006 18:00:00, type the following command as root user:
# date -s "2 OCT 2006 18:00:00"
OR
# date set="2 OCT 2006 18:00:00"

You can also simplify format using following syntax:
# date +%Y%m%d -s "20081128"

Linux Set Time

To set time use the following syntax:
# date +%T -s "10:13:13"
date -s "042616132010"

Friday, March 12, 2010

How to setup http server in beagle board

please Follow below step
  1. Download the software
  2. Extract the software
  3. Compile the code(gcc -o httpd httpd.c -lpthread)
  4. Run output(./httpd)
check port and IP
If you give correct IP and port you will get the page.

Thursday, March 11, 2010

How to run script in Start UP Linux

setting script in Linux start UP
Please do the Following step:
  1. Write a script file(Eg: new_script).
  2. make it executable (Eg:chmod +x new_script ).
  3. Copy the script in to /etc/init.d/
  4. ln -s /etc/init.d/new_script /etc/rc5.d/S50new_script
  5. ln -s /etc/init.d/new_script /etc/rc5.d/K50new_script
  6. Restart the machine.
After the restart your script will work in start up.