-
Double posted and asked some further nonsense, haha. Sorry for the hassle.
Now, after having spent my time modularizing the whole program, my main looks like this:
Code:
int main()
{
FILE* fp;
{
printf("\n Escribe la ruta del documento deseado: ");
scanf("%s", x);
printf("\n");
fp = fopen(x, "r");
if (fp == NULL)
{
printf("\n El archivo no se ha podido encontrar\n\n");
exit(0);
}
while (fgets(ch, sizeof(ch), fp))
{
printf("%s", ch);
}
printf("\n");
fclose(fp);
leerAdaptadores();
leerIpsValidas();
comparativaIps();
extraerDNS();
comparativaDNS();
}
}
So far, so good.
The DNS extraction works perfect. I've that "dns_responden.txt" filled with the data I need, i.e. DNS lined one after the other with line breaks among them, just like my "ip_responden.txt" file I needed for "comparativaIps()":
Code:
void comparativaIps()
{
int best_response = 0;
char ipresp[100], best_ip[sizeof(ipresp)] = "";
int best_valid = 0;
FILE* responses = fopen("ips_responden.txt", "r");
if (responses != NULL)
{
while (fgets(ipresp, sizeof(ipresp), responses))
{
int response1 = velocidad_media(ipresp);
if (!best_valid || response1 < best_response) {
best_response = response1;
strcpy(best_ip, ipresp);
best_valid = 1;
}
}
printf("\n IP seleccionada: %s", best_ip);
printf("\n Velocidad de respuesta media: %d ms.\n", best_response);
fclose(responses);
}
}
As for the "comparativaDNS()" block, it's just the same as "comparativaIps()" and still unable to print what I expect to do...:
Code:
void comparativaDNS()
{
int best_response_time = 0;
char ip_str[100], best_dns[sizeof(ip_str)] = "";
int best_valid_dns = 0;
FILE* responsesdns = fopen("dns_responden.txt", "r");
if (responsesdns != NULL)
{
while (fgets(ip_str, sizeof(ip_str), responsesdns))
{
int dns1 = velocidad_media(ip_str);
if (!best_valid_dns || dns1 < best_response_time) {
best_response_time = dns1;
strcpy(best_dns, ip_str);
best_valid_dns = 1;
}
}
printf("\n\n Velocidad de respuesta media: %d ms.\n", best_response_time);
printf("\n DNS seleccionada: %s", best_dns);
}
}
-
Got it on my own! My extraction of DNS servers lacked a fclose at the end of it. :wink: I was close to insanity...
-
Now, and this is the final part of my project: once I've got the best response for both my IP's and DNS servers, I must compare them and, if IP shows a faster time of response, replace the DNS server of such network interface that lost the comparison.
Once modularized, I need to call the variables within different modules to compare them:
Code:
leerIpsValidas();
printf("\n\n");
comparativaIps();
extraerDNS();
printf("\n");
comparativaDNS();
if (best_response_time > best_response)
blah blah...
best_response_time belongs to the comparativaDNS module and best_response to comparativaIps. Not sure how to invoke them back from main.
And one final thing, which troubles me the most. I'd selected the network interface before, in the "leerAdaptadores" module, with a number ("adaptador" variable) that got me a system command like "netsh interface ipv4 show dnsservers adaptador" for the DNS server extraction. The system call to replace a given DNS server would be something like "netsh interface ipv4 set dns name=adaptador static best_response", but instead of a number, a full string of text with the name of such interface. How can I omit this approach, so I'm able to omit special characters such as Conexión?
-
Ha, finally I've gone through it - seems like numbers also worked with that, and the value of my variable was used as well.
I'm finally done with this project. Thanks A LOT anyone who provided help - much appreciated!