GTK+ Forums Forum Index GTK+ Forums
Discussion forum for GTK+ and Programming. Ask questions, troubleshoot problems, view and post example code, or express your opinions.
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

how to know server is down

 
Post new topic   Reply to topic    GTK+ Forums Forum Index -> GTK+ Programming
Author Message
ramesh
Familiar Face


Joined: 16 Nov 2006
Posts: 40

PostPosted: Wed Mar 07, 2007 1:52 pm    Post subject: how to know server is down Reply with quote

hi all
this is the code to know wether the net on or off


#include <stdio.h>
#include <unistd.h>
#include <netdb.h>
#include <gtk/gtk.h>
#include <stdlib.h>
#include <string.h>

int can_resolve_host (const char *host)
{
struct hostent *h = NULL;
h = gethostbyname (host);

if (h == NULL)
{
return -1;
}
else
{
return 0;
}
}

int netstate()
{
FILE* FD;
char buf[256] = {0};
char* linkstatus = NULL;

FD = popen ("/sbin/mii-tool", "r");

if (FD)
{
fgets (buf, sizeof (buf), FD);
buf[strlen(buf) - 1] = '\0';
linkstatus = strstr (buf, "ok");
}

pclose (FD);
if ((linkstatus) && (0 == strcmp (linkstatus, "ok")))
{
if (can_resolve_host ("axillsearch.com") == -1)
{
printf ("Failed to reach axillsearch.com\n");
}
else
{
printf ("Successfully reached axillsearch.com\n");
}
}
else
fprintf (stderr, "%s(): Network connectivity not available \n", __func__);
printf ("U r net is down \n");
return -1;

}

int
main (int argc, char *argv[])

{

int i;
i=gtk_timeout_add(8000,
(GtkFunction) netstate,
NULL);

gtk_main ();
return 0;
}
save it has one.c
and compile
gcc one.c -o one `pkg-config gtk+-2.0 --cflags --libs`


it is working successfully
when
1.net deactivate or activate
2.cable unplugged or plugged

but it is not working when the server is down

how can i do when the server is down

when the serveris down(main servers)
it has to show the message like
"U r net is down \n"

if any help
cheers
Back to top
Display posts from previous:   
Post new topic   Reply to topic    GTK+ Forums Forum Index -> GTK+ Programming All times are GMT
Page 1 of 1

 


Powered by phpBB © 2001, 2005 phpBB Group
CodeBB 1.0 Beta 2
Protected by Anti-Spam ACP