SlideShare ist ein Scribd-Unternehmen logo
1 von 8
/* SERVER */



#include<stdio.h>

#include<sys/types.h>

#include<sys/socket.h>

#include<netinet/in.h>

#include<arpa/inet.h>

#include<stdlib.h>

#include<unistd.h>

#include<string.h>

#include<errno.h>



#define port 7564



int main()

{

    int sock,con,byte_rec,i=0;

    char send_data[1024],rec_data[1024];

    struct sockaddr_in ser,cli;

    int sin_size;

    char ip[5][20]={"127.0.0.1","127.0.0.2","127.0.0.3","127.0.0.4","127.0.0.5"};

    char mac[5][20]={"15.8.12.0.0.1","15.8.12.0.0.2","15.8.12.0.0.3","15.8.12.0.0.4","15.8.12.0.0.5"};



    //socket creation

    if((sock=socket(AF_INET,SOCK_STREAM,0))==-1)
{

    perror("Socketn");

    exit(1);

}



ser.sin_family=AF_INET;

ser.sin_port=htons(port);

ser.sin_addr.s_addr=INADDR_ANY;

bzero(&(ser.sin_zero),8);



//binding the socket

if(bind(sock,(struct sockaddr*)&ser,sizeof(struct sockaddr))==-1)

{

    perror("can't bindn");

    exit(1);

}



//listening to clients connection request

if(listen(sock,3)==-1)

{

    perror("listenn");

    exit(1);

}

printf("Waiting n");
sin_size=sizeof(struct sockaddr_in);

//accepting connection of client

con=accept(sock,(struct sockaddr*)&cli,&sin_size);

    printf("Connectedn");

while(1)

{

    //receiving data from client

    byte_rec=recv(con,rec_data,1024,0);

    rec_data[byte_rec]='0';

    if(strcmp(rec_data,"end")==0)

    {

           //closing socket

           close(con);

           close(sock);

           break;

    }

    else

           printf("Received IP address=%sn",rec_data);



    for(i=0;i<5;i++)

    {

           if(strcmp(ip[i],rec_data)==0)

           {

               strcpy(send_data,mac[i]);

               printf("Mac address %s sent to clientnn",mac[i]);
break;

                }

        }



        //sending data to client

        send(con,send_data,strlen(send_data),0);

    }

    return 0;

}



/*CLIENT*/



#include<stdio.h>

#include<sys/types.h>

#include<sys/socket.h>

#include<netinet/in.h>

#include<arpa/inet.h>

#include<stdlib.h>

#include<unistd.h>

#include<string.h>

#include<netdb.h>

#include<errno.h>



#define port 7564
int main()

{

    int i,sock,byte_rec;

    char send_data[1024],rec_data[1024];



char ip[5][20]={"127.0.0.1","127.0.0.2","127.0.0.3","127.0.0.4","127.0.0.5"};

    struct hostent *host;

    struct sockaddr_in ser,cli;

    host=gethostbyname("127.0.0.1");



    //socket creation

    if((sock=socket(AF_INET,SOCK_STREAM,0))==-1)

    {

         perror("Socketn");

         exit(1);

    }



    printf("socket createdn");

    ser.sin_family=AF_INET;

    ser.sin_port=htons(port);

    ser.sin_addr= *((struct in_addr *)host->h_addr);

    bzero(&(ser.sin_zero),8);



    //connecting to server

    if(connect(sock,(struct sockaddr*)&ser,sizeof(struct sockaddr))==-1)
{

    perror("connectn");

    exit(1);

}



while(1)




{

    //sending data to server

    printf("nEnter the IP address : ");

    scanf("%s",send_data);

loop1:

    for(i=0;i<5;i++)

    {

    if((strcmp(ip[i],send_data)==0)||(strcmp(send_data,"end")==0))

           goto loop2;

    }

    if(strcmp(ip[i],send_data)!=0)

    {

           printf("SORRY!! Enter a VALID IP ADDRESS");

           printf("nEnter the IP address:n");

           scanf("%s",send_data);

           goto loop1;

    }
loop2:

         if(strcmp(send_data,"end")!=0)

         {



                send(sock,send_data,strlen(send_data),0);

         }

         else

         {

                send(sock,send_data,strlen(send_data),0);

                //closing socket

                close(sock);

                break;

         }



         //receiving data from server

         byte_rec=recv(sock,rec_data,1024,0);

         rec_data[byte_rec]='0';

         printf("Received MAC address = %snn",rec_data);

    }

    return 0;

}

Output

[12mcs009@mepcolinux:~/networkslab]cat arpoutput.txt

[12mcs009@mepcolinux:~]vi arpserver.c
[12mcs009@mepcolinux:~]cc arpserver.c

[12mcs009@mepcolinux:~]./a.out

Waiting

Connected

Received IP address=127.0.0.5

Mac address 15.8.12.0.0.5 sent to client



[12mcs009@mepcolinux:~]vi arpclient.c

[12mcs009@mepcolinux:~]cc arpclient.c

[12mcs009@mepcolinux:~]./a.out

socket created



Enter the IP address : 127.0.0.5

Received MAC address = 15.8.12.0.0.5




[12mcs009@mepcolinux:~/networkslab]

Weitere ähnliche Inhalte

Was ist angesagt?

ZeroMQ Is The Answer
ZeroMQ Is The AnswerZeroMQ Is The Answer
ZeroMQ Is The AnswerIan Barber
 
ZeroMQ: Messaging Made Simple
ZeroMQ: Messaging Made SimpleZeroMQ: Messaging Made Simple
ZeroMQ: Messaging Made SimpleIan Barber
 
2016 gunma.web games-and-asm.js
2016 gunma.web games-and-asm.js2016 gunma.web games-and-asm.js
2016 gunma.web games-and-asm.jsNoritada Shimizu
 
Introduction to ES6 with Tommy Cresine
Introduction to ES6 with Tommy CresineIntroduction to ES6 with Tommy Cresine
Introduction to ES6 with Tommy CresineMovel
 
c++ program for Canteen management
c++ program for Canteen managementc++ program for Canteen management
c++ program for Canteen managementSwarup Kumar Boro
 
Full-Stack JavaScript with Node.js
Full-Stack JavaScript with Node.jsFull-Stack JavaScript with Node.js
Full-Stack JavaScript with Node.jsMichael Lehmann
 
"You shall not pass : anti-debug methodics"
"You shall not pass : anti-debug methodics""You shall not pass : anti-debug methodics"
"You shall not pass : anti-debug methodics"ITCP Community
 
Créer une base NoSQL en 1 heure
Créer une base NoSQL en 1 heureCréer une base NoSQL en 1 heure
Créer une base NoSQL en 1 heureAmaury Bouchard
 
Debugging: Rules And Tools - PHPTek 11 Version
Debugging: Rules And Tools - PHPTek 11 VersionDebugging: Rules And Tools - PHPTek 11 Version
Debugging: Rules And Tools - PHPTek 11 VersionIan Barber
 
PyCon KR 2019 sprint - RustPython by example
PyCon KR 2019 sprint  - RustPython by examplePyCon KR 2019 sprint  - RustPython by example
PyCon KR 2019 sprint - RustPython by exampleYunWon Jeong
 
Mozilla とブラウザゲーム
Mozilla とブラウザゲームMozilla とブラウザゲーム
Mozilla とブラウザゲームNoritada Shimizu
 
プログラム実行の話と
OSとメモリの挙動の話
プログラム実行の話と
OSとメモリの挙動の話プログラム実行の話と
OSとメモリの挙動の話
プログラム実行の話と
OSとメモリの挙動の話tatsunori ishikawa
 
Teaching Your Machine To Find Fraudsters
Teaching Your Machine To Find FraudstersTeaching Your Machine To Find Fraudsters
Teaching Your Machine To Find FraudstersIan Barber
 
Institute management
Institute managementInstitute management
Institute managementvarun arora
 
Debugging JavaScript with Chrome
Debugging JavaScript with ChromeDebugging JavaScript with Chrome
Debugging JavaScript with ChromeIgor Zalutsky
 

Was ist angesagt? (20)

Ee
EeEe
Ee
 
ZeroMQ Is The Answer
ZeroMQ Is The AnswerZeroMQ Is The Answer
ZeroMQ Is The Answer
 
Yg byev2e
Yg byev2eYg byev2e
Yg byev2e
 
ZeroMQ: Messaging Made Simple
ZeroMQ: Messaging Made SimpleZeroMQ: Messaging Made Simple
ZeroMQ: Messaging Made Simple
 
Php arduino
Php arduinoPhp arduino
Php arduino
 
20151224-games
20151224-games20151224-games
20151224-games
 
2016 gunma.web games-and-asm.js
2016 gunma.web games-and-asm.js2016 gunma.web games-and-asm.js
2016 gunma.web games-and-asm.js
 
Introduction to ES6 with Tommy Cresine
Introduction to ES6 with Tommy CresineIntroduction to ES6 with Tommy Cresine
Introduction to ES6 with Tommy Cresine
 
c++ program for Canteen management
c++ program for Canteen managementc++ program for Canteen management
c++ program for Canteen management
 
Full-Stack JavaScript with Node.js
Full-Stack JavaScript with Node.jsFull-Stack JavaScript with Node.js
Full-Stack JavaScript with Node.js
 
"You shall not pass : anti-debug methodics"
"You shall not pass : anti-debug methodics""You shall not pass : anti-debug methodics"
"You shall not pass : anti-debug methodics"
 
Créer une base NoSQL en 1 heure
Créer une base NoSQL en 1 heureCréer une base NoSQL en 1 heure
Créer une base NoSQL en 1 heure
 
File Handling Program
File Handling ProgramFile Handling Program
File Handling Program
 
Debugging: Rules And Tools - PHPTek 11 Version
Debugging: Rules And Tools - PHPTek 11 VersionDebugging: Rules And Tools - PHPTek 11 Version
Debugging: Rules And Tools - PHPTek 11 Version
 
PyCon KR 2019 sprint - RustPython by example
PyCon KR 2019 sprint  - RustPython by examplePyCon KR 2019 sprint  - RustPython by example
PyCon KR 2019 sprint - RustPython by example
 
Mozilla とブラウザゲーム
Mozilla とブラウザゲームMozilla とブラウザゲーム
Mozilla とブラウザゲーム
 
プログラム実行の話と
OSとメモリの挙動の話
プログラム実行の話と
OSとメモリの挙動の話プログラム実行の話と
OSとメモリの挙動の話
プログラム実行の話と
OSとメモリの挙動の話
 
Teaching Your Machine To Find Fraudsters
Teaching Your Machine To Find FraudstersTeaching Your Machine To Find Fraudsters
Teaching Your Machine To Find Fraudsters
 
Institute management
Institute managementInstitute management
Institute management
 
Debugging JavaScript with Chrome
Debugging JavaScript with ChromeDebugging JavaScript with Chrome
Debugging JavaScript with Chrome
 

Andere mochten auch

Cctv,fds,ids,acs
Cctv,fds,ids,acsCctv,fds,ids,acs
Cctv,fds,ids,acsrajparkash
 
The impact of innovation on travel and tourism industries (World Travel Marke...
The impact of innovation on travel and tourism industries (World Travel Marke...The impact of innovation on travel and tourism industries (World Travel Marke...
The impact of innovation on travel and tourism industries (World Travel Marke...Brian Solis
 
Reuters: Pictures of the Year 2016 (Part 2)
Reuters: Pictures of the Year 2016 (Part 2)Reuters: Pictures of the Year 2016 (Part 2)
Reuters: Pictures of the Year 2016 (Part 2)maditabalnco
 
What's Next in Growth? 2016
What's Next in Growth? 2016What's Next in Growth? 2016
What's Next in Growth? 2016Andrew Chen
 
The Six Highest Performing B2B Blog Post Formats
The Six Highest Performing B2B Blog Post FormatsThe Six Highest Performing B2B Blog Post Formats
The Six Highest Performing B2B Blog Post FormatsBarry Feldman
 
The Outcome Economy
The Outcome EconomyThe Outcome Economy
The Outcome EconomyHelge Tennø
 
32 Ways a Digital Marketing Consultant Can Help Grow Your Business
32 Ways a Digital Marketing Consultant Can Help Grow Your Business32 Ways a Digital Marketing Consultant Can Help Grow Your Business
32 Ways a Digital Marketing Consultant Can Help Grow Your BusinessBarry Feldman
 

Andere mochten auch (7)

Cctv,fds,ids,acs
Cctv,fds,ids,acsCctv,fds,ids,acs
Cctv,fds,ids,acs
 
The impact of innovation on travel and tourism industries (World Travel Marke...
The impact of innovation on travel and tourism industries (World Travel Marke...The impact of innovation on travel and tourism industries (World Travel Marke...
The impact of innovation on travel and tourism industries (World Travel Marke...
 
Reuters: Pictures of the Year 2016 (Part 2)
Reuters: Pictures of the Year 2016 (Part 2)Reuters: Pictures of the Year 2016 (Part 2)
Reuters: Pictures of the Year 2016 (Part 2)
 
What's Next in Growth? 2016
What's Next in Growth? 2016What's Next in Growth? 2016
What's Next in Growth? 2016
 
The Six Highest Performing B2B Blog Post Formats
The Six Highest Performing B2B Blog Post FormatsThe Six Highest Performing B2B Blog Post Formats
The Six Highest Performing B2B Blog Post Formats
 
The Outcome Economy
The Outcome EconomyThe Outcome Economy
The Outcome Economy
 
32 Ways a Digital Marketing Consultant Can Help Grow Your Business
32 Ways a Digital Marketing Consultant Can Help Grow Your Business32 Ways a Digital Marketing Consultant Can Help Grow Your Business
32 Ways a Digital Marketing Consultant Can Help Grow Your Business
 

Ähnlich wie Arp

[4] 아두이노와 인터넷
[4] 아두이노와 인터넷[4] 아두이노와 인터넷
[4] 아두이노와 인터넷Chiwon Song
 
tp socket en C.pdf
tp socket en C.pdftp socket en C.pdf
tp socket en C.pdfYoussefJamma
 
Udp socket programming(Florian)
Udp socket programming(Florian)Udp socket programming(Florian)
Udp socket programming(Florian)Flor Ian
 
Gaztea Tech Robotica 2016
Gaztea Tech Robotica 2016Gaztea Tech Robotica 2016
Gaztea Tech Robotica 2016Svet Ivantchev
 
Chatting dengan beberapa pc laptop
Chatting dengan beberapa pc laptopChatting dengan beberapa pc laptop
Chatting dengan beberapa pc laptopyayaria
 
Assignment7.pdf
Assignment7.pdfAssignment7.pdf
Assignment7.pdfdash41
 
Network security Lab manual
Network security Lab manual Network security Lab manual
Network security Lab manual Vivek Kumar Sinha
 
Roberto Gallea: Workshop Arduino, giorno #2 Arduino + Processing
Roberto Gallea: Workshop Arduino, giorno #2 Arduino + ProcessingRoberto Gallea: Workshop Arduino, giorno #2 Arduino + Processing
Roberto Gallea: Workshop Arduino, giorno #2 Arduino + ProcessingDemetrio Siragusa
 
Look Ma, “update DB to HTML5 using C++”, no hands! 
Look Ma, “update DB to HTML5 using C++”, no hands! Look Ma, “update DB to HTML5 using C++”, no hands! 
Look Ma, “update DB to HTML5 using C++”, no hands! aleks-f
 
Encrypt all transports
Encrypt all transportsEncrypt all transports
Encrypt all transportsEleanor McHugh
 
nw-lab_dns-server.pdf
nw-lab_dns-server.pdfnw-lab_dns-server.pdf
nw-lab_dns-server.pdfJayaprasanna4
 

Ähnlich wie Arp (20)

UDP.yash
UDP.yashUDP.yash
UDP.yash
 
[4] 아두이노와 인터넷
[4] 아두이노와 인터넷[4] 아두이노와 인터넷
[4] 아두이노와 인터넷
 
tp socket en C.pdf
tp socket en C.pdftp socket en C.pdf
tp socket en C.pdf
 
Winform
WinformWinform
Winform
 
Udp socket programming(Florian)
Udp socket programming(Florian)Udp socket programming(Florian)
Udp socket programming(Florian)
 
Gaztea Tech Robotica 2016
Gaztea Tech Robotica 2016Gaztea Tech Robotica 2016
Gaztea Tech Robotica 2016
 
Chatting dengan beberapa pc laptop
Chatting dengan beberapa pc laptopChatting dengan beberapa pc laptop
Chatting dengan beberapa pc laptop
 
Socket Programming
Socket ProgrammingSocket Programming
Socket Programming
 
Codes
CodesCodes
Codes
 
java sockets
 java sockets java sockets
java sockets
 
Assignment7.pdf
Assignment7.pdfAssignment7.pdf
Assignment7.pdf
 
Network security Lab manual
Network security Lab manual Network security Lab manual
Network security Lab manual
 
Roberto Gallea: Workshop Arduino, giorno #2 Arduino + Processing
Roberto Gallea: Workshop Arduino, giorno #2 Arduino + ProcessingRoberto Gallea: Workshop Arduino, giorno #2 Arduino + Processing
Roberto Gallea: Workshop Arduino, giorno #2 Arduino + Processing
 
Pemrograman Jaringan
Pemrograman JaringanPemrograman Jaringan
Pemrograman Jaringan
 
Server
ServerServer
Server
 
Look Ma, “update DB to HTML5 using C++”, no hands! 
Look Ma, “update DB to HTML5 using C++”, no hands! Look Ma, “update DB to HTML5 using C++”, no hands! 
Look Ma, “update DB to HTML5 using C++”, no hands! 
 
Encrypt all transports
Encrypt all transportsEncrypt all transports
Encrypt all transports
 
Tugas 2
Tugas 2Tugas 2
Tugas 2
 
Arduino práctico ethernet
Arduino práctico   ethernetArduino práctico   ethernet
Arduino práctico ethernet
 
nw-lab_dns-server.pdf
nw-lab_dns-server.pdfnw-lab_dns-server.pdf
nw-lab_dns-server.pdf
 

Kürzlich hochgeladen

The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxheathfieldcps1
 
How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17Celine George
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingTechSoup
 
How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17Celine George
 
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...ZurliaSoop
 
Sociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning ExhibitSociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning Exhibitjbellavia9
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.pptRamjanShidvankar
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxVishalSingh1417
 
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptxSKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptxAmanpreet Kaur
 
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxDenish Jangid
 
Understanding Accommodations and Modifications
Understanding  Accommodations and ModificationsUnderstanding  Accommodations and Modifications
Understanding Accommodations and ModificationsMJDuyan
 
ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.MaryamAhmad92
 
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfUGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfNirmal Dwivedi
 
Making communications land - Are they received and understood as intended? we...
Making communications land - Are they received and understood as intended? we...Making communications land - Are they received and understood as intended? we...
Making communications land - Are they received and understood as intended? we...Association for Project Management
 
Micro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdfMicro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdfPoh-Sun Goh
 
This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.christianmathematics
 
ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxAreebaZafar22
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfciinovamais
 
Dyslexia AI Workshop for Slideshare.pptx
Dyslexia AI Workshop for Slideshare.pptxDyslexia AI Workshop for Slideshare.pptx
Dyslexia AI Workshop for Slideshare.pptxcallscotland1987
 

Kürzlich hochgeladen (20)

The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptx
 
How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy Consulting
 
How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17
 
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
 
Sociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning ExhibitSociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning Exhibit
 
Asian American Pacific Islander Month DDSD 2024.pptx
Asian American Pacific Islander Month DDSD 2024.pptxAsian American Pacific Islander Month DDSD 2024.pptx
Asian American Pacific Islander Month DDSD 2024.pptx
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.ppt
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptx
 
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptxSKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
 
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
 
Understanding Accommodations and Modifications
Understanding  Accommodations and ModificationsUnderstanding  Accommodations and Modifications
Understanding Accommodations and Modifications
 
ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.
 
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfUGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
 
Making communications land - Are they received and understood as intended? we...
Making communications land - Are they received and understood as intended? we...Making communications land - Are they received and understood as intended? we...
Making communications land - Are they received and understood as intended? we...
 
Micro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdfMicro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdf
 
This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.
 
ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptx
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
 
Dyslexia AI Workshop for Slideshare.pptx
Dyslexia AI Workshop for Slideshare.pptxDyslexia AI Workshop for Slideshare.pptx
Dyslexia AI Workshop for Slideshare.pptx
 

Arp

  • 1. /* SERVER */ #include<stdio.h> #include<sys/types.h> #include<sys/socket.h> #include<netinet/in.h> #include<arpa/inet.h> #include<stdlib.h> #include<unistd.h> #include<string.h> #include<errno.h> #define port 7564 int main() { int sock,con,byte_rec,i=0; char send_data[1024],rec_data[1024]; struct sockaddr_in ser,cli; int sin_size; char ip[5][20]={"127.0.0.1","127.0.0.2","127.0.0.3","127.0.0.4","127.0.0.5"}; char mac[5][20]={"15.8.12.0.0.1","15.8.12.0.0.2","15.8.12.0.0.3","15.8.12.0.0.4","15.8.12.0.0.5"}; //socket creation if((sock=socket(AF_INET,SOCK_STREAM,0))==-1)
  • 2. { perror("Socketn"); exit(1); } ser.sin_family=AF_INET; ser.sin_port=htons(port); ser.sin_addr.s_addr=INADDR_ANY; bzero(&(ser.sin_zero),8); //binding the socket if(bind(sock,(struct sockaddr*)&ser,sizeof(struct sockaddr))==-1) { perror("can't bindn"); exit(1); } //listening to clients connection request if(listen(sock,3)==-1) { perror("listenn"); exit(1); } printf("Waiting n");
  • 3. sin_size=sizeof(struct sockaddr_in); //accepting connection of client con=accept(sock,(struct sockaddr*)&cli,&sin_size); printf("Connectedn"); while(1) { //receiving data from client byte_rec=recv(con,rec_data,1024,0); rec_data[byte_rec]='0'; if(strcmp(rec_data,"end")==0) { //closing socket close(con); close(sock); break; } else printf("Received IP address=%sn",rec_data); for(i=0;i<5;i++) { if(strcmp(ip[i],rec_data)==0) { strcpy(send_data,mac[i]); printf("Mac address %s sent to clientnn",mac[i]);
  • 4. break; } } //sending data to client send(con,send_data,strlen(send_data),0); } return 0; } /*CLIENT*/ #include<stdio.h> #include<sys/types.h> #include<sys/socket.h> #include<netinet/in.h> #include<arpa/inet.h> #include<stdlib.h> #include<unistd.h> #include<string.h> #include<netdb.h> #include<errno.h> #define port 7564
  • 5. int main() { int i,sock,byte_rec; char send_data[1024],rec_data[1024]; char ip[5][20]={"127.0.0.1","127.0.0.2","127.0.0.3","127.0.0.4","127.0.0.5"}; struct hostent *host; struct sockaddr_in ser,cli; host=gethostbyname("127.0.0.1"); //socket creation if((sock=socket(AF_INET,SOCK_STREAM,0))==-1) { perror("Socketn"); exit(1); } printf("socket createdn"); ser.sin_family=AF_INET; ser.sin_port=htons(port); ser.sin_addr= *((struct in_addr *)host->h_addr); bzero(&(ser.sin_zero),8); //connecting to server if(connect(sock,(struct sockaddr*)&ser,sizeof(struct sockaddr))==-1)
  • 6. { perror("connectn"); exit(1); } while(1) { //sending data to server printf("nEnter the IP address : "); scanf("%s",send_data); loop1: for(i=0;i<5;i++) { if((strcmp(ip[i],send_data)==0)||(strcmp(send_data,"end")==0)) goto loop2; } if(strcmp(ip[i],send_data)!=0) { printf("SORRY!! Enter a VALID IP ADDRESS"); printf("nEnter the IP address:n"); scanf("%s",send_data); goto loop1; }
  • 7. loop2: if(strcmp(send_data,"end")!=0) { send(sock,send_data,strlen(send_data),0); } else { send(sock,send_data,strlen(send_data),0); //closing socket close(sock); break; } //receiving data from server byte_rec=recv(sock,rec_data,1024,0); rec_data[byte_rec]='0'; printf("Received MAC address = %snn",rec_data); } return 0; } Output [12mcs009@mepcolinux:~/networkslab]cat arpoutput.txt [12mcs009@mepcolinux:~]vi arpserver.c
  • 8. [12mcs009@mepcolinux:~]cc arpserver.c [12mcs009@mepcolinux:~]./a.out Waiting Connected Received IP address=127.0.0.5 Mac address 15.8.12.0.0.5 sent to client [12mcs009@mepcolinux:~]vi arpclient.c [12mcs009@mepcolinux:~]cc arpclient.c [12mcs009@mepcolinux:~]./a.out socket created Enter the IP address : 127.0.0.5 Received MAC address = 15.8.12.0.0.5 [12mcs009@mepcolinux:~/networkslab]