0

How can i check internet connection in c++ or c, i'm using mac & cant find a good way. If

possible i want to check internet connection constantly' so i can save the users data.

Please provide me with examples, information and ideas.

THanks!

user1262876
  • 31
  • 1
  • 7

2 Answers2

3

Call system("ping www.google.com").

If the process dies or becomes slow, then your internet connection is doing badly.

SecurityMatt
  • 6,593
  • 1
  • 22
  • 28
  • This is a very good answer, but how can i get the return of the result? should i use pipe ...or? any example please.. – user1262876 Mar 11 '12 at 22:29
  • If you're in C++ you should be able to connect to the stdout of the process, which will return a line of text every time a ping succeeds. – SecurityMatt Mar 11 '12 at 23:38
  • There was some statistic that google is used by majority of people to check whether internet connection is up or not rather than actual search :) – user138645 Mar 13 '12 at 06:00
  • Note that many schools and businesses block ping packets. Also, if google goes out of business or renames itself, this may fail in future. – DavidJ Sep 20 '17 at 21:46
1

You can try implementing a lightweight ICMP to ping a remote host periodically.

Maybe this question can shed some light: Mac network ping source code compile error

Community
  • 1
  • 1
torrential coding
  • 1,755
  • 2
  • 24
  • 34