loadYOURSELF

loadYOURSELF

Entries Tagged ‘linux’

How to find multiple ip address for one domain name (with c programming)

Some domain’s serve under multiple ip addresses for example google.com

if you want to query this ip addresses then you can use this code block

#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <netdb.h>
#include <stdlib.h>
#include <stdio.h>

int main(int argc, char **argv) {
 if (argc < 2) {
   fprintf(stderr,"Usage: ./app www.google.com\n");
   exit(1);
 }

 struct hostent *hp = gethostbyname(argv[1]);

 if (hp == NULL) {
   fprintf(stderr,"query failed\n");
   exit(1);
 } else {
   unsigned int i=0;
   while ( hp -> h_addr_list[i] != NULL) {
     printf( "%d -> %s ",i, inet_ntoa( *( struct in_addr*)( hp -> h_addr_list[i])));
     i++;
   }
   exit(0);
 }
}

Buy me a beer

shell counter script (remember the number next restart)

This script counts one by one every time the user runs the script. “./scriptname reset” reset the counter.


!/bin/bash
if [ "$1" = "reset" ]
then
rm -rf fstore
fi
sayi=0
if [ -f fstore ]
then
sayi=`cat fstore`
fi
let sayi=$sayi+1
echo "INCREMENTING"
echo $sayi > fstore
echo -e -n "CURRENT="
echo $sayi

uses fstore file to remember the previous number.

Buy me a beer

High CPU usage solution for vmware on linux (files on NTFS)

If you have high cpu usage problem for your vmware application which runs on linux and the virtual machine files in NTFS partition,

you have to add:


mainMem.useNamedFile= FALSE"

to your .vmx file of you virtual machine.

this will solve the high cpu usage of mount.ntfs-3g.

Buy me a beer

Linux mbr record backup with sfdisk included extened partition infos

You can backup your system partition table with sfdisk which you can also inlude extended partitions.

backup partition table

sfdisk -d /dev/sda > my-sda.sf

restore partition table

sfdisk /dev/sda < my-sda.sf --force

you can download the sfdisk source from

ftp://ftp.kernel.org/pub/linux/utils/util-linux-ng/v2.15/

and you can compile it for your desktop PC or for your embedded device. (cross compiling)

Buy me a beer

Creating & using ext3 filesystem images

Ext3 is a linux filesystem and used by most of the linux systems. This article shows and example ext3 image usage situation.

we will create and use 20MB ext3 image. 1024×20480 bytes.

first we create an empty file with dd block size 1024

dd if=/dev/zero of=disk1.image bs=1024 count=20480

then we format that image

mkfs.ext3 -F -b 1024 disk1.image 20480

this will give an empty filesystem whose type is ext3.

Shell script to check file & directory existance

if [ -f filename ]
then
echo "file exist"
else
echo "Sorry, file does not exist"
fi

if [ -d directory ]
then
echo "directory exist"
else
echo "Sorry, directory does not exist"
fi

Buy me a beer

MBR backup with dd command @ LINUX

MBR is the master boot record of your disks. It includes also partition table. If you want to create one to one partition table and don’t want to copy all your disk you can use the commands below

to backup your mbr

dd if=/dev/sdX of=mbr.bin bs=512 count=1

to restore back your mbr

dd if=mbr.bin of=/dev/sdX bs=1 count=64 skip=446 seek=446

Buy me a beer

Moving Mobile Linux forward: Opera joins the LiMo Foundation

Opera Software today announced that it has joined the swelling ranks of mobile Linux leaders in the LiMo Foundation. Opera has a long history in developing its browser for the Linux platform and by joining this mobile Linux community the company hopes to contribute to the advancement of open and accessible mobile phone technology.

Linux Broken Pipe Error Solution

SIGPIPE signal is sent by kernel to programs whose remote end closes or shuts down the socket and your program still tries to send/write operations on closed connection. The default signal handler terminates your program at this situation because of default behavior.

Solution 1:

Ignore the signal using ’signal(SIGPIPE, SIG_IGN)’

then catch the EPIPE error which will return from the send/write operation due to a broken pipe.

Solution 2:

Pass MSG_NOSIGNAL flag to send(). This is results as same as solution 1

How to use mplayer as a YUV player (raw video)

You can use mplayer as a YUV player with the example command below.

mplayer foreman.qcif -demuxer rawvideo -rawvideo qcif

mplayer “yuv filename” -demuxer rawvideo -rawvideo “qcif,cif”

Buy me a beer