Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <stdlib.h>
- #include <string.h>
- #include <sys/socket.h>
- #include <sys/types.h>
- #include <netinet/in.h>
- #include <arpa/inet.h>
- #include <unistd.h>
- using namespace std;
- void errore(...){
- cerr<<"Errore!"<<endl;
- exit(1);
- }
- int main(){
- const int port = 4444;
- int sockfd;
- struct sockaddr_in serverAddr;
- int newSocket;
- struct sockaddr_in newAddr;
- socklen_t addr_size;
- sockfd = socket(AF_INET, SOCK_STREAM, 0);
- if(sockfd == -1) errore();
- cout<<"[+]Server Socket Creata.\n";
- serverAddr.sin_family = AF_INET;
- serverAddr.sin_port = htons(port);
- serverAddr.sin_addr.s_addr = inet_addr("127.0.0.1");
- if((bind(sockfd, (struct sockaddr*)&serverAddr, sizeof(serverAddr))) == -1)
- errore();
- cout<<"[+]Bind sulla Port numero "<<port<<endl;
- if((listen(sockfd, 5)) == -1) errore();
- cout<<"[+]Sto ascoltanto...\n";
- newSocket = accept(sockfd, (struct sockaddr*)&newAddr, &addr_size);
- if(newSocket == -1) errore();
- cout<<"Connessione accetta";
- cout<<"[+]Sto chiudendo la connessione\n";
- close(sockfd);
- close(newSocket);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement