
Enviado em 25/10/2018 - 21:52h
Olá, boa noite a todos!
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <netdb.h>
#include <sys/types.h>
#include <arpa/inet.h>
#include <sys/socket.h>
#include <netinet/in.h>
#define PORT "9009"
int make_server_socket(void){
int sockfd;
struct addrinfo *res=NULL, hints;
memset(&hints, 0, sizeof(hints));
hints.ai_flags=AI_PASSIVE;
hints.ai_family=AF_UNSPEC;
hints.ai_socktype=SOCK_STREAM;
hints.ai_protocol=IPPROTO_TCP;
if(getaddrinfo(NULL, PORT, &hints, &res)!=0){
sockfd=-1;
}else{
if((sockfd=socket(res->ai_family, SOCK_STREAM, IPPROTO_TCP))!=-1){
if(bind(sockfd, res->ai_addr, res->ai_addrlen)<0){
sockfd=-1;
}
}
freeaddrinfo(res);
}
return sockfd;
}
int main(void){
int sockfd=make_server_socket();
if(sockfd!=-1){
listen(sockfd, 1);
int csockfd=accept(sockfd, NULL, NULL);
if(csockfd!=-1){
send(csockfd, "Real Muthaphuckkin G's", 23, 0);
}
close(sockfd);
close(csockfd);
}
return 0;
}
zherkezhi@zherkezhi :~/Documents/C/Perguntas$ nc -4 127.0.0.1 9009
Real Muthaphuckkin G's
zherkezhi@zherkezhi:~/Documents/C/Perguntas$ #Funcionou perfeitamente!
zherkezhi@zherkezhi:~/Documents/C/Perguntas$ nc -6 ::1 9009
zherkezhi@zherkezhi:~/Documents/C/Perguntas$ #não aconteceu nada *_*
Cirurgia para acelerar o openSUSE em HD externo via USB
Void Server como Domain Control
Modo Simples de Baixar e Usar o bash-completion
Monitorando o Preço do Bitcoin ou sua Cripto Favorita em Tempo Real com um Widget Flutuante
Como fazer a conversão binária e aplicar as restrições no Linux
Como quebrar a senha de um servidor Linux Debian
Como bloquear pendrive em uma rede Linux
Um autoinstall.yaml para Ubuntu com foco em quem vai fazer máquina virtual
Instalar GRUB sem archinstall no Arch Linux em UEFI Problemático









