Wednesday, 8 June 2016

Find Intersect Node On Merged Linked List

Program to find intersect node in merged linked list


#include <stdio.h>
#include <stdlib.h>

struct node {
        int             data;
        int     visited:1;
        struct node *next;
};

void AppendToList (struct node **head, int value)
{
        struct node *newNode = NULL;

        newNode = (struct node *) malloc(sizeof(struct node));
        if (newNode == NULL)
                return;

        newNode->data = value;
        newNode->visited = 0;
        newNode->next = NULL;

        if (*head == NULL)
                        *head = newNode;
        else {
                newNode->next = *head;
                *head   = newNode;
        }

        return;
}

void PrintList (struct node **head)
{
        struct node *temp = *head;

        while (temp) {
                printf("%d\r\n", temp->data);
                temp = temp->next;
        }

        return;
}

void MergeTwoList (struct node **head1, struct node **head2)
{
        struct node *temp = *head1;
        struct node *merge = *head2;

        while (temp->next != NULL) {
                temp = temp->next;
        }
        temp->next = merge->next->next->next;

        return;
}


void FindIntersectNode (struct node **head1, struct node **head2, struct node **join)
{
        struct node *temp = *head1;

        while (temp->next != NULL) {
                temp->visited = 1;
                temp = temp->next;
        }

        temp = *head2;
        while (temp->next != NULL) {
                if (temp->visited) {
                                *join = temp;
                                return;
                }
                temp = temp->next;
        }

        return;
}

int main(void)
{
        int i;
        struct node *head1 = NULL, *head2 = NULL;
        struct node *join = NULL;

        for (i = 1; i <= 10; i++) {
                AppendToList(&head1, i);
        }

        for (i = 11; i <= 20; i++) {
                AppendToList(&head2, i);
        }

        MergeTwoList(&head1, &head2);

        printf("Merged Head1 List \r\n");
        PrintList(&head1);

        printf("Merged Head2 List \r\n");
        PrintList(&head2);

        FindIntersectNode(&head1, &head2, &join);

        printf("Joined Node %d \r\n", join->data);


        return 0;
}



CC = gcc

CFLAGS = -g -Wall

all: mergenode

mergenode: mergenode.o
        ${CC} ${CFLAGS} -o $@ mergenode.o

clean:
        -@rm *.o

distclean: clean
        -@rm    mergenode


Output: 


Merged Head1 List
10
9
8
7
6
5
4
3
2
1
17
16
15
14
13
12
11
Merged Head2 List
20
19
18
17
16
15
14
13
12
11
Joined Node 17

Tuesday, 16 February 2016

DNS Server Configuration named in RHEL

Pr-requisition install named

Very simple method just two steps to setup dns server for private LAN network.

Step-1:

File :   /etc/named.config

/
// named.conf for caching-nameserver
//

options {
        directory "/var/named";
        listen-on-v6 { any; };

        /*
         * If there is a firewall between you and nameservers you want
         * to talk to, you might need to uncomment the query-source
         * directive below.  Previous versions of BIND always asked
         * questions using port 53, but BIND 8.1 uses an unprivileged
         * port by default.
         */
        query-source address * port 53;
};


include "/etc/rndc.key";

zone "abc.com" {
        type master;
        notify no;
        file "acb.com.zone";
};




Step-2


vi /var/named/abc.com.zone

$TTL    86400
@               IN SOA  centos6.abc.com. root.abc.com. (
                                        42              ; serial (d. adams)
                                        3H              ; refresh
                                        15M             ; retry
                                        1W              ; expiry
                                        1D )            ; minimum
                IN NS           centos6
centos6         IN AAAA 2001:1::100
centos6         IN A    192.168.1.100


Keep Add your  IPv4 - A Record &  IPV6 AAAA record in the zone file.

Start named daemon

/etc/init.d/named start
root@localhost network-scripts]# /etc/init.d/named status
version: 9.8.2rc1-RedHat-9.8.2-0.37.rc1.el6_7.6
CPUs found: 1
worker threads: 1
number of zones: 17
debug level: 0
xfers running: 0
xfers deferred: 0
soa queries in progress: 0
query logging is OFF
recursive clients: 0/0/1000
tcp clients: 0/100
server is up and running
named-sdb (pid  5911) is running...


DNS Client : Host
---------------

Configure nameserver to resolve dns request .

/etc/resolve.conf

nameserver 192.168.1.100

ping centos6.abc.com




Sunday, 17 January 2016

Mount ISO and Install FTP Client & Server

If ftp server not running in your Linux Box.

If you have ISO image. mount to local machine.


[root@localhost ~]# mount -o loop /home/ssankar/rhel-server-6.0-i386-dvd.iso /mnt/
[root@localhost ~]# cd /mnt/
[root@localhost mnt]#
[root@localhost Packages]# pwd
/mnt/Packages

Install FTP Client
----------------


[root@localhost Packages]# rpm -ivh ftp-0.17-51.1.el6.i686.rpm
warning: ftp-0.17-51.1.el6.i686.rpm: Header V3 RSA/SHA256 Signature, key ID fd431d51: NOKEY
Preparing...                ########################################### [100%]
   1:ftp                    ########################################### [100%]
[root@localhost Packages]# ftp
ftp> quit
[root@localhost Packages]# ftp localhost
Trying 127.0.0.1...
Connected to localhost (127.0.0.1).
220 (vsFTPd 2.2.2)

Install FTP  Server
----------------

[root@localhost Packages]# rpm -ivh vsftpd-2.2.2-6.el6.i686.rpm
warning: vsftpd-2.2.2-6.el6.i686.rpm: Header V3 RSA/SHA256 Signature, key ID fd431d51: NOKEY
Preparing...                ########################################### [100%]
   1:vsftpd                 ########################################### [100%]
[root@localhost Packages]#
[root@localhost Packages]# service vsftpd status
vsftpd is stopped
[root@localhost Packages]# service vsftpd start
Starting vsftpd for vsftpd:                                [  OK  ]