SlideShare a Scribd company logo
1 of 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]

More Related Content

What's hot

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
 

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

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

Chatting dengan beberapa pc laptop
Chatting dengan beberapa pc laptopChatting dengan beberapa pc laptop
Chatting dengan beberapa pc laptop
yayaria
 
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
 

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

The basics of sentences session 4pptx.pptx
The basics of sentences session 4pptx.pptxThe basics of sentences session 4pptx.pptx
The basics of sentences session 4pptx.pptx
heathfieldcps1
 
Financial Accounting IFRS, 3rd Edition-dikompresi.pdf
Financial Accounting IFRS, 3rd Edition-dikompresi.pdfFinancial Accounting IFRS, 3rd Edition-dikompresi.pdf
Financial Accounting IFRS, 3rd Edition-dikompresi.pdf
MinawBelay
 
MSc Ag Genetics & Plant Breeding: Insights from Previous Year JNKVV Entrance ...
MSc Ag Genetics & Plant Breeding: Insights from Previous Year JNKVV Entrance ...MSc Ag Genetics & Plant Breeding: Insights from Previous Year JNKVV Entrance ...
MSc Ag Genetics & Plant Breeding: Insights from Previous Year JNKVV Entrance ...
Krashi Coaching
 

Recently uploaded (20)

Software testing for project report .pdf
Software testing for project report .pdfSoftware testing for project report .pdf
Software testing for project report .pdf
 
Exploring Gemini AI and Integration with MuleSoft | MuleSoft Mysore Meetup #45
Exploring Gemini AI and Integration with MuleSoft | MuleSoft Mysore Meetup #45Exploring Gemini AI and Integration with MuleSoft | MuleSoft Mysore Meetup #45
Exploring Gemini AI and Integration with MuleSoft | MuleSoft Mysore Meetup #45
 
....................Muslim-Law notes.pdf
....................Muslim-Law notes.pdf....................Muslim-Law notes.pdf
....................Muslim-Law notes.pdf
 
Dementia (Alzheimer & vasular dementia).
Dementia (Alzheimer & vasular dementia).Dementia (Alzheimer & vasular dementia).
Dementia (Alzheimer & vasular dementia).
 
ANTI PARKISON DRUGS.pptx
ANTI         PARKISON          DRUGS.pptxANTI         PARKISON          DRUGS.pptx
ANTI PARKISON DRUGS.pptx
 
The basics of sentences session 4pptx.pptx
The basics of sentences session 4pptx.pptxThe basics of sentences session 4pptx.pptx
The basics of sentences session 4pptx.pptx
 
Spring gala 2024 photo slideshow - Celebrating School-Community Partnerships
Spring gala 2024 photo slideshow - Celebrating School-Community PartnershipsSpring gala 2024 photo slideshow - Celebrating School-Community Partnerships
Spring gala 2024 photo slideshow - Celebrating School-Community Partnerships
 
REPRODUCTIVE TOXICITY STUDIE OF MALE AND FEMALEpptx
REPRODUCTIVE TOXICITY  STUDIE OF MALE AND FEMALEpptxREPRODUCTIVE TOXICITY  STUDIE OF MALE AND FEMALEpptx
REPRODUCTIVE TOXICITY STUDIE OF MALE AND FEMALEpptx
 
size separation d pharm 1st year pharmaceutics
size separation d pharm 1st year pharmaceuticssize separation d pharm 1st year pharmaceutics
size separation d pharm 1st year pharmaceutics
 
Financial Accounting IFRS, 3rd Edition-dikompresi.pdf
Financial Accounting IFRS, 3rd Edition-dikompresi.pdfFinancial Accounting IFRS, 3rd Edition-dikompresi.pdf
Financial Accounting IFRS, 3rd Edition-dikompresi.pdf
 
Features of Video Calls in the Discuss Module in Odoo 17
Features of Video Calls in the Discuss Module in Odoo 17Features of Video Calls in the Discuss Module in Odoo 17
Features of Video Calls in the Discuss Module in Odoo 17
 
MSc Ag Genetics & Plant Breeding: Insights from Previous Year JNKVV Entrance ...
MSc Ag Genetics & Plant Breeding: Insights from Previous Year JNKVV Entrance ...MSc Ag Genetics & Plant Breeding: Insights from Previous Year JNKVV Entrance ...
MSc Ag Genetics & Plant Breeding: Insights from Previous Year JNKVV Entrance ...
 
An overview of the various scriptures in Hinduism
An overview of the various scriptures in HinduismAn overview of the various scriptures in Hinduism
An overview of the various scriptures in Hinduism
 
Championnat de France de Tennis de table/
Championnat de France de Tennis de table/Championnat de France de Tennis de table/
Championnat de France de Tennis de table/
 
MichaelStarkes_UncutGemsProjectSummary.pdf
MichaelStarkes_UncutGemsProjectSummary.pdfMichaelStarkes_UncutGemsProjectSummary.pdf
MichaelStarkes_UncutGemsProjectSummary.pdf
 
UChicago CMSC 23320 - The Best Commit Messages of 2024
UChicago CMSC 23320 - The Best Commit Messages of 2024UChicago CMSC 23320 - The Best Commit Messages of 2024
UChicago CMSC 23320 - The Best Commit Messages of 2024
 
Incoming and Outgoing Shipments in 2 STEPS Using Odoo 17
Incoming and Outgoing Shipments in 2 STEPS Using Odoo 17Incoming and Outgoing Shipments in 2 STEPS Using Odoo 17
Incoming and Outgoing Shipments in 2 STEPS Using Odoo 17
 
PSYPACT- Practicing Over State Lines May 2024.pptx
PSYPACT- Practicing Over State Lines May 2024.pptxPSYPACT- Practicing Over State Lines May 2024.pptx
PSYPACT- Practicing Over State Lines May 2024.pptx
 
Graduate Outcomes Presentation Slides - English (v3).pptx
Graduate Outcomes Presentation Slides - English (v3).pptxGraduate Outcomes Presentation Slides - English (v3).pptx
Graduate Outcomes Presentation Slides - English (v3).pptx
 
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT VẬT LÝ 2024 - TỪ CÁC TRƯỜNG, TRƯ...
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT VẬT LÝ 2024 - TỪ CÁC TRƯỜNG, TRƯ...TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT VẬT LÝ 2024 - TỪ CÁC TRƯỜNG, TRƯ...
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT VẬT LÝ 2024 - TỪ CÁC TRƯỜNG, TRƯ...
 

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]