SlideShare a Scribd company logo
/* 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]

More Related Content

What's hot

Ee
EeEe
ZeroMQ Is The Answer
ZeroMQ Is The AnswerZeroMQ Is The Answer
ZeroMQ Is The Answer
Ian Barber
 
Yg byev2e
Yg byev2eYg byev2e
Yg byev2e
longphi2812
 
ZeroMQ: Messaging Made Simple
ZeroMQ: Messaging Made SimpleZeroMQ: Messaging Made Simple
ZeroMQ: Messaging Made Simple
Ian Barber
 
Php arduino
Php arduinoPhp arduino
Php arduino
Jonadri Bundo
 
20151224-games
20151224-games20151224-games
20151224-games
Noritada Shimizu
 
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
Noritada Shimizu
 
Introduction to ES6 with Tommy Cresine
Introduction to ES6 with Tommy CresineIntroduction to ES6 with Tommy Cresine
Introduction to ES6 with Tommy Cresine
Movel
 
c++ program for Canteen management
c++ program for Canteen managementc++ program for Canteen management
c++ program for Canteen management
Swarup Kumar Boro
 
Full-Stack JavaScript with Node.js
Full-Stack JavaScript with Node.jsFull-Stack JavaScript with Node.js
Full-Stack JavaScript with Node.js
Michael 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 heure
Amaury Bouchard
 
File Handling Program
File Handling ProgramFile 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
Ian 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 example
YunWon 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 Fraudsters
Ian Barber
 
Institute management
Institute managementInstitute management
Institute management
varun arora
 
Debugging JavaScript with Chrome
Debugging JavaScript with ChromeDebugging JavaScript with Chrome
Debugging JavaScript with Chrome
Igor Zalutsky
 

What's hot (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
 

Viewers also liked

Cctv,fds,ids,acs
Cctv,fds,ids,acsCctv,fds,ids,acs
Cctv,fds,ids,acs
rajparkash
 
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? 2016
Andrew 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 Formats
Barry Feldman
 
The Outcome Economy
The Outcome EconomyThe Outcome Economy
The Outcome Economy
Helge 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 Business
Barry Feldman
 

Viewers also liked (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
 

Similar to Arp

UDP.yash
UDP.yashUDP.yash
UDP.yash
Yashpatel821746
 
[4] 아두이노와 인터넷
[4] 아두이노와 인터넷[4] 아두이노와 인터넷
[4] 아두이노와 인터넷
Chiwon Song
 
tp socket en C.pdf
tp socket en C.pdftp socket en C.pdf
tp socket en C.pdf
YoussefJamma
 
Winform
WinformWinform
Winform
quocphu199
 
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 2016
Svet Ivantchev
 
Chatting dengan beberapa pc laptop
Chatting dengan beberapa pc laptopChatting dengan beberapa pc laptop
Chatting dengan beberapa pc laptop
yayaria
 
Socket Programming
Socket ProgrammingSocket Programming
Socket Programming
Sivadon Chaisiri
 
Codes
CodesCodes
java sockets
 java sockets java sockets
java sockets
Enam Ahmed Shahaz
 
Assignment7.pdf
Assignment7.pdfAssignment7.pdf
Assignment7.pdf
dash41
 
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 + Processing
Demetrio Siragusa
 
Pemrograman Jaringan
Pemrograman JaringanPemrograman Jaringan
Pemrograman Jaringan
belajarkomputer
 
Server
ServerServer
Server
marveenstein
 
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 transports
Eleanor McHugh
 
Tugas 2
Tugas 2Tugas 2
Tugas 2
Novi_Wahyuni
 
Arduino práctico ethernet
Arduino práctico   ethernetArduino práctico   ethernet
Arduino práctico ethernet
Jose Antonio Vacas
 
nw-lab_dns-server.pdf
nw-lab_dns-server.pdfnw-lab_dns-server.pdf
nw-lab_dns-server.pdf
Jayaprasanna4
 

Similar to 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
 

Recently uploaded

CACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdfCACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdf
camakaiclarkmusic
 
The basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptxThe basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptx
heathfieldcps1
 
How to Build a Module in Odoo 17 Using the Scaffold Method
How to Build a Module in Odoo 17 Using the Scaffold MethodHow to Build a Module in Odoo 17 Using the Scaffold Method
How to Build a Module in Odoo 17 Using the Scaffold Method
Celine George
 
Pride Month Slides 2024 David Douglas School District
Pride Month Slides 2024 David Douglas School DistrictPride Month Slides 2024 David Douglas School District
Pride Month Slides 2024 David Douglas School District
David Douglas School District
 
How to Fix the Import Error in the Odoo 17
How to Fix the Import Error in the Odoo 17How to Fix the Import Error in the Odoo 17
How to Fix the Import Error in the Odoo 17
Celine George
 
Digital Artifact 1 - 10VCD Environments Unit
Digital Artifact 1 - 10VCD Environments UnitDigital Artifact 1 - 10VCD Environments Unit
Digital Artifact 1 - 10VCD Environments Unit
chanes7
 
Natural birth techniques - Mrs.Akanksha Trivedi Rama University
Natural birth techniques - Mrs.Akanksha Trivedi Rama UniversityNatural birth techniques - Mrs.Akanksha Trivedi Rama University
Natural birth techniques - Mrs.Akanksha Trivedi Rama University
Akanksha trivedi rama nursing college kanpur.
 
A Survey of Techniques for Maximizing LLM Performance.pptx
A Survey of Techniques for Maximizing LLM Performance.pptxA Survey of Techniques for Maximizing LLM Performance.pptx
A Survey of Techniques for Maximizing LLM Performance.pptx
thanhdowork
 
ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...
ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...
ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...
PECB
 
Chapter 4 - Islamic Financial Institutions in Malaysia.pptx
Chapter 4 - Islamic Financial Institutions in Malaysia.pptxChapter 4 - Islamic Financial Institutions in Malaysia.pptx
Chapter 4 - Islamic Financial Institutions in Malaysia.pptx
Mohd Adib Abd Muin, Senior Lecturer at Universiti Utara Malaysia
 
বাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdf
বাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdfবাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdf
বাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdf
eBook.com.bd (প্রয়োজনীয় বাংলা বই)
 
Advanced Java[Extra Concepts, Not Difficult].docx
Advanced Java[Extra Concepts, Not Difficult].docxAdvanced Java[Extra Concepts, Not Difficult].docx
Advanced Java[Extra Concepts, Not Difficult].docx
adhitya5119
 
The simplified electron and muon model, Oscillating Spacetime: The Foundation...
The simplified electron and muon model, Oscillating Spacetime: The Foundation...The simplified electron and muon model, Oscillating Spacetime: The Foundation...
The simplified electron and muon model, Oscillating Spacetime: The Foundation...
RitikBhardwaj56
 
World environment day ppt For 5 June 2024
World environment day ppt For 5 June 2024World environment day ppt For 5 June 2024
World environment day ppt For 5 June 2024
ak6969907
 
Pollock and Snow "DEIA in the Scholarly Landscape, Session One: Setting Expec...
Pollock and Snow "DEIA in the Scholarly Landscape, Session One: Setting Expec...Pollock and Snow "DEIA in the Scholarly Landscape, Session One: Setting Expec...
Pollock and Snow "DEIA in the Scholarly Landscape, Session One: Setting Expec...
National Information Standards Organization (NISO)
 
Executive Directors Chat Leveraging AI for Diversity, Equity, and Inclusion
Executive Directors Chat  Leveraging AI for Diversity, Equity, and InclusionExecutive Directors Chat  Leveraging AI for Diversity, Equity, and Inclusion
Executive Directors Chat Leveraging AI for Diversity, Equity, and Inclusion
TechSoup
 
South African Journal of Science: Writing with integrity workshop (2024)
South African Journal of Science: Writing with integrity workshop (2024)South African Journal of Science: Writing with integrity workshop (2024)
South African Journal of Science: Writing with integrity workshop (2024)
Academy of Science of South Africa
 
Types of Herbal Cosmetics its standardization.
Types of Herbal Cosmetics its standardization.Types of Herbal Cosmetics its standardization.
Types of Herbal Cosmetics its standardization.
Ashokrao Mane college of Pharmacy Peth-Vadgaon
 
writing about opinions about Australia the movie
writing about opinions about Australia the moviewriting about opinions about Australia the movie
writing about opinions about Australia the movie
Nicholas Montgomery
 
Introduction to AI for Nonprofits with Tapp Network
Introduction to AI for Nonprofits with Tapp NetworkIntroduction to AI for Nonprofits with Tapp Network
Introduction to AI for Nonprofits with Tapp Network
TechSoup
 

Recently uploaded (20)

CACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdfCACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdf
 
The basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptxThe basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptx
 
How to Build a Module in Odoo 17 Using the Scaffold Method
How to Build a Module in Odoo 17 Using the Scaffold MethodHow to Build a Module in Odoo 17 Using the Scaffold Method
How to Build a Module in Odoo 17 Using the Scaffold Method
 
Pride Month Slides 2024 David Douglas School District
Pride Month Slides 2024 David Douglas School DistrictPride Month Slides 2024 David Douglas School District
Pride Month Slides 2024 David Douglas School District
 
How to Fix the Import Error in the Odoo 17
How to Fix the Import Error in the Odoo 17How to Fix the Import Error in the Odoo 17
How to Fix the Import Error in the Odoo 17
 
Digital Artifact 1 - 10VCD Environments Unit
Digital Artifact 1 - 10VCD Environments UnitDigital Artifact 1 - 10VCD Environments Unit
Digital Artifact 1 - 10VCD Environments Unit
 
Natural birth techniques - Mrs.Akanksha Trivedi Rama University
Natural birth techniques - Mrs.Akanksha Trivedi Rama UniversityNatural birth techniques - Mrs.Akanksha Trivedi Rama University
Natural birth techniques - Mrs.Akanksha Trivedi Rama University
 
A Survey of Techniques for Maximizing LLM Performance.pptx
A Survey of Techniques for Maximizing LLM Performance.pptxA Survey of Techniques for Maximizing LLM Performance.pptx
A Survey of Techniques for Maximizing LLM Performance.pptx
 
ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...
ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...
ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...
 
Chapter 4 - Islamic Financial Institutions in Malaysia.pptx
Chapter 4 - Islamic Financial Institutions in Malaysia.pptxChapter 4 - Islamic Financial Institutions in Malaysia.pptx
Chapter 4 - Islamic Financial Institutions in Malaysia.pptx
 
বাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdf
বাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdfবাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdf
বাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdf
 
Advanced Java[Extra Concepts, Not Difficult].docx
Advanced Java[Extra Concepts, Not Difficult].docxAdvanced Java[Extra Concepts, Not Difficult].docx
Advanced Java[Extra Concepts, Not Difficult].docx
 
The simplified electron and muon model, Oscillating Spacetime: The Foundation...
The simplified electron and muon model, Oscillating Spacetime: The Foundation...The simplified electron and muon model, Oscillating Spacetime: The Foundation...
The simplified electron and muon model, Oscillating Spacetime: The Foundation...
 
World environment day ppt For 5 June 2024
World environment day ppt For 5 June 2024World environment day ppt For 5 June 2024
World environment day ppt For 5 June 2024
 
Pollock and Snow "DEIA in the Scholarly Landscape, Session One: Setting Expec...
Pollock and Snow "DEIA in the Scholarly Landscape, Session One: Setting Expec...Pollock and Snow "DEIA in the Scholarly Landscape, Session One: Setting Expec...
Pollock and Snow "DEIA in the Scholarly Landscape, Session One: Setting Expec...
 
Executive Directors Chat Leveraging AI for Diversity, Equity, and Inclusion
Executive Directors Chat  Leveraging AI for Diversity, Equity, and InclusionExecutive Directors Chat  Leveraging AI for Diversity, Equity, and Inclusion
Executive Directors Chat Leveraging AI for Diversity, Equity, and Inclusion
 
South African Journal of Science: Writing with integrity workshop (2024)
South African Journal of Science: Writing with integrity workshop (2024)South African Journal of Science: Writing with integrity workshop (2024)
South African Journal of Science: Writing with integrity workshop (2024)
 
Types of Herbal Cosmetics its standardization.
Types of Herbal Cosmetics its standardization.Types of Herbal Cosmetics its standardization.
Types of Herbal Cosmetics its standardization.
 
writing about opinions about Australia the movie
writing about opinions about Australia the moviewriting about opinions about Australia the movie
writing about opinions about Australia the movie
 
Introduction to AI for Nonprofits with Tapp Network
Introduction to AI for Nonprofits with Tapp NetworkIntroduction to AI for Nonprofits with Tapp Network
Introduction to AI for Nonprofits with Tapp Network
 

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]