I am working on a project where I have to do a program Client/Server where I have to test the connection , send/receive files and list all the files saved on the server.
I am on the first step , and I am asked to enter manually the port number and the IP address and I am blocked on the IP address declaration..
There is my code
void connection(){
int port;
int sockfd,connfd;
struct sockaddr_in servaddr,cli;
sockfd=socket(AF_INET,SOCK_STREAM,0);
if(sockfd==-1)
{
printf("socket creation failed...\n");
exit(0);
}
else
printf("Socket successfully created..\n");
printf("Enter Port Number \n");
scanf("%d",&port);
bzero(&servaddr,sizeof(servaddr));
servaddr.sin_family=AF_INET;
servaddr.sin_addr.s_addr=inet_addr("127.0.0.1");
servaddr.sin_port=htons(port);
if(connect(sockfd,(SA *)&servaddr,sizeof(servaddr))!=0)
{
printf("connection with the server failed...\n");
printf("Program Closed\n");
exit(0);
}
else
printf("connected to the server..\n");
printf("listening from Server\n");
func(sockfd);
close(sockfd);}
Now If I want to declare a variable and put my IP "127.0.0.1" in it and use it in this line servaddr.sin_addr.s_addr=inet_addr
?
And after establishing the connection to the server, I am able to send and receieve messages , but I want to show the traces (Frames) with their size in bytes etc. Any idea?
Thank you