LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 04-14-2013, 12:23 PM   #1
Xeratul
Senior Member
 
Registered: Jun 2006
Location: UNIX
Distribution: FreeBSD
Posts: 2,657

Rep: Reputation: 255Reputation: 255Reputation: 255
Faster way to check if there is internet connection in C?


Hi,

I would like to check before doing some networking/backup stuffs that internet is available.
(c pure programming lang. (not in c++))

I could find some solution but arent adapted to Linux so much.
http://stackoverflow.com/questions/8...net-connection

Would you know the best way?

for instance, in bash, i use :
Code:
curl --silent --head http://www.google.com/  |egrep Found
libcurl is not portable much.

I would that it works as well under ms windows.

regards

Last edited by Xeratul; 04-14-2013 at 12:38 PM.
 
Old 04-14-2013, 02:27 PM   #2
mariostg
Member
 
Registered: Apr 2011
Location: Gatineau, Quebec
Distribution: OpenBSD
Posts: 80

Rep: Reputation: 5
Something like this? http://en.wikibooks.org/wiki/C_Progr...orking_in_UNIX

The Beej's guide is also often cited as C network programming reference http://beej.us/guide/bgnet/
 
Old 04-16-2013, 01:02 PM   #3
Xeratul
Senior Member
 
Registered: Jun 2006
Location: UNIX
Distribution: FreeBSD
Posts: 2,657

Original Poster
Rep: Reputation: 255Reputation: 255Reputation: 255
Quote:
Originally Posted by mariostg View Post
Something like this? http://en.wikibooks.org/wiki/C_Progr...orking_in_UNIX

The Beej's guide is also often cited as C network programming reference http://beej.us/guide/bgnet/
the quite problem is that which likely not working with a regular limited portable (windows / Unix ) env : gcc -lncurses simple.c

netinet is not into pdcurses.dll

Code:
#include <arpa/inet.h>
#include <sys/types.h>
#include <netinet/in.h>
#include <sys/socket.h>
It compiles well under debian.

I will try under windows... and let you know. lets cross fingers

Last edited by Xeratul; 04-16-2013 at 01:04 PM.
 
Old 04-16-2013, 04:41 PM   #4
dwhitney67
Senior Member
 
Registered: Jun 2006
Location: Maryland
Distribution: Kubuntu, Fedora, RHEL
Posts: 1,541

Rep: Reputation: 335Reputation: 335Reputation: 335Reputation: 335
Quote:
Originally Posted by Xeratul View Post
the quite problem is that which likely not working with a regular limited portable (windows / Unix ) env : gcc -lncurses simple.c

netinet is not into pdcurses.dll

Code:
#include <arpa/inet.h>
#include <sys/types.h>
#include <netinet/in.h>
#include <sys/socket.h>
It compiles well under debian.

I will try under windows... and let you know. lets cross fingers
I despise Windows, but unfortunately I to have to develop software that works under it. For Windoze, you will need a different header file, which I believe is winsock2.h (perhaps winsock.h?):
Code:
#ifdef WIN32    // works for 32- and 64-bit Visual Studio
        #include <winsock2.h>
#else
        #include <arpa/inet.h>
        #include <sys/types.h>
        #include <netinet/in.h>
        #include <sys/socket.h>
#endif
 
Old 04-17-2013, 12:27 AM   #5
Xeratul
Senior Member
 
Registered: Jun 2006
Location: UNIX
Distribution: FreeBSD
Posts: 2,657

Original Poster
Rep: Reputation: 255Reputation: 255Reputation: 255
Quote:
Originally Posted by dwhitney67 View Post
I despise Windows, but unfortunately I to have to develop software that works under it. For Windoze, you will need a different header file, which I believe is winsock2.h (perhaps winsock.h?):
Code:
#ifdef WIN32    // works for 32- and 64-bit Visual Studio
        #include <winsock2.h>
#else
        #include <arpa/inet.h>
        #include <sys/types.h>
        #include <netinet/in.h>
        #include <sys/socket.h>
#endif

hopefully we can do it without winock windoze and io stuffs

lets ... see.

we keep in touch since we have same concern: portability

I have made several functions that work for both platfomr: nix and win. we can chat
 
Old 04-17-2013, 07:39 PM   #6
mariostg
Member
 
Registered: Apr 2011
Location: Gatineau, Quebec
Distribution: OpenBSD
Posts: 80

Rep: Reputation: 5
Quote:
Originally Posted by Xeratul View Post
the quite problem is that which likely not working with a regular limited portable (windows / Unix ) env : gcc -lncurses simple.c

netinet is not into pdcurses.dll

Code:
#include <arpa/inet.h>
#include <sys/types.h>
#include <netinet/in.h>
#include <sys/socket.h>
It compiles well under debian.

I will try under windows... and let you know. lets cross fingers
Maybe I don't get the point, but curses has nothing to do with network stuff. lncurses is unique to *nixes if not mistaken though.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
The best way howto check internet connection every second or less? fandar Linux - Networking 0 02-13-2013 10:44 AM
Problem bash script to check the internet connection? shams Programming 9 10-28-2012 09:27 PM
Can I combine two internet connections to get a faster connection? gardenair Linux - Newbie 2 10-25-2010 02:19 AM
check if the internet connection is available. ALInux Linux - Networking 3 02-12-2006 05:05 AM
check internet connection in .bashrc mvo Linux - Newbie 2 11-26-2005 06:32 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 05:48 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration