GTK+ Forums

Discussion forum for GTK+ and Programming. Ask questions, troubleshoot problems, view and post example code, or express your opinions.
It is currently Sun Apr 20, 2014 11:29 pm

All times are UTC




Post new topic Reply to topic  [ 1 post ] 
Author Message
 Post subject: how to know server is down
PostPosted: Wed Mar 07, 2007 1:52 pm 
Offline
GTK+ Guru

Joined: Thu Nov 16, 2006 5:08 am
Posts: 259
Location: INDIA
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


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 1 post ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 5 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group