SlideShare una empresa de Scribd logo
1 de 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]

Más contenido relacionado

La actualidad más candente

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
 

La actualidad más candente (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
 

Destacado

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
 

Destacado (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 a 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
 

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

Último

APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAssociation for Project Management
 
Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphThiyagu K
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfciinovamais
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxVishalSingh1417
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Celine George
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdfQucHHunhnh
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdfSoniaTolstoy
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeThiyagu K
 
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
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxiammrhaywood
 
Student login on Anyboli platform.helpin
Student login on Anyboli platform.helpinStudent login on Anyboli platform.helpin
Student login on Anyboli platform.helpinRaunakKeshri1
 
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...christianmathematics
 
social pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajansocial pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajanpragatimahajan3
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfagholdier
 
Disha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdfDisha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdfchloefrazer622
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformChameera Dedduwage
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationnomboosow
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3JemimahLaneBuaron
 

Último (20)

APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across Sectors
 
Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot Graph
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptx
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and Mode
 
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
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
 
Student login on Anyboli platform.helpin
Student login on Anyboli platform.helpinStudent login on Anyboli platform.helpin
Student login on Anyboli platform.helpin
 
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
 
social pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajansocial pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajan
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdf
 
Disha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdfDisha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdf
 
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptxINDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
 
Advance Mobile Application Development class 07
Advance Mobile Application Development class 07Advance Mobile Application Development class 07
Advance Mobile Application Development class 07
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy Reform
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communication
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3
 

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]