Skip to main content

Posts

Showing posts with the label networking

UDP echo server, client

udpserver.c #include "stdio.h" #include "stdlib.h" #include "sys/types.h" #include "sys/socket.h" #include "arpa/inet.h" #include "netinet/in.h" #include "string.h" #define SA struct sockaddr #define MAX 1024 int main(int argc,char** argv) { int sockfd,n; socklen_t len; struct sockaddr_in servaddr,cliaddr; char buff[MAX],tmp[MAX]; //create socket sockfd = socket(AF_INET,SOCK_DGRAM,0);

Simulation of ARP/RARP

Here is the core simulation of the ARP(Address Resolution Protocol) and RARP(Reverse Address Resolution Protocol) ARP used to map the ip address with the corresponding MAC address and RARP do that in reverse. it maps the MAC with the ip. #include "stdio.h" #include "string.h" int main() { char table[3][2][40]; char ipin[10],macin[30]; int i,j,found; strcpy(table[0][0],"127.0.0.1"); strcpy(table[0][1],"44:dd:22:11:33"); strcpy(table[1][0],"10.1.1.8"); strcpy(table[1][1],"33:aa:fe:4e:2d"); strcpy(table[2][0],"10.1.8.5"); strcpy(table[2][1],"23:a3:5d:33:9d"); printf("IP address\t MAC address\n"); for(i=0;i

tcp client, server chat simplified

Here is my simplified version of the tcp client, server chat application client.c #include "stdio.h" #include "stdlib.h" #include "sys/types.h" #include "sys/socket.h" #include "arpa/inet.h" int main() { int sockfd,n; char buff[256]; struct sockaddr_in servaddr; //create socket sockfd = socket(AF_INET,SOCK_STREAM,0); //fill serv struct servaddr.sin_family = AF_INET; servaddr.sin_port = htons(40402); servaddr.sin_addr.s_addr = inet_addr("127.0.0.1");