22bps1059 Lab8
22bps1059 Lab8
client
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/socket.h>
#include <arpa/inet.h>
#include <unistd.h>
int main() {
int sockfd;
struct sockaddr_in server_addr;
char ip_address[16];
// Create socket
sockfd = socket(AF_INET, SOCK_STREAM, 0);
// Connect to server
connect(sockfd, (struct sockaddr*)&server_addr, sizeof(server_addr));
close(sockfd);
return 0;
}
Server
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/socket.h>
#include <arpa/inet.h>
#include <unistd.h>
int main() {
int sockfd, newsockfd;
struct sockaddr_in server_addr, client_addr;
socklen_t client_len;
char buffer[16];
struct in_addr ip;
// Create socket
sockfd = socket(AF_INET, SOCK_STREAM, 0);
client_len = sizeof(client_addr);
newsockfd = accept(sockfd, (struct sockaddr*)&client_addr, &client_len);
// Print IP information
print_ip_info(ip);
close(newsockfd);
close(sockfd);
return 0;
}