Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <ctype.h>
- #include <sys/types.h>
- #include <sys/socket.h>
- #include <netinet/in.h>
- #include <signal.h>
- #define SIZE sizeof(struct sockaddr_in)
- #define MYPORT 7091
- void catcher(int sig);
- int newsockfd;
- main()
- {
- int sockfd;
- char c;
- struct sockaddr_in server = {AF_INET, MYPORT, INADDR_ANY};
- static struct sigaction act;
- act.sa_handler = catcher;
- sigfillset(&(act.sa_mask));
- sigaction(SIGPIPE, &act, NULL);
- if((sockfd=socket(AF_INET, SOCK_STREAM, 0)) == -1){
- perror("socket call failed");
- exit(1);
- }
- if(bind(sockfd, (struct sockaddr *)&server, SIZE) == -1){
- perror("bind call failed");
- exit(1);
- }
- if(listen(sockfd,5) == -1){
- perror("listen call failed");
- exit(1);
- }
- while(1){
- if((newsockfd=accept(sockfd, NULL, NULL)) == -1){
- perror("accept call failed");
- continue;
- }
- if(fork() == 0){
- while(recv(newsockfd, &c, 1, 0) > 0){
- c = toupper(c);
- send(newsockfd, &c, 1, 0);
- }
- close(newsockfd);
- exit(0);
- }
- close(newsockfd);
- }
- }
- void catcher(int sig)
- {
- close(newsockfd);
- exit(0);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement