GTK+ Forums

Discussion forum for GTK+ and Programming. Ask questions, troubleshoot problems, view and post example code, or express your opinions.
It is currently Wed Aug 31, 2016 2:18 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 
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;
return 0;

int netstate()
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 ("") == -1)
printf ("Failed to reach\n");
printf ("Successfully reached\n");
fprintf (stderr, "%s(): Network connectivity not available \n", __func__);
printf ("U r net is down \n");
return -1;


main (int argc, char *argv[])


int i;
(GtkFunction) netstate,

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 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

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: Google [Bot], Yahoo [Bot] and 7 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