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 *_*
Kernel turbinado, compatibilidade em alta e debate sobre sustentabilidade: o dia no mundo Linux
Kernel turbinado e GNOME 49 dominam o giro do dia no mundo Linux
Novidades Linux: Kernel 6.17, distros em ebulição e segurança em foco
Kernel ganha novos linters Rust e distros avançam com recursos de IA
Adicionando o repositório backports no Debian 13 Trixie
Como definir um IP estático no Linux Debian
Jogos de Azar Online no Android em Portugal: Tudo o Que Precisa Saber (0)
Orientação para instalar o Warsaw - módulo de proteção do Banco do Bra... (6)
systemd-resol... precisa ser reiniciado periodicamente (5)
Alguém que utilize o Warsaw do BB no Ubuntu 24.04 [RESOLVIDO] (6)
Fedora não reconhece James Donkey 102 Wireless Gaming Mouse (2)