Tuesday, May 30, 2006
Friday, May 19, 2006
Check ur Linux MAC address
On Linux, you can use the ioctl SIOCGIFHWADDR, an open socket and an ifreq structure to retrieve information on any network interface. The MAC address is stored on the ifr_hwaddr member of the ifreq structure:
#include
#include
#include
#include
#include
#include
int main(int argc,char** argv)
{
int fd;
struct ifreq ifbuf;
struct sockaddr_in sa;
unsigned char* hwaddr;
fd = socket(AF_INET, SOCK_DGRAM, 0);
strcpy(ifbuf.ifr_name,argv[1]?argv[1]:"eth0");
ioctl(fd,SIOCGIFHWADDR,&ifbuf);
hwaddr = (unsigned char*) ifbuf.ifr_hwaddr.sa_data;
printf("%2.2X:%2.2X:%2.2X:%2.2X:%2.2X:%2.2X\n",hwaddr[0],hwaddr[1],hwaddr[2],hwaddr[3],hwaddr[4],hwaddr[5]);
return 0;
}
soumya@abracadabra:~/codes/cpp$ gcc -o sucket_out sucket.c
soumya@abracadabra:~/codes/cpp$ ./sucket_out
00:0E:A6:64:2D:39
Posted by Unknown at 11:19 AM
Tuesday, May 16, 2006
Colourful GREP
This is how GNU defines GREP
" The grep command searches one or more input files for lines containing a match to a specified pattern. By default, grep prints the matching lines. "
grep basically searches. To be more precise,
grep bacteria food
returns all the lines that contain a string matching the expression "bacteria" in the file "food".
If we assume an expression as a string. So grep returns all matching lines that contain bacteria as a substring. Another way of using grep is to have it accept data through STDIN
. instead of having it search a file. For example,
ls |grep vindo
lists all files in the current directory whose names contain the string "vindo"
Now I guess you know how grep works.In case you are still in doubt about GREP please ask Mr.Google. My main objective of writing this blog is to introduce the normal unix users to the colourful version of grep.So when u search for the term it will become automatically highlighted. Just check out the sreenshot on top.
How can I do it ?
Well one just needs to edit his/her .bashrc file and put up an alias for grep.
alias G=' grep -ni --color=auto '
That's it done .Your colourfull grep is ready for use :)
Posted by Unknown at 12:04 AM
Saturday, May 13, 2006
Who copied whom
Take a look at new Yahoo Mail beta version and at the some other application called Zimbra. Who copied whom ??
Posted by Unknown at 4:46 PM
Tuesday, May 09, 2006
Distcc and increasing compiling speed
Distcc allows you to easily distribute your compilation jobs over a number of machines, so even if u have an outdated system still u can compile huge codes pretty fast if u have hooked up ur system with some other using distcc.
The requirments are minimal:
- Install GCC and distcc on all the machines you wish to use for the "compile farm".
As you can see there are no onerous requirements, common with distributed work. Specifically:
- You don't need to have the same libraries and development packages on all systems.
- You don't need to have a single filesystem which all machines can access.
- The clocks on all the machines don't need to be in sync.
apt-get install distcc
When the package is installed you'll be asked two questions :
- Should distcc be started on boot?
- Answer yes if think you will wish to use the package often, or no if not. (No is the default)
- Which machines should be allowed to connect to the distcc server?
- Asnwer with the machines you wish to allow, and the localhost
The answers you give will be stored away in the configuration file /etc/default/distcc.
Install the package on all the other machines you wish to use and make sure that each one is allowed to connect to the other.
There are several ways you can specify the hosts which should be used to perform the compilation:
- Via the environmental variable "DISTCC_HOSTS"
- Via the a per-user configuration file ~/.distcc/hosts
Assuming that you have two machines appy and abracadabra and wish to compile a job you could run using distcc as follows:
soumya@abracadabra:~/tmp$ export DISTCC_HOSTS="appy abracadabra"
soumya@abracadabra:~/tmp$ make CC=distcc
This specifies the two machines you wish to use for the compilation, and runs make telling it to use distcc as the compiler.
Once you do this you should find that the jobs are spread fairly evenly across the two machines.
Once you've installed the distcc program on each machine you must:
- Tell the local instance which machines it can contact to compile files upon remotely.
- Make sure you use "distcc" instead of "gcc" as the compiler command in your Makefile / build system.
Tats it done, now u need not go for coffee while compiling codes :)
Posted by Unknown at 4:42 PM