SHOW:
|
|
- or go back to the newest paste.
1 | #include <iostream> | |
2 | #include <stdlib.h> | |
3 | #include <string.h> | |
4 | #include <sys/socket.h> | |
5 | #include <sys/types.h> | |
6 | #include <netinet/in.h> | |
7 | #include <arpa/inet.h> | |
8 | #include <unistd.h> | |
9 | using namespace std; | |
10 | ||
11 | void errore(...){ | |
12 | cerr<<"Errore!"<<endl; | |
13 | exit(1); | |
14 | } | |
15 | ||
16 | int main(){ | |
17 | const int port = 4444; | |
18 | ||
19 | int sockfd; | |
20 | struct sockaddr_in serverAddr; | |
21 | ||
22 | - | char buffer[1024]; |
22 | + | |
23 | struct sockaddr_in newAddr; | |
24 | ||
25 | - | if(sockfd == -1){ |
25 | + | |
26 | - | cerr<<"Socket fallita"; |
26 | + | |
27 | - | exit(1); |
27 | + | |
28 | - | } |
28 | + | if(sockfd == -1) errore(); |
29 | cout<<"[+]Server Socket Creata.\n"; | |
30 | - | memset(&serverAddr, '\0', sizeof(serverAddr)); |
30 | + | |
31 | serverAddr.sin_family = AF_INET; | |
32 | serverAddr.sin_port = htons(port); | |
33 | serverAddr.sin_addr.s_addr = inet_addr("127.0.0.1"); | |
34 | ||
35 | ||
36 | if((bind(sockfd, (struct sockaddr*)&serverAddr, sizeof(serverAddr))) == -1) | |
37 | - | if((bind(sockfd, (struct sockaddr*)&serverAddr, sizeof(serverAddr))) == -1){ |
37 | + | errore(); |
38 | - | cerr<<"Bind fallita"; |
38 | + | |
39 | - | exit(1); |
39 | + | |
40 | - | } |
40 | + | |
41 | ||
42 | if((listen(sockfd, 5)) == -1) errore(); | |
43 | cout<<"[+]Sto ascoltanto...\n"; | |
44 | - | if((listen(sockfd, 5)) == -1){ |
44 | + | |
45 | - | cerr<<"Listen fallita"; |
45 | + | |
46 | - | exit(1); |
46 | + | if(newSocket == -1) errore(); |
47 | - | } |
47 | + | |
48 | cout<<"[+]Sto chiudendo la connessione\n"; | |
49 | close(sockfd); | |
50 | close(newSocket); | |
51 | - | if(newSocket == -1){ |
51 | + |