Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <sys/types.h>
- #include <sys/socket.h>
- #include <netinet/in.h>
- #include <netdb.h>
- #include <stdio.h>
- #include <unistd.h>
- #include <stdlib.h>
- #include <string.h>
- #include <pthread.h>
- #include <error.h>
- #include <errno.h>
- #include <signal.h>
- void signal_handler(int signo) {
- if(signo == SIGINT) {
- write(STDOUT_FILENO, "Interrupt signal received.", 27);
- exit(0);
- }
- if(signo == SIGTERM) {
- write(STDOUT_FILENO, "Terminate signal received.", 26);
- exit(0);
- }
- }
- int sock;
- int main() {
- signal(SIGINT, signal_handler);
- signal(SIGTERM, signal_handler);
- struct sockaddr_in server;
- struct hostent *hp;
- char buf[1024];
- //Thread func
- /* Create socket */
- sock = socket(AF_INET, SOCK_STREAM, 0);
- if (sock < 0) {
- perror("opening stream socket");
- exit(1);
- }
- while(1) {
- write(STDOUT_FILENO, "Client Running!nEnter the IP address to connect to: ", 52);
- char ip[20];
- int rip = read(STDIN_FILENO, ip, 20);
- ip[rip - 1] = '