2. What changes would be required to use IPv6 instead of IPv4? Demonstrate it in code. Make a list of all lines that nee

Business, Finance, Economics, Accounting, Operations Management, Computer Science, Electrical Engineering, Mechanical Engineering, Civil Engineering, Chemical Engineering, Algebra, Precalculus, Statistics and Probabilty, Advanced Math, Physics, Chemistry, Biology, Nursing, Psychology, Certifications, Tests, Prep, and more.
Post Reply
answerhappygod
Site Admin
Posts: 899604
Joined: Mon Aug 02, 2021 8:13 am

2. What changes would be required to use IPv6 instead of IPv4? Demonstrate it in code. Make a list of all lines that nee

Post by answerhappygod »

2 What Changes Would Be Required To Use Ipv6 Instead Of Ipv4 Demonstrate It In Code Make A List Of All Lines That Nee 1
2 What Changes Would Be Required To Use Ipv6 Instead Of Ipv4 Demonstrate It In Code Make A List Of All Lines That Nee 1 (13.4 KiB) Viewed 48 times
PLEASE EXPLAIN LINES THAT NEEDS TO BE CHANGED TO FIT THE IPv6
REQUIREMENT
CLIENT CODE:
#include<string.h>
#include<stdlib.h>
#include <stdio.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <netdb.h>
#define SERVER_PORT 5432
#define MAX_LINE 256
int main(int argc, char * argv[]) {
FILE * fp;
struct hostent * hp;
struct sockaddr_in sin;
char * host;
char buf[MAX_LINE];
int s;
int len;
if (argc == 2) {
host = argv[1];
} else {
fprintf(stderr, "usage: simplex-talk
host\n");
exit(1);
}


/* translate host name into peer's IP address
*/
hp = gethostbyname(host);
if (!hp) {
fprintf(stderr, "simplex-talk: unknown
host: %s\n", host);
exit(1);
}

/* building address data structure */
bzero((char * ) & sin, sizeof(sin));
sin.sin_family = AF_INET;
bcopy(hp -> h_addr, (char * ) & sin.sin_addr,
hp -> h_length);
sin.sin_port = htons(SERVER_PORT);
/* active open */
if ((s = socket(PF_INET, SOCK_STREAM, 0)) < 0)
{
perror("simplex-talk: socket");
exit(1);
}
if (connect(s, (struct sockaddr * ) & sin,
sizeof(sin)) < 0) {
perror("simplex-talk: connect");
close(s);
exit(1);
}
/* main loop: get and send lines of text */
printf("Enter exit to Terminate the
connection\n");
while (1) {
bzero(buf,MAX_LINE); // clear
buffer
// get the input
printf("Enter Text Here >>>
");
fgets(buf, MAX_LINE, stdin); // get
input
buf[MAX_LINE - 1] = '\0';
len = strlen(buf) + 1;
// send(s, buf, len, 0); // send to
server
write(s,buf,len);
if(strncmp(buf,"exit",4) == 0)
return
0;
// fputs("Server: ",stdout);
// // clear buffer
// bzero(buf,MAX_LINE);
// // recieve from server
// recv(s, buf, MAX_LINE, 0);
// fputs(buf,stdout); // print
// if user enters exit; exit from
program
if(strncmp(buf,"exit",4) == 0)
return 0;
}
return 0;
}
SERVER CODE:
#include<string.h>
#include<stdlib.h>
#include <stdio.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <netdb.h>
#define SERVER_PORT 5432
#define MAX_PENDING 5
#define MAX_LINE 256
int main() {
struct sockaddr_in sin;
char buf[MAX_LINE];
int buf_len, addr_len;
int s, new_s;
FILE * file = fopen("serverlog.txt","w");


/* building address data structure */
bzero((char * ) & sin, sizeof(sin));
sin.sin_family = AF_INET;
sin.sin_addr.s_addr = INADDR_ANY;
sin.sin_port = htons(SERVER_PORT);
/* setup passive open */
if ((s = socket(PF_INET, SOCK_STREAM, 0)) < 0)
{
perror("simplex-talk: socket");
exit(1);
}
if ((bind(s, (struct sockaddr * ) & sin,
sizeof(sin))) < 0) {
perror("simplex-talk: bind");
exit(1);
}
listen(s, MAX_PENDING);
pid_t childpid;
int ctr = 1; // total number of connection

while (1) {
// accept new connection
if ((new_s = accept(s, (struct sockaddr
* ) & sin, & addr_len)) < 0) {
perror("simplex-talk:
accept");
exit(1);
}
if((childpid = fork()) == 0){
close(s);

/* wait for connection, then receive
and print text */
while (1){
// clear
buffer

bzero(buf,MAX_LINE);
// recieve
data and print
buf_len =
recv(new_s, buf, MAX_LINE, 0);

fputs("Clinet",file);

fprintf(file, "%d: ", new_s);
fputs(buf,
file);

if(strncmp(buf,"exit",4) == 0)

return 0;
//
printf(">>> ");
// // get
input
//
fgets(buf,MAX_LINE,stdin);
// // send
to client
//
write(new_s,buf,strlen(buf));
// // if
user sent exit; exit the program
//
if(strncmp(buf,"exit",4) == 0)
//
return 0;
}
close(new_s);
}
}
return 0;
}
2. What changes would be required to use IPv6 instead of IPv4? Demonstrate it in code. Make a list of all lines that need to be changed and give an example with a brief explanation.
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!
Post Reply