PDA

Visualizza la versione completa : [C] non mi di connette al server


sys14
06-04-2011, 07:16
#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;
}
Provando ad eseguire questo codice mi esce sempre il messaggio Error to connected at the server. Dove sbaglio?

sys14
06-04-2011, 18:04
qualcuno mi puņ rispondere cortesemente?

Loading