
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 *_*
O Editor de Texto Nano: Simplicidade no Terminal
SynapSeq - programa para estimular as ondas cerebrais
Por que seu __DIR__ falhou ou o "inferno" dos caminhos no PHP
Preparando-se para certificações da LPI através do LPI Lab
Migração de Arch Linux para repositórios CachyOS (Uso de Instruções v3 e v4)
Jogando "Magic" gratuitamente no Linux
Zoxide e fzf no bash para incrementar o uso do Terminal
As diferencas entre o clipboard comum e a selecao ativa
Arch Linux com repos do CachyOS para otimização ou usar Gentoo?
[pedido] biglinux versao 1 (0)
A falsa sensação de que entende a tal da palavra! (1)
Eu aprendi o segredo das artes! hahaha (5)









