I was writing my first client in C when I reached the point where I have to send a socket to the server. When i try to get its address I get a
Resource temporarily unavailable
and I can't find what is causing this problem.
dadesSoftConfig->ipServer has inside localhost
struct hostent *ent;
ent = gethostbyname(dadesSoftConfig->ipServidor);
if (ent == NULL) {
int errnum = errno;
fprintf(stderr, "Client finalitzat: %s\n", strerror(errnum));
exit(EXIT_FAILURE);
}
I do not send any socket, wait for any data yet when I do this call , this is happening at the very beginning, even before the register phase of my protocol.
As requested, this is a print of the dadesSoftConfig:
DEBUG_INFO: Nom: SW-01
Mac: 89F107457A36
Server: localhost
Server-port: 2019
And this is how I print it:
void print_software_configuration(TDadesSoftConfig *dades) {
char *msg;
msg = (char *) malloc(sizeof(char) * 75);
if (sprintf(msg, "\tNom: %s \t\tMac: %s \t\tServer: %s \t\tServer-port: %d\n",
dades->nom, dades->mac, dades->ipServidor, dades->serverPort) < 0) {
fprintf(stderr, "No s'ha pogut mostrar el contingut llegit\n");
} else {
print_debug_info(msg);
}
free(msg);
}
I tried sending "127.0.0.1" to gethostbyname() function and the code perfectly works, even when I store it to my struct. Any idea why it doesn't work when sending "localhost"?