PDA

Visualizza la versione completa : perchè non mi si connette al server?


sys14
05-04-2011, 22:04
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <arpa/inet.h>
#include <netinet/in.h>

void inet_all (struct sockaddr_in *data, int port, long int ip);

int main (void) {
int sock;
struct sockaddr_in info;
inet_all(&info, 6669, inet_addr("pierotofy1.no-ip.org"));
sock = socket(AF_INET, SOCK_STREAM, 0);
if (sock < 0) {
puts("Error to created a socket");
exit(EXIT_FAILURE);
}
if (connect(sock, (struct sockaddr *) &info, sizeof(struct sockaddr)) < 0) {
puts("Error to connected at the server");
exit(EXIT_FAILURE);
}
close(sock);
return 0;
}

void inet_all (struct sockaddr_in *data, int port, long int ip) {
data->sin_family = AF_INET;
data->sin_port = htons(port);
data->sin_addr.s_addr = ip;
return;
}Dove sbaglio?

alka
05-04-2011, 22:54
Manca linguaggio ed errore riscontrato, come da Regolamento (http://forum.html.it/forum/showthread.php?s=&threadid=973887).

Loading