15 December 2009

how to make linux kernel 2.6.32

Download Linux 2.6.32 source code from here.
Download the config file for 2.6.32 from here..

cd /usr/src/kernels
tar xjvf linux-2.6.32.tar.bz2
mv config.32 .config
make oldconfig
make
make modules_install
make install
noticeable changes:
Intel ATOM CPU Support
...

Reference:
/2009/10/make-mininal-linux-kernel-from-fedora.html

10 November 2009

wget

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <netdb.h>
#include <sys/types.h>
#include <netinet/in.h>
#include <sys/socket.h>

#include <fcntl.h>
#include <libgen.h>

char *gethostname(char *url)
{
if(strstr(url, "http://"))
{
url += strlen("http://");
}
if(strstr(url, "https://"))
{
url += strlen("https://");
}
if(strchr(url, '/'))
{
strchr(url, '/')[0] = '\0';
}

return url;
}

char *getfilename(char *file)
{
if(file[0] == '\0')
strcpy(file, "test.txt");
if(file[0] == '/' && file[1] == '\0')
strcpy(file, "test.txt");

return file;
}


#define PORT 80

int connect_to_ip(char *host)
{
int sock;
int sockfd;
struct hostent *he;
struct sockaddr_in their_addr;


if((he = gethostbyname(host)) == NULL)
{
perror("gethostbyname(): fail: ");
exit(1);
}
else
printf("Client-The remote host is: %s\n", host);

if((sockfd = socket(AF_INET, SOCK_STREAM, 0)) == -1)
{
perror("socket()");
exit(1);
}
else
printf("Client-The socket() sockfd is OK...\n");

their_addr.sin_family = AF_INET;
printf("Server-Using %s and port %d...\n", host, PORT);
their_addr.sin_port = htons(PORT);
their_addr.sin_addr = *((struct in_addr *)he->h_addr);
memset(&(their_addr.sin_zero), '\0', 8);

if(connect(sockfd, (struct sockaddr *)&their_addr, sizeof(struct sockaddr)) == -1)
{
perror("connect()");
exit(1);
}
else
printf("Client-The connect() is OK...\n");

return sockfd;
}

char *gethdr(char *buff, int size, FILE *sfp)
{
char *s;
memset((char*)buff, 0, size);

fgets(buff, size, sfp);

for(s=buff; *s == '\r'; ++s) continue;
if(*s == '\n') return NULL;

/* locate the end of header */
while (*s && *s != '\r' && *s != '\n')
++s;

*s = '\0';

return buff;
}


#define isspace(s) (*s == ' ')

char *skip_whitespace(char *str)
{
while(isspace(str)) ++str;

return str;
}

char *skip_non_whitespace(char *str)
{
while(*str && !isspace(str)) ++str;

return str;
}


void getfile(int sockfd, char *host, char *file)
{
char cmd[1024] = {};
char buff[512] = {};
char *fname;
int fd, len=0;
int hack = 0;
FILE *sfp;
char *str;

/* open outpt file */
fname = basename(file);
fd = open(fname, O_CREAT|O_RDWR, 0755);

sprintf(cmd, "GET %s HTTP/1.1\r\n", file);
sprintf(cmd, "%sHost: %s\r\n", cmd, host);
sprintf(cmd, "%s\r\n", cmd);

write(sockfd, cmd, strlen(cmd));
printf("cmd: %s\n", cmd);

/* skip the HEADER */
/* START */
sfp = fdopen(sockfd, "r+");
gethdr(buff, 20, sfp);

str = buff;
str = skip_non_whitespace(str);
str = skip_whitespace(str);
printf("%s, status: %d\n", buff, atoi(str));

while(gethdr(buff, sizeof(buff), sfp) != NULL)
printf("%s\n", buff);

fflush(sfp);
/* END */

while(1)
{
memset((char*)buff, 0, sizeof(buff));
len=read(sockfd, buff, sizeof(buff));

write(fd, buff, len);

if(len <= 0) break;
}

close(fd);
close(sockfd);

return;
}

int main(int argc, char *argv[])
{
char *host, *file;
char url[256] = {};
int sockfd;

if(argc < 2)
{
printf("usage: %s \n", argv[0]);
exit(0);
}

strcpy(url, argv[1]);
host = gethostname(url);
file = argv[1];
file = getfilename(&file[host+strlen(host)-url]);
printf("url: %s, file: %s\n", url, file);

sockfd = connect_to_ip(host);
getfile(sockfd, host, file);

printf("\nsuccessfully written to \"%s\"\n\n", basename(file));

return 0;
}

gcc -o wget wget.c
./wget http://www.dhpc.adelaide.edu.au/education/dhpc/lab/MPI/hello.c
./wget www.physics.arizona.edu/~physreu/dox/cprogs/day1/hello.c

21 October 2009

Flo Rida n Kesha - Right Round

(Flo Rida)
You spin my head right round, right round
When you go down, when you go down down...
(Kesha)
You spin my head right round, right round
When you go down, when you go down down...

(Flo Rida)
Heyy!
Hopped out of that house with my swagger
Hop in that with girl, I got places to go!
People to see, time is precious
I look at my crowd and they out of control
Just like my mind where I'm going
No women, no shorties, no nothin but clothes
No stoppin now, my parolees on role
I like my jewlrey, that's always on gold
I know the storm is comin
My pockets keep tellin me it's gonna shower
Call up my homies that's home
Then pop in the night cuz it's meant to be ours
We keep a fade away shot cuz we ballin
it's platinum patrone that be ours
Lil mama, I owe you just like the flowers
Girl you to drink with all that and power clubs

(Flo Rida)
You spin my head right round, right round
When you go down, when you go down down...
(Kesha)
You spin my head right round, right round
When you go down, when you go down down...

(Flo Rida)
From the top of the pole I watch her go down
She got me throwin my money around
Ain't nothin more beautiful to be found
It's goin down down...
From the top of the pole I watch her go down
She got me throwin my money around
Ain't nothin more beautiful to be found
It's goin down down...

(Flo Rida)
Heyy!
Shawty must know I'm not playin
My money love her like a numba one fan
Don't look at my mouth, let her talk to my fans
My Benjamin Franklins...
A couple of grands, I got rubberbands
My paper planes makin a dance
Get dirty all night, that's part of my thing
Keep building castles that's made out of sand
She's amazing, the fire blazing
Hotter than cajun
Girl won't you move a lil closer?
Time to get paid, it's maximum wage
That body belong on a poster
I'm in a daze, that bottom is wavin' at me
Like damnit I know you
You wanna show like a gun out of holster
Tell me whatever and I'll be your roper cuz...

(Flo Rida)
You spin my head right round, right round
When you go down, when you go down down...
(Kesha)
You spin my head right round, right round
When you go down, when you go down down...

(Flo Rida)
From the top of the pole I watch her go down
She got me throwin my money around
Ain't nothin more beautiful to be found
It's goin down down...
From the top of the pole I watch her go down
She got me throwin my money around
Ain't nothin more beautiful to be found
It's goin down down...

(Flo Rida)
Yeah!
I'm spendin my money
I'm out of control
Somebody help me
She's takin my bank roll.
But I'm king of the club
And I'm wearin the crown
Poppin these bottles
Touchin these models
Watchin they asses go down down....(echo)

(Flo Rida)
You spin my head right round, right round
When you go down, when you go down down...
(Kesha)
You spin my head right round, right round
When you go down, when you go down down...
(Flo Rida)
You spin my head right round, right round
When you go down, when you go down down...
(Kesha)
You spin my head right round, right round
When you go down, when you go down down...

15 October 2009

Brain Teaser - 2



Reference:
download the executable Extractaflash

View the code

linux module initialisation

1. “module_init” and “__initcall” will be added into a new section called “.initcall6.init”

2. The macro “__initcall” and “module_init” (include/linux/init.h) will group all such functions into a single section called “.initcall6.init” and all these functions get executed on system bootup by the function “do_initcalls” (init/main.c)

3. init() -> do_basic_setup() -> do_initcalls()

4. The functions will be collected between the symbols “__early_initcall_end” and “__initcall_end” in the file (arch/x86/kernel/vmlinux.lds.S -> arch/x86/kernel/vmlinux.lds)

5. All the __initcalls are arranged in kernel the range from 0 to 7. Hence kernel does the initialization in order

14 October 2009

Reverse bits the easy way

typedef unsigned int uint;
uint reverse(uint val)
{
int i;
uint tval=0;

for(i=0; i<sizeof(val)*8; i++)
{
tval <<= 1;
tval |= val&1;
val >>= 1;
}

return tval;
}
typedef unsigned int uint;
uint reverse(uint val)
{
char i;
uint tval=0;

for(i=sizeof(val)*8; val; i--)
{
tval <<= 1;
tval |= val&1;
val >>= 1;
}

return (tval<<i);
}

Reference:
http://graphics.stanford.edu/~seander/bithacks.html#CountBitsSetNaive

12 October 2009

script remove unwanted folders from linux kernel

----------------------script.sh----------------------
#!/bin/sh

ARCHDIRS="alpha blackfin h8300 m68knommu mn10300 s390 arm \
cris m32r microblaze parisc sh avr32 frv ia64 m68k mips \
powerpc sparc xtensa"

for DIR in $ARCHDIRS; do
echo "deleting $DIR"
rm -rf arch/$DIR
done

rm -rf Documentation

DOCDIRS=" / accounting auxdisplay connector DocBook \
filesystems ia64 networking pcmcia spi video4linux vm \
watchdog"

for DIR in $DOCDIRS; do
echo "creating Documentation/$DIR/Makefile"
mkdir -p Documentation/$DIR
touch Documentation/$DIR/Makefile
done
-----------------------------------------------------

make a mininal linux kernel from Fedora Core 11

1. allocate 12GB of HDD space
2. Install FC11 on VMware
3. Review and modify partitioning layout
4. Delete VolGroup, sda1 and sda2 partitions
5. Create 512MB swap space
6. Create EXT3 file system and mount pount "/"
7. Select "customize now" for software selection
8. Un-select everything in software selection
9. A total of 179 packages will get installed.

mkdir /mnt/cdrom
vi /etc/fstab
>> /dev/cdrom /mnt/cdrom iso9660 defaults 0 0
mount /dev/cdrom
cd /mnt/cdrom/Pakages
rpm -ivh createrepo + DEPENDENCY FILES
rpm -ivh yum + DEPENDENCY FILES
cd /mnt
createrepo .

cd /etc/yum.repos.d/
vi fedora.repo >> enabled=0
vi fedora-updates.repo
>> baseurl=file:///mnt
>> #baseurl
>> #mirrorurl
>> enabled=1
>> gpgcheck=0

yum install ftp make which vim ctags gcc ncur* man-pages
yum install dhclient bzip2 kerenal-devel man ntsysv gpm
yum install openssl* ...

vi /etc/syscofig/network-scripts/ifcfg-eth0
>> DEVICE=eth0
>> BOOTPROTO=dhcp
>> ONBOOT=yes

mv /bin/vi{,.old}
ln -s /usr/bin/vim /bin/vi

vi /sbin/mkinitrd
>> after "mknod /dev/hvc0 c 229 0"
>> mknod /dev/sda b 8 0
>> mknod /dev/sda1 b 8 1
>> mknod /dev/sda2 b 8 2
vi /etc/fstab
>> /dev/sda1 / ext3 defaults 0 0
>> /dev/sda2 swap swap defaults 0 0
Download the config file for 2.6.31 from here.
Download the config file for 2.6.31 (with S/W shutdown) from here
cd /usr/src/kernels
tar xjvf linux-2.6.31.tar.bz2
mv config.31 .config
make oldconfig
make
make modules_install
make install
You can get the sample make log file from here
vi /boot/grub/grub.conf
>> default=0
>> timeout=10
>> #hiddenmenu
>> # ... rghb quiet

22 September 2009

RJ45

10base-T straight cable
Pin No.strand colorName
1white and orangeTX+
2orangeTX-
3white and greenRX+
4NC*
5NC*
6greenRX-
7NC*
8NC*

10base-T cross cable
One end
RJ45 Male
Other end
RJ45 Male
1 (TX+)3 (RX+)
2 (TX-)6 (RX-)
3 (RX+)1 (TX+)
**
**
6 (RX-)2 (TX-)
**
**


100base-T straight cable
Pin No.conductor colorName
1white and orangeTX_D1+
2orangeTX_D1-
3white and greenRX_D2+
4blueBI_D3+
5white and blueBI_D3-
6greenRX_D2-
7white and brownBI_D4+
8brownBI_D4-

100base-T cross cable
One end
RJ45 Male
Other end
RJ45 Male
1 (TX_D1+)3 (RX_D2+)
2 (TX_D1-)6 (RX_D2-)
3 (RX_D2+)1 (TX_D1+)
4 (BI_D3+)7 (BI_D4+)
5 (BI_D3-)8 (BI_D4-)
6 (RX_D2-)2 (TX_D1-)
7 (BI_D4+)4 (BI_D3+)
8 (BI_D4-)5 (BI_D3-)



Reference:
http://konfigurasi-lan.blogspot.com/2008/07/lan.html
http://konfigurasi-lan.blogspot.com/2008_07_01_archive.html

18 September 2009

miscellaneous in C


Type int represents a machine's natural word size.

#define abs(x) ((x < 0)? -x : x)

#define offsetof(type, member) ((size_t)&((type *)0)->member)

#define roundup(x, y) (x + (x % y))

#define _THIS_IP_ ({ __here: (unsigned long)&&__here; })

#define swap(a, b) ({typeof(a) __tmp = a; a = b; b = __tmp;})

#define container_of(ptr, type, member) ({ \
(type *)((char *)ptr - offsetof(type, member)); })

#define dprintf(fmt, arg...) printf("%s:%s:%d " fmt "\n", \
__FILE__, __FUNCTION__, __LINE__, ##arg)

typedef unsigned char u8;
typedef unsigned long u32;

#define set(val, addr) (*(volatile u32 *)addr = val)

void wrap_printf(const char *fmt, ...) {
va_list args;

va_start(args, fmt);
vprintf(fmt, args);
va_end(args);
}

Reference:
http://www.linuxjournal.com/article/7269
http://c-faq.com
http://kernelnewbies.org/FAQ/DoWhile0
http://publications.gbdirect.co.uk/c_book/chapter9/stdarg.html

17 September 2009

doubly linked list in C

list *reverse(list *current)
{
list *prev = NULL;
list *next = NULL;

while(current)
{
next = current->next; //tricky: save the next node
current->next = prev; //point current to previous
current->prev = next; //point current to next
prev = current;
current = next;
}

return prev;
}

---------------------dlist.c---------------------
#include <stdio.h>
#include <stdlib.h>

typedef struct list{
int val;
struct list *next;
struct list *prev;
}list;

list *getfirst(list *head)
{
while(head && head->prev) head = head->prev;
return head;
}

list *getlast(list *head)
{
while(head && head->next) head = head->next;
return head;
}

void print(list *head1)
{
list *head = NULL;
list *end = NULL;

head = head1;
printf("to next: ");
while(head)
{
printf("%d->", head->val);
head = head->next;
}
printf("NULL\n");

head = getlast(head1);
printf("to prev: ");
while(head)
{
printf("%d->", head->val);
head = head->prev;
}
printf("NULL\n");
}


list *insert(list *head, int val)
{
list *new = (list*)malloc(sizeof(list));
new->val = val;
new->prev = NULL;
new->next = head;

if(head) head->prev = new;

return new;
}

list *reverse(list *current)
{
list *prev = NULL;
list *next = NULL;

while(current)
{
next = current->next; //tricky: save the next node
current->next = prev; //point current to previous
current->prev = next; //point current to next
prev = current;
current = next;
}

return prev;
}

int main()
{
list *head = NULL;

head = insert(head, 10);
head = insert(head, 20);
head = insert(head, 60);
head = insert(head, 51);
head = insert(head, 73);
head = insert(head, 19);
head = insert(head, 10);
head = insert(head, 81);
head = insert(head, 95);
printf("before reverse:\n");
print(head);

printf("after reverse:\n");
head = reverse(head);
print(head);

return 0;
}
-------------------------------------------------

Output:
before reverse:
to next: 95->81->10->19->73->51->60->20->10->NULL
to prev: 10->20->60->51->73->19->10->81->95->NULL
after reverse:
to next: 10->20->60->51->73->19->10->81->95->NULL
to prev: 95->81->10->19->73->51->60->20->10->NULL

reverse a string in C

void reverse(char *buf)
{
char *start = buf;
char *end = buf + strlen(buf) - 1;

while(start < end)
swap(start++, end--);

}
#include <stdio.h>
#include <string.h>

void swap(char *s1, char *s2)
{
char t = *s1;
*s1 = *s2;
*s2 = t;
}

void swap2(char *s1, char *s2)
{
*s1 ^= *s2;
*s2 ^= *s1;
*s1 ^= *s2;
}

void reverse(char *buf)
{
char *start = buf;
char *end = buf + strlen(buf) - 1;

while(start < end)
swap(start++, end--);
}

int main()
{
char buf[] = "program to reverse a string";

printf("before: %s\n", buf);
reverse(buf);
printf("after : %s\n", buf);

return 0;
}

output:
before: program to reverse a string
after : gnirts a esrever ot margorp

15 September 2009

single linked list in C

list *reverse(list *current)
{
list *prev = NULL;
list *next = NULL;

while(current)
{
next = current->next; //tricky: save the next node
current->next = prev; //point current to previous
prev = current;
current = next;
}

return prev;
}

--------------------llist.c--------------------
#include <stdio.h>
#include <stdlib.h>

typedef struct list{
int val;
struct list *next;
}list;


list *insert(list *head, int val)
{
list *new = (list*)malloc(sizeof(list));
new->val = val;
new->next = head;

return new;
}

void print(list *head)
{
while(head)
{
printf("%d->", head->val);
head = head->next;
}

printf("NULL\n");
}

list *reverse(list *current)
{
list *prev = NULL;
list *next = NULL;

while(current)
{
next = current->next; //tricky: save the next node
current->next = prev; //point current to previous
prev = current;
current = next;
}

return prev;
}

int main()
{
list *head = NULL;

head = insert(head, 10);
head = insert(head, 12);
head = insert(head, 20);
head = insert(head, 17);
head = insert(head, 25);
head = insert(head, 3);
head = insert(head, 75);
head = insert(head, 49);
head = insert(head, 32);
printf("before reverse: ");
print(head);

head = reverse(head);
printf("after reverse: ");
print(head);

return 0;
}
-----------------------------------------------

Output:
before reverse: 32->49->75->3->25->17->20->12->10->NULL
after reverse: 10->12->20->17->25->3->75->49->32->NULL

binary tree in C

int count(node *head)
{
if(head == NULL) return 0;

return count(head->left) + 1 + count(head->right);
}

int depth(node *head)
{
if(head == NULL)
return 0;
else
{
int ldepth = depth(head->left);
int rdepth = depth(head->right);

if(ldepth < rdepth) return rdepth+1;
else return ldepth+1;
}
}

int compare(node *n1, node *n2)
{
if(n1==NULL && n2==NULL)
return true;
else if(n1!=NULL && n2!=NULL)
{
return ((n1->val==n2->val) &&
compare(n1->left, n2->left) &&
compare(n1->right, n2->right));
}
else return false;
}

-----------------btree.c-----------------
#include <stdio.h>
#include <stdlib.h>

typedef struct node{
int val;
struct node *left;
struct node *right;
}node;


void print(node *head)
{
if(head == NULL) return;

print(head->left);
printf("%d->",head->val);
print(head->right);
}

node * insert(node *head, int val)
{
if(head == NULL)
{
head = (node*)malloc(sizeof(node));
head->left=head->right=NULL;
head->val = val;
}
else if(val < head->val)
head->left = insert(head->left, val);
else if(val > head->val)
head->right = insert(head->right, val);
else
printf("duplicate vale (%d)\n", val);

return head;
}

int count(node *head)
{
if(head == NULL) return 0;

return count(head->left) + 1 + count(head->right);
}

int count2(node *head)
{
int count = 0;

if(head == NULL) return 0;
count += count2(head->left);
count += count2(head->right);

return ++count;
}

void count3(node *head, int *count)
{
if(head == NULL) return;

count3(head->left, count);
count3(head->right, count);
(*count)++;
}

int depth(node *head)
{
if(head == NULL)
return 0;
else
{
int ldepth = depth(head->left);
int rdepth = depth(head->right);

if(ldepth < rdepth) return rdepth+1;
else return ldepth+1;
}
}

#define true 1
#define false 0
int compare(node *n1, node *n2)
{
if(n1==NULL && n2==NULL)
return true;
else if(n1!=NULL && n2!=NULL)
{
return ((n1->val==n2->val) &&
compare(n1->left, n2->left) &&
compare(n1->right, n2->right));
}
else return false;
}

int main()
{
node *head1 = NULL;
node *head2 = NULL;
int c1 = 0;

head1 = insert(head1, 50);
insert(head1, 40);
insert(head1, 70);
insert(head1, 30);
insert(head1, 25);
insert(head1, 90);
insert(head1, 45);
insert(head1, 10);
insert(head1, 55);
insert(head1, 85);
print(head1); printf("NULL\n");

head2 = insert(head2, 50);
insert(head2, 40);
insert(head2, 70);
insert(head2, 30);
insert(head2, 25);
insert(head2, 90);
insert(head2, 45);
insert(head2, 10);
insert(head2, 55);
insert(head2, 85);
print(head2); printf("NULL\n");

printf("number of nodes in the tree is %d\n", count(head1));
printf("Max depth of the tree is %d\n", depth(head1));
printf("comparison for both the tree is \"%s\"\n",
compare(head1, head2)?"true":"false");

return 0;
}
-----------------------------------------

Reference:
http://cslibrary.stanford.edu/110/BinaryTrees.html

parity in C

int oparity(int val)
{
int parity = 0;

while(val)
{
parity = !parity;
val &= val-1;
//val = val&(val-1);
//val &= ~(val&-val);
//val ^= val&(~val+1);
}

return parity;
}

int oparity(int val)
{
int nbit = 0;

while(val)
{
if(val&1) nbit++;
val >>= 1;
}

return nbit%2;
}

-----------------oddparity.c-----------------
#include <stdio.h>

int oparity(int val)
{
int nbit = 0;

while(val)
{
if(val&1) nbit++;
val >>= 1;
}

return nbit%2;
}

int main()
{
int val = 0xaF19;

printf("oddparity of 0x%X is %d\n", val, oparity(val));
printf("evenparity of 0x%X is %d\n", val, oparity(val)?0:1);

return 0;
}
---------------------------------------------

Reference:
http://resnet.uoregon.edu/~gurney_j/jmpc/bitwise.html

pyramid in C

-----------------------pyramid1.c-----------------------
#include <stdio.h>
#include <stdlib.h>

int main(int argc, char*argv[])
{
int i, j, level;
char ch = '*';

if(argc < 2)
{
printf("usage: %s <level> <<character>>\n", argv[0]);
exit(0);
}
level = atoi(argv[1]);
if(argv[2]) ch = argv[2][0];

for(i=0; i<level; i++)
{
for(j=i; j<level-1; j++)
printf(" ");

for(j=0; j<2*i+1; j++)
printf("%c ", ch);

printf("\n");
}


return 0;
}
--------------------------------------------------------

-----------------------pyramid2.c-----------------------
#include <stdio.h>
#include <stdlib.h>

int main(int argc, char*argv[])
{
int i, j, level;
char ch = '*';

if(argc < 2)
{
printf("usage: %s <level> <<character>>\n", argv[0]);
exit(0);
}
level = atoi(argv[1]);
if(argv[2]) ch = argv[2][0];

for(i=0; i<level; i++)
{
for(j=0; j<2*level-1; j++)
printf("%c ", (abs(level-1-j)<=i)?ch:' ');

printf("\n");
}


return 0;
}
--------------------------------------------------------

factorial in C

int fact(int num)
{
if(num<=0) return 1;

return num * fact(num-1);
}


---------------------factorial.c---------------------
#include <stdio.h>
#include <stdlib.h>

int fact(int num)
{
if(num<=0) return 1;

return num * fact(num-1);
}

int main(int argc, char *argv[])
{
int num = 0;

if(argc < 2)
{
printf("usage: %s <number>\n", argv[0]);
exit(0);
}

num = atoi(argv[1]);

printf("factorial of %d is %d\n", num, fact(num));
return 0;
}
-----------------------------------------------------

yum

yum install createrepo
mkdir -p /mnt/iso
mount /dev/cdrom /mnt/iso
cd /mnt
createrepo .
cd /etc/yum.repos.d/
edit all repo files and make enabled=0
-------------------iso.repo-------------------
[localrepo]
name=My Repo
baseurl=file:///mnt/iso/
enabled=1
gpgcheck=0
----------------------------------------------

yum repolist
yum --disablerepo=updates install gcc*
yum --disablerepo=updates install xorg*

Traceback (most recent call last):
File "/usr/bin/yum", line 29, in
yummain.main(sys.argv[1:])
File "/usr/share/yum-cli/yummain.py", line 172, in main
base.doTransaction()
File "/usr/share/yum-cli/cli.py", line 302, in doTransaction
problems = self.downloadPkgs(downloadpkgs)
File "/usr/lib/python2.5/site-packages/yum/__init__.py", line 798, in downloadPkgs
remote_pkgs.sort(mediasort)
File "/usr/lib/python2.5/site-packages/yum/__init__.py", line 747, in mediasort
a = a.getDiscNum()
File "/usr/lib/python2.5/site-packages/yum/packages.py", line 485, in getDiscNum
return int(fragid)

ValueError: invalid literal for int() with base 10: ''

-----------------------------------------------
vi /usr/lib/python2.5/site-packages/yum/packages.py +485
return int(fragid) ==> return int()
-----------------------------------------------

Happy yumming...

Reference:
http://fedora-help.blogspot.com/2009/07/install-from-dvd-using-yum-installer.html

06 September 2009

Two New Technologies to check out!!!

1. One technology involves enabling users to gain instant access to a laptop's e-mail, browser and other basic functionality -- without booting Windows at all.
2. The second technology enables an Internet-based message to wake a Windows PC from sleep mode.

Dell Latitude On
Dell announced this week a new feature called Latitude On that enables the use of e-mail, Web surfing, basic personal information manager functionality and document reading -- all without booting Windows. The Latitude On feature uses a low-power Intel ARM processor, flash storage and Linux (SUSE Linux Enterprise Desktop 10) separate from the laptop's main CPU, hard drive and Windows operating system. If you use only Latitude On, battery life lasts not hours but days, according to Dell.

Intel Remote Wake
Intel introduced new technology yesterday called Remote Wake, a chip set and software development kit that enables a PC to be "awakened" over the Internet when in sleep mode. This will enable you to dump your land-line phone and use a PC-based VoIP phone without leaving your PC on all the time.

Reference:
http://www.computerworld.com/s/article/9112732/Elgan_While_Windows_sleeps

03 September 2009

Cross Site scripting

Setup the WampServer as explained here
------------------test.php------------------
<?php echo "Welcome to our site " . stripslashes($name); ?>
--------------------------------------------
-> http://localhost/test.php?name=John
-> http://localhost/test.php?name=<script language=javascript>alert('Hey, you are going to be hijacked!');</script>"
-> http://localhost/test.php?name=<script language=javascript>setInterval("window.open('http://www.google.com','innerName')",1000);</script>
--------------------------------------------

------------------test1.php------------------
<?php
function validateQueryString ( $queryString , $min=1, $max=32 ) {
if ( !preg_match( "/^[a-zA-Z0-9]{".$min.",".$max."}$/", $queryString ) ) {
return false;
}
return true;
}

if ( !validateQueryString ( $name ) ) {
echo "The cross site scripting is not allowed.";
}
else {
echo "Welcome to our site " . stripslashes($name);
}
?>
--------------------------------------------
-> http://localhost/test2.php?name=John
-> http://localhost/test1.php?name=<script language=javascript>alert('Hey, you are going to be hijacked!');</script>
--------------------------------------------

Reference:
Acunetix Web Vulnerability Scanner
Paros - for web application security assessment
Rational AppScan Standard Edition V7.8
A Quick Look at Cross Site Scripting

21 August 2009

Secure Network Access

NAC stands for Network Access Control.
802.1X is the IEEE standard for port-based network access control.

NAC provides Endpoint security. The end point device can be a Laptop connected to a corporate network or a VPN client.
Depending on the security policy NAC will do user authentication, periodic health checks and policy enforcement.

-> User authentication can be by portal login, 802.1x etc.
-> Health check is done by a custom made Java applet, which runs on client, collect useful device information. Microsoft’s built-in NAP client also does the same job.
-> Policy enforcement, the most important part in a NAC, is done by SSCP, SSCPLite (Nortel proprietary), 802.1x etc.

=> NAC creates database with the information forwarded by NAC client. The policy decision is made based on corporate policy and database information. NAC server is also known as Policy Decision Point.

=> Policy enforcement point can be Switch, router, VPN gateway or firewall. Most commonly used access control techniques are VLAN segregation and packet filtering ACLs.

Future of NAC:
Some NAC policy servers are:
1. Cisco's Access Control Server (ACS)
2. Juniper's Unified Access Controller (UAC)
3. Microsoft's Network Policy Server (NPS)
4. Nortel's Secure Network Access (NSNA)
5. Trusted Computing Group's Trusted Network Connect (TNC)

IF-MAP is a standard client/server, XML-based SOAP, protocol for accessing a Metadata Access Point. The IF-MAP server has a database for storing information about network security events and objects (users, devices, etc.). The IF-MAP protocol defines a powerful publish/subscribe/search mechanism and an extensible set of identifiers, and data types.





=> Integrity measurements are carried between the TNC Client and TNC Server on a protocol called IF-TNCCS (Trusted Network Connect Client-Server).
=> For communication with NAP Client and NAP Server Microsoft used protocol called System of Health (SoH). Later donated to TCG as IF-TNCCS-SOH.

=> Consolidated IF-TNCCS enables Client-Server interoperability between NAP and TNC.
=> industry has agreed on TNC standard for NAC, except Cisco.

Reference:
White Paper - 1
http://features.techworld.com/networking/4073/microsoft-gets-nac-act-together
http://www.isp-planet.com/technology/2007/nac_3c.html
http://www.trustedcomputinggroup.org/developers/trusted_network_connect

802.1x

PPP is a data link protocol commonly used to establish a direct connection between two networking nodes.
PPP can provide connection authentication, transmission encryption privacy, and compression.

PPP -> alone provides username/password authentication (CHAP, PAP)
PPP + EAP -> Any type of authentication (EAP-MD5, PEAP)
PPP + EAP + RAS -> works fine
PPP + EAP + RAS + AAA -> RADIUS protocol takes care of the authentication
EAPOL + RAS + AAA -> 802.1x


L2TP and Microsoft’s secure RAS made PPP popular.
EAP is a universal authentication framework.
EAPOL is a standard for passing EAP over LAN.


802.1x is an IEEE standard for Port-Based Network Access Control.
802.1x works at Layer 2 to authentication and authorize devices on LAN switches and wireless APs.
It won’t work with multiple PC's connecting to a switch via a hub.

-> The user/client that wants to be authenticated is called a supplicant.
-> The actual server doing the authentication, typically a RADIUS server, is called the authentication server.
-> And the device in between, such as a wireless access point, is called the authenticator.



Benefits of IEEE 802.1X
1. Leverages existing standards EAP and RADIUS
2. Authentication based on Network Access Identifier and credentials
3. Centralized authentication, authorization, and accounting
4. Scalable through EAP types
5. Supports password authentication and One-Time Passwords (OTP)

Configure Freeradius:
/etc/raddb/clients.conf -> "client localhost { secret = testing }"
/etc/raddb/users -> "user1 User-Password := "pass1""
/sbin/radiusd -X
/bin/radtest user1 pass1 localhost 0 testing


Configure Switch (Nortel ERS 4550):
vlan members remove 1 1-11
vlan members add 16 1-11
vlan ports 12 tagging enable

radius-server host 192.168.10.254
radius-server key "testing"
radius-server port 1812

eapol enable
##EAPOL Administrative Status #> ENABLE
##EAPOL Administrative Status for ports #> Auto


Configure PC:
enable the following windows services:
-> Extensible Authentication Protocol Service
-> Wired AutoConfig / Wireless Zero Configuration

Local Area Connection properties -> Authentication -> Enable IEEE 802.1x authentication
Local Area Connection properties -> Authentication -> network auth method -> Protected EAP
Local Area Connection properties -> Authentication -> settings -> Authentication method -> EAP-MSCHAP v2



Reference:
http://www.javvin.com/protocol8021X.html
http://www.netcraftsmen.net/welcher/papers/dot1x.html
http://www.ipv6.com/articles/wireless/8021x-Wireless.htm
http://www.zyxeltech.de/SNotep335wt/app/8021x.htm
http://en.opensuse.org/RadiusServerHOWTO
http://www.ibm.com/developerworks/library/l-radius/

20 August 2009

Brain Teaser

Try to get 56 in all the blue boxes, using the pull-down lists!


= = = = = =
= =
= =
= =
= =
= = = = = =

18 August 2009

a SOAP message using SAAJ

--> doGoogleSearch WebService with JAVA

----------------------Client.java----------------------
import javax.xml.soap.SOAPConnectionFactory;
import javax.xml.soap.SOAPConnection;
import javax.xml.soap.MessageFactory;
import javax.xml.soap.SOAPMessage;
import javax.xml.soap.SOAPPart;
import javax.xml.soap.SOAPEnvelope;
import javax.xml.soap.SOAPBody;
import javax.xml.soap.SOAPElement;
import javax.xml.soap.MimeHeaders;

import javax.xml.transform.TransformerFactory;
import javax.xml.transform.Transformer;
import javax.xml.transform.Source;

import javax.xml.transform.stream.StreamResult;

public class Client {

public static void main(String[] args) {

try {
// Create the connection
SOAPConnectionFactory scf = SOAPConnectionFactory.newInstance();
SOAPConnection conn = scf.createConnection();

// Create message
MessageFactory mf = MessageFactory.newInstance();
SOAPMessage msg = mf.createMessage();

// Add eventually a SoapAction header if necessary
MimeHeaders hd = msg.getMimeHeaders();
hd.addHeader("SOAPAction", "\"urn:GoogleSearchAction\"");

// Object for message parts
SOAPPart sp = msg.getSOAPPart();

SOAPEnvelope env = sp.getEnvelope();
env.addNamespaceDeclaration("xsd","http://www.w3.org/2001/XMLSchema");
env.addNamespaceDeclaration("xsi","http://www.w3.org/2001/XMLSchema-instance");
env.addNamespaceDeclaration("enc","http://schemas.xmlsoap.org/soap/encoding/");
env.addNamespaceDeclaration("env","http://schemas.xmlsoap.org/soap/envelop/");
env.setEncodingStyle("http://schemas.xmlsoap.org/soap/encoding/");

SOAPBody bd = env.getBody();

// Populate body
// Main element and namespace
SOAPElement be = bd.addChildElement(env.createName("doGoogleSearch",
"namesp1",
"urn:GoogleSearch"));
be.addChildElement("key").addTextNode("OS7mOjxQFHIztxIYU9yb8y3ibYgY4w2o").setAttribute("xsi:type","xsd:string");
be.addChildElement("q").addTextNode("ls").setAttribute("xsi:type","xsd:string");
be.addChildElement("start").addTextNode("0").setAttribute("xsi:type","xsd:int");
be.addChildElement("maxResults").addTextNode("5").setAttribute("xsi:type","xsd:int");
be.addChildElement("filter").addTextNode("0").setAttribute("xsi:type","xsd:boolean");
be.addChildElement("restrict").setAttribute("xsi:type","xsd:string");
be.addChildElement("safeSearch").addTextNode("0").setAttribute("xsi:type","xsd:boolean");
be.addChildElement("lr").setAttribute("xsi:type","xsd:string");
be.addChildElement("ie").addTextNode("latin1").setAttribute("xsi:type","xsd:string");
be.addChildElement("oe").addTextNode("latin1").setAttribute("xsi:type","xsd:string");

// Save message
msg.saveChanges();

// View input
System.out.println("\n Soap request:\n");
msg.writeTo(System.out);
System.out.println();

// Send
String urlval = "http://api.google.com/search/beta2";
SOAPMessage rp = conn.call(msg, urlval);

// View the output
System.out.println("\nXML response\n");

// Create transformer
TransformerFactory tff = TransformerFactory.newInstance();
Transformer tf = tff.newTransformer();

// Get reply content
Source sc = rp.getSOAPPart().getContent();

// Set output transformation
StreamResult result = new StreamResult(System.out);
tf.transform(sc, result);
System.out.println();

// Close connection
conn.close();

}
catch (Exception e){
System.out.println(e.getMessage());
}
}
}
-------------------------------------------------------

1. get the latest java sdk (1.6.0_16)
2. javac Client.java
3. java Client

Reference:
http://www.pascalbotte.be
http://users.skynet.be/pascalbotte/rcx-ws-doc/present.htm
http://users.skynet.be/pascalbotte/rcx-ws-doc/saajpost.htm

17 August 2009

GoogleSearch with SOAP - perl

------------------google.pl------------------
#!/usr/bin/perl

use SOAP::Lite;
use strict;
use warnings;

@ARGV == 2 or die "Usage: google <query> <number of results 1-10>\n";

my $key='OS7mOjxQFHIztxIYU9yb8y3ibYgY4w2o';

my($query, $maxResults) = @ARGV;

my @params = ($key, $query, 0, $maxResults, 0, '', 0, '', 'latin1', 'latin1');

my $result = SOAP::Lite->service("http://api.google.com/GoogleSearch.wsdl")->doGoogleSearch(@params);

print "Result: \n";

print join "\n", map( { qq{$_->{URL}} } @{$result->{resultElements}} ), "";
---------------------------------------------

1. Download SOAP for Perl from here.
2. tar xzvf SOAP-Lite-0.60a.tar.gz
3. cd SOAP-Lite-0.60/lib
4. chmod 755 google.pl
5. ./google.pl ls 10

Reference:
perl-google-soap-example
http://search.cpan.org/~byrne/SOAP-Lite/lib/SOAP/Lite

16 August 2009

Learn to speak chess

You can learn speek chess from here.

Download Filemate tool from here.

1. File >> New Game
2. Options >> Setup Position...
3. clear, and start adding blank and white coins

This will be the best game to start with
1. e4 e5
2. Nf3 d6
3. d4 Bg4
4. dxe5 Bxf3
5. Qxf3 dxe5
6. Bc4 Nf6
7. Qb3 Qe7
8. Nc3 c6
9. Bg5 b5
10. Nxb5 cxb5
11. Bxb5+ Nbd7
12. O-O-O Rd8
13. Rxd7 Rxd7
14. Rd1 Qe6
15. Bxd7+ Nxd7
16. Qb8+!! Nxb8
17. Rd8#

enjoy!!!

Reference:
http://www.enpassant.dk/chess/softeng.htm

Enable call option in Yahoo! Messensger

Y!M supports PC to PC calling option.

It is supported in Yahoo! Messenger USA and it is not supported in Yahoo! Messenger India.

Upgrade to latest Y!M USA version :-)
Enjoy!!!

Reference:
http://in.answers.yahoo.com/question/index?qid=20090814230433AAUOAnF

14 August 2009

How to add category in the blog

Please refer this link.

1. Layout >> Page Element >> Add a Gadget >> Labels (Show all the labels of posts in your blog).

2. Layout >> Edit HTML >> Add "Label Cloud User Variables", "Label Cloud Styles" and "Widget Label code" at the specified location.

3. Add "Lables for this post" for at least one post.

Happy Blogging...
Enjoy!!!!

Reference:
http://phy3blog.googlepages.com/Beta-Blogger-Label-Cloud.html
http://ialja.blogspot.com/2007/04/view-blogger-labels-in-label-cloud.html

05 August 2009

openssl and certificates

Download the latest openssl source from here (0.9.8k).

1.3.6.1.4.1.311.20.2.2 - Smart Card Logon
1.3.6.1.4.1.311.20.2.3 - UPN (User Principal Name)

Certificate extentions:
.pem - (Privacy Enhanced Mail) Base64 encoded DER certificate, 
enclosed between "-----BEGIN CERTIFICATE-----"
and "-----END CERTIFICATE-----"

.cer, .crt, .der - usually in binary DER form,
but Base64-encoded certificates are common too

.p7b, .p7c - PKCS#7 SignedData structure without data,
just certificate(s) or CRL(s)

.p12 - PKCS#12, may contain certificate(s) (public)
and private keys
(password protected)
(Personnal Information Exchange)
Generate CA key and Certificate:
openssl genrsa -out ca.key 1024

openssl req -new -x509 -days 365 \
-subj '/C=IN/ST=KA/L=BL/O=Nortel/OU=Eng/CN=localhost ca' \
-key ca.key -out ca.crt
Generate server key and certificate:
openssl genrsa -out server.key 1024

openssl req -new \
-subj '/C=IN/ST=KA/L=BL/O=Nortel/OU=Eng/CN=localhost' \
-key server.key -out server.csr

cat > server.cnf << EOF
[dir_sect]
keyUsage=digitalSignature,keyEncipherment
subjectKeyIdentifier=hash
authorityKeyIdentifier=keyid,issuer
subjectAltName=otherName:1.3.6.1.4.1.311.20.2.3;UTF8:humble@yahoo.com
EOF

openssl x509 -req -days 365 -in server.csr \
-CA ca.crt -CAkey ca.key \
-extfile server.cnf -extensions dir_sect -set_serial 01 -out server.crt
Verify and show the server generated certificate:
# openssl pkcs12 -export -out server.p12 -inkey server.key -in server.crt
# openssl req -in server.csr -noout -verify -key server.key
# openssl x509 -noout -text -in server.crt
Certificate:
Data:
Version: 3 (0x2)
Serial Number: 1 (0x1)
Signature Algorithm: sha1WithRSAEncryption
Issuer: C=IN, ST=KA, L=BL, O=Nortel, OU=Eng, CN=localhost ca
Validity
Not Before: Jul 27 09:23:44 2010 GMT
Not After : Jul 27 09:23:44 2011 GMT
Subject: C=IN, ST=KA, L=BL, O=Nortel, OU=Eng, CN=localhost
Subject Public Key Info:
Public Key Algorithm: rsaEncryption
RSA Public Key: (1024 bit)
Modulus (1024 bit):
00:d3:d4:a6:31:55:20:94:38:a8:72:16:eb:b8:2a:
9a:7c:07:98:36:63:7c:3c:f7:ad:ff:ad:27:4b:9b:
38:85:92:e5:44:07:12:1e:e3:b7:e9:09:d2:67:01:
71:51:50:fc:a7:7f:ec:72:2c:30:f4:24:0b:68:fa:
c4:7e:56:7b:70:dd:c4:50:7a:8c:51:d5:7f:46:a1:
02:7f:76:d8:6f:2c:79:48:57:9b:6f:fa:06:2d:dd:
5c:e6:f0:74:57:0a:85:85:39:a0:ce:36:64:2a:b1:
7b:1e:26:aa:df:c5:8f:93:6b:e6:02:cb:8d:f8:44:
89:37:58:31:cd:83:68:3a:87
Exponent: 65537 (0x10001)
X509v3 extensions:
X509v3 Key Usage:
Digital Signature, Key Encipherment
X509v3 Subject Key Identifier:
CF:36:42:69:6D:85:D4:D6:22:F8:6F:45:DD:EC:74:...
X509v3 Authority Key Identifier:
keyid:55:B0:22:DC:4F:4C:21:AA:69:EA:47:31:A2:...

X509v3 Subject Alternative Name:
othername:
Signature Algorithm: sha1WithRSAEncryption
de:ff:04:5c:82:e5:74:3c:75:d0:80:21:c7:5b:74:21:91:5b:
07:cb:5a:9e:6d:46:ae:5d:1d:69:26:5a:44:ec:b5:ad:25:72:
a5:5d:f1:e9:b5:45:14:2c:98:b6:40:5f:b8:e8:92:ba:a5:0c:
34:86:0e:20:51:25:64:6a:f7:cf:33:ec:50:f8:eb:9f:59:de:
99:b5:c1:75:cd:d2:ff:00:c0:ed:b2:30:44:f2:1e:13:75:dd:
21:da:f7:7f:bd:3c:60:7a:f6:66:44:c1:c9:b4:b6:75:ac:59:
07:c3:e5:06:eb:97:b2:64:0c:f2:2c:2c:39:b1:35:a6:19:b6:
a6:50

The certificate "server.crt" in windows:


Reference:
make-certs.sh
http://www.madboa.com/geek/openssl
http://en.wikipedia.org/wiki/X.509

30 July 2009

Setting up SSL and Apache

Setup the WampServer as explained here

------------------Generate your own CA------------------
1. Generate a ca key:
openssl genrsa -des3 -out ca.key 1024

2. Generate a ca certificate:
openssl req -new -x509 -days 365 -key ca.key -out ca.crt
subject=/C=IN/ST=Karnataka/L=Bangalore/O=Nortel/OU=Engineering/CN=localhostca

3. Generate a server key:
openssl genrsa -des3 -out server.key 1024

4. Create a certificate signing request:
openssl req -new -key server.key -out server.csr
subject=/C=IN/ST=Karnataka/L=Bangalore/O=Nortel/OU=Engineering/CN=localhost

5. Sign the certificate signing request:
openssl x509 -req -days 365 -in server.csr -CA ca.crt -CAkey ca.key -set_serial 01 -out server.crt

6. Create an insecure version of the server.key:
openssl rsa -in server.key -out server.key.insecure
mv server.key.insecure server.key

openssl req -noout -text -in server.csr
openssl x509 -noout -text -in server.crt

server.crt: The self-signed server certificate.
server.key: The private server key.
ca.crt: The Certificate Authority's own certificate.
--------------------------------------------------------

1. Update "C:\Program Files\wamp\bin\apache\Apache2.2.11\conf\httpd.conf"
-> LoadModule ssl_module modules/mod_ssl.so
-> Include conf/extra/httpd-ssl.conf
2. Update "C:\Program Files\wamp\bin\apache\Apache2.2.11\conf\extra\httpd-ssl.conf"
-> #DocumentRoot "C:/Program Files/Apache Software Foundation/Apache2.2/htdocs"
-> SSLCertificateFile "C:/Program Files/Apache Software Foundation/Apache2.2/conf/server.crt"
-> SSLCertificateKeyFile "C:/Program Files/Apache Software Foundation/Apache2.2/conf/server.key"
3. Copy server.crt and server.key to "C:\Program Files\Apache Software Foundation\Apache2.2\conf"
4. Restart Apache server
5. Copy ca.crt to:
-> Mozilla Tools >> Options >> Advanced >> Encryption >> Veiw Certificates >> Authorities
-> IE Tools >> Internet Options >> Content >> Certificates >> Trusted Root Certification Authorities

If https://localhost is not working then refer the logs at "C:\Program Files\Apache Software Foundation\Apache2.2\logs"

Reference:
http://middleware.its.state.nc.us/middleware/Documentation/en_US/htm/csqzas00/csqzas000p.htm
http://progtutorials.tripod.com/SSL.htm
http://www.tc.umn.edu/~brams006/selfsign.html
http://www.tc.umn.edu/~brams006/selfsign_redhat.html
http://articles.techrepublic.com.com/2415-3513_11-167032.html

Eclipse - quick start

1. Download the latest Java SE Development Kit (JDK) from here (JDK 6 Update 14).
2. Download the latest Eclipse IDE for Java EE Developers from here.

How to create a sample Java Project in Eclipse:
1. File -> New -> Java Project
2. Give project name, Use default JRE
3. Navigate -> Show In -> Package Explorer
4. Right click on project src, New -> Class
5. Give Name, Modifier, Create stubs and Comments
6. Run and Debug the code at Run menu
----------------------test.java----------------------
public class test {

public static void main(String[] args) {
System.out.println("Hello world!!!\n");
}

}
-----------------------------------------------------



Reference:
http://java.sun.com/javase/technologies/index.jsp

24 July 2009

Embedding Applets in a Web page - 3

Setup the WampServer as explained here
-----------------TestApplet3.java-----------------------
import javax.swing.*;

public class TestApplet3 extends JApplet {
public void init() {
add (new JLabel("Hello World", JLabel.CENTER));
}
}
--------------------------------------------------------
-----------------------test3.html-----------------------
<HTML>
<HEAD>
<TITLE>My new applet page</TITLE>
</HEAD>
<BODY>
<OBJECT
classid="clsid:8AD9C840-044E-11D1-B3E9-00805F499D93"
WIDTH="170"
HEIGHT="70"
codebase="http://java.sun.com/products/plugin/autodl/jinstall-1_4_2_05-windows-i586.cab#Version=1,4,2,5">
<PARAM NAME=CODE VALUE="TestApplet3">
<PARAM NAME=CACHE_OPTION VALUE="plugin">
<PARAM NAME=CACHE_ARCHIVE VALUE="TestApplet3.jar">

<COMMENT>
<EMBED
TYPE="application/x-java-applet;version=1.4.2"
CODE="TestApplet3"
CACHE_OPTION="plugin"
CACHE_ARCHIVE="TestApplet3.jar"
WIDTH="170"
HEIGHT="70">
</EMBED>
</COMMENT>
</OBJECT>
</BODY>
-------------------------------------------------------
----------------------mymanifest-----------------------
Manifest-Version: 1.2
Main-Class: TestApplet3
Created-By: 1.4 (Sun Microsystems Inc.)
-------------------------------------------------------

-------------------------------------------------------
1. Save TestApplet2.java, test2.html and mymanifest inside the website's home page
2. Make sure JRE is installed in the machine.
3. javac TestApplet3.java
4. jar cvfm TestApplet3.jar mymanifest TestApplet3.class
5. del TestApplet3.class
6. http://localhost/test3.html
7. appletviewer -classic test2.html
8. java -jar TestApplet3.jar
-------------------------------------------------------

Reference:
How to make a JAVA application - executable JAR archive:

Embedding Applets in a Web page - 2

Setup the WampServer as explained here
-----------------TestApplet2.java-----------------
import javax.swing.*;
public class TestApplet2 extends JApplet {
public void init() {
add (new JLabel("Hello World", JLabel.CENTER));
}
}
-------------------------------------------------------
-----------------------test2.html-----------------------
<OBJECT
classid="clsid:8AD9C840-044E-11D1-B3E9-00805F499D93"
WIDTH="170"
HEIGHT="70"
codebase="http://java.sun.com/products/plugin/autodl/jinstall-1_4_2_05-windows-i586.cab#Version=1,4,2,5">
<PARAM NAME=CODE VALUE="TestApplet2.class">
<PARAM NAME=CACHE_OPTION VALUE="plugin">
<PARAM NAME=CACHE_ARCHIVE VALUE="TestApplet2.class">

<COMMENT>
<EMBED
TYPE="application/x-java-applet;version=1.4.2"
CODE="TestApplet2.class"
CACHE_OPTION="plugin"
CACHE_ARCHIVE="TestApplet2.class"
WIDTH="170"
HEIGHT="70">
</EMBED>
</COMMENT>
</OBJECT>
-------------------------------------------------------

-------------------------------------------------------
1. Save TestApplet2.java and test2.html inside the website's home page
2. Make sure JRE is installed in the machine.
3. javac TestApplet2.java
4. http://localhost/test2.html
5. appletviewer -classic test2.html
-------------------------------------------------------

Reference:
Embedding Applets in a Web page

Embedding Applets in a Web page - 1

Setup the WampServer as explained here
-----------------HelloWorldApplet.java-----------------
import java.applet.Applet;
import java.awt.*;
import java.awt.event.*;

public class HelloWorldApplet extends Applet{
public static void main(String[] args){
Frame frame = new Frame("Roseindia.net");
frame.setSize(400,200);
Applet app = new HelloWorldApplet();
frame.add(app);
frame.setVisible(true);
frame.addWindowListener(new WindowAdapter(){
public void windowClosing(WindowEvent e){
System.exit(0);
}
});
}
public void paint(Graphics g){
g.drawString("Hello World!",200,100);
}
}
-------------------------------------------------------
-----------------------test.html-----------------------
<html>
<head>
<title>A Simple Applet program</title>
</head>
<body>
<APPLET CODE="HelloWorldApplet.class" WIDTH=700 HEIGHT=500>
</APPLET>
</body>
</html>
-------------------------------------------------------


-------------------------------------------------------
1. Save HelloWorldApplet.java and test.html inside the website's home page
2. Make sure JRE is installed in the machine.
3. javac HelloWorldApplet.java
4. http://localhost/test.html
5. appletviewer -classic test.html
-------------------------------------------------------

Reference:

19 July 2009

VMware and Fedora Core 7

VMware Server - The free VMware Server is a hosted virtualization platform that installs like an application on any existing server hardware and partitions a physical server into multiple virtual machines.
VMware ESXi - The free VMware ESXi doesn't require and Host operating system, the avoidance of host os provides nmatched levels of performance and reliability.

Download Vmware Server 2.0.1 from here.
Download Vmware Server 1.0.9 from here.

--------How to install VMware Server (2.0.1) on windows host machine--------
1. Download VMware Server 2.0.1 from here.
2. Download Fedora Core 7 here.
3. Start the VMware, login with local username and password without domain.
4. Virtual Machine >> Create Virtual Machine
-> Name: FC7
-> Operating System: Linux Operating System
-> Memory Size: Recommended Size
-> Create a New Virtual Disk (10GB+)
-> Add a Network Adapter >> Network Connection: Bridged
-> DVD Drive: use ISO Image
-> Don't add a Floppy Drive
-> Don't add a USB controller
5. Power ON and install Fedora Core 11
6. Summary >> Status >> VMware Tools >> Install VMware Tools
7. su; cp /media/VMware Tools/VMwareTools-7.7.5-156745.tar.gz /root
8. tar xzvf VMwareTools-7.7.5-156745.tar.gz; cd vmware-tools-distrib
9. ./vmware-install.pl
ERROR!!!!!
10. Get vmware-tools patch for linux 2.6.29 from here.
12. Combine the patch files and apply
-> cd vmware-tools-distrib/lib/modules
-> cp -r source source-backup; cd source
-> tar xzvf vmwaretools-7.7.5_156745_for_2.6.29.tgz
-> ls *.tar | xargs -n1 tar xvf
-> sed -i 's/--- /--- original\//g' *.patch
-> sed -i 's/+++ /+++ work\//g' *.patch
-> ls *.patch | xargs cat > all
-> mv all all.patch
-> patch -p1 < all.patch
13. ./vmware-install.pl
STILL ERROR!!!!!!
----------------------------------------------------------------------------

Reference:
http://www.vmware.com/products/product_index.html
http://download3.vmware.com/demos/esxi/VMware_ESXi.html

18 July 2009

pcidump.c

#include <stdio.h>
#include <string.h>
#include <fcntl.h>
#include <errno.h>
#include <stdlib.h>

#include <linux/pci.h>
#include <asm/page.h>

/* A structure to declare how data is decoded */
struct pcidump_info {
int offset; /* the data item to retrieve */
unsigned long bitmask;
int bool; /* true or false */
char *string;
};

#define ONEBYTE 0xFF
#define TWOBYTES 0xFFFF
#define FOURBYTES 0xFFFFFFFF

struct pcidump_info dumpinfo[] = {
{0, 0, 0, "\tCompulsory registers:\n"},
{PCI_VENDOR_ID, TWOBYTES, 0, "Vendor id: 0x%04x\n"},
{PCI_DEVICE_ID, TWOBYTES, 0, "Device id: 0x%04x\n"},
{PCI_COMMAND, TWOBYTES, 0, "Command Register: 0x%04x\n"},
{PCI_STATUS, TWOBYTES, 0, "Status Register: 0x%04x\n"},
{PCI_REVISION_ID, ONEBYTE, 0, "Revision id (decimal): %i\n"},
{PCI_CLASS_PROG, ONEBYTE, 0, "Programmer Interface: 0x%02x\n"},
{PCI_CLASS_DEVICE, TWOBYTES, 0, "Class of device: 0x%04x\n"},
{PCI_HEADER_TYPE, 0x7f, 0, "Header type: 0x%02x\n"},
{PCI_HEADER_TYPE, 0x80, 1, "Multi function device: %c\n"},
{0, 0, 0, "\tOptional registers:\n"},
{PCI_CACHE_LINE_SIZE, ONEBYTE, 0, "Cache line size (decimal): %i\n"},
{PCI_LATENCY_TIMER, ONEBYTE, 0, "Latency timer (decimal): %i\n"},
{PCI_BIST, ONEBYTE, 0, "Is Built-In-Self-Test available: %c\n"},
{PCI_BASE_ADDRESS_0, FOURBYTES, 0, "Base Address 0 (B0): 0x%08x\n"},
{PCI_BASE_ADDRESS_1, FOURBYTES, 0, "Base Address 1 (B1): 0x%08x\n"},
{PCI_BASE_ADDRESS_2, FOURBYTES, 0, "Base Address 2 (B2): 0x%08x\n"},
{PCI_BASE_ADDRESS_3, FOURBYTES, 0, "Base Address 3 (B3): 0x%08x\n"},
{PCI_BASE_ADDRESS_4, FOURBYTES, 0, "Base Address 4 (B4): 0x%08x\n"},
{PCI_BASE_ADDRESS_5, FOURBYTES, 0, "Base Address 5 (B5): 0x%08x\n"},
{PCI_SUBSYSTEM_ID, TWOBYTES, 0, "Subsystem id: 0x%04x\n"},
{PCI_SUBSYSTEM_VENDOR_ID, TWOBYTES,0, "Subsystem vendor: 0x%04x\n"},
{PCI_ROM_ADDRESS, FOURBYTES, 0, "Expantion Rom base address: 0x%08x\n"},
{PCI_INTERRUPT_LINE, ONEBYTE, 0, "Interrupt line (decimal): %i\n"},
{PCI_INTERRUPT_PIN, ONEBYTE, 0, "Interrupt pin (decimal): %i\n"},
{PCI_MIN_GNT, ONEBYTE, 0, "Min bus grant time (decimal): %i\n"},
{PCI_MAX_LAT, ONEBYTE, 0, "Max bus latency acceptable (decimal): %i\n"},
{0x00, 0, 0, NULL}
};

unsigned char buffer[PAGE_SIZE];

int main(int argc, char **argv)
{
int fd, len;
char file[] = "/proc/bus/pci/00/00.0";
char *fname = file;

unsigned char *curr, *end;

if (argc>1) {
fname = argv[1];
}
if (argc != 2) {
printf("Usage: \"%s <file name>\"\n", argv[0]);
printf("\tfilename should embed binary pci configuration data\n");
printf("\tif filename is missing, \"%s\" is used\n", fname);

exit(0);
}

fd=open(fname, O_RDONLY);
if (fd<0) {
fprintf(stderr,"%s: %s: %s\n", argv[0], fname, strerror(errno));
exit(1);
}

switch (len=read(fd,buffer,PAGE_SIZE)) {
case 0:
fprintf(stderr,"%s: %s: no data\n", argv[0], fname);
exit(1);
case -1:
fprintf(stderr,"%s: %s: %s\n", argv[0], fname, strerror(errno));
exit(1);
default: break;
}
if (len < 64) {
buffer[len]='\0';
fprintf(stderr," %s: %s: %s\n", argv[0], fname, buffer);
exit(1);
}
if (len % 64) {
fprintf(stderr," %s: %s: incorrect data size: %i\n",
argv[0], fname, len);
exit(1);
}

for (end = buffer+len, curr = buffer; curr < end; curr += 256) {
struct pcidump_info *ptr;
unsigned int datum;

for (ptr = dumpinfo; ptr->string; ptr++) {
/*
* Perform a little-endian read of the item
*/
datum = curr[ptr->offset]
| (curr[ptr->offset+1]<<8)
| (curr[ptr->offset+2]<<16)
| (curr[ptr->offset+3]<<24);
datum &= ptr->bitmask;
printf(ptr->string, ptr->bool ? (datum ? 'y' : 'n') : datum);
}
printf("\n");
}
return 0;
}
lspci
gcc -o pcidump pcidump.c
./pcidump /proc/bus/pci/00/12.0
Compulsory registers:
Vendor id: 0x1022
Device id: 0x2000
Command Register: 0x0003
Status Register: 0x0280
Revision id (decimal): 16
Programmer Interface: 0x00
Class of device: 0x0200
Header type: 0x00
Multi function device: n
Optional registers:
Cache line size (decimal): 0
Latency timer (decimal): 64
Is Built-In-Self-Test available:
Base Address 0 (B0): 0x00001401
Base Address 1 (B1): 0x00000000
Base Address 2 (B2): 0x00000000
Base Address 3 (B3): 0x00000000
Base Address 4 (B4): 0x00000000
Base Address 5 (B5): 0x00000000
Subsystem id: 0x2000
Subsystem vendor: 0x1022
Expantion Rom base address: 0x00000000
Interrupt line (decimal): 9
Interrupt pin (decimal): 1
Min bus grant time (decimal): 6
Max bus latency acceptable (decimal): 255


Reference:
pcidump.c