-
Notifications
You must be signed in to change notification settings - Fork 0
/
internet_check.cc
54 lines (45 loc) · 1.06 KB
/
internet_check.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#include <stdio.h>
#include <ctype.h>
#include <unistd.h>
#define VC_EXTRALEAN
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#include <wininet.h>
int main(int argc, char **argv) {
int vflag = 0;
int eflag = 0;
int c;
DWORD flags;
int rc;
BOOL isConnected;
setbuf(stdout, NULL);
while ((c = getopt (argc, argv, "hev")) != -1) {
switch (c) {
case 'h':
printf("internet check, v1.0\n");
printf("https://github.com/denisdemaisbr/internet_check\n");
printf("usage:\n");
printf("\t-h = this help\n");
printf("\t-v = verbose\n");
printf("\t-e = extended code\n");
printf("\n");
printf("BUILD: %s %s\n", __DATE__, __TIME__);
#ifdef __GNUC__
printf("GCC: %d.%d\n", __GNUC__, __GNUC_MINOR__);
#endif
printf("\n\n");
exit(0);
case 'v': vflag=1; break;
case 'e': eflag=1; break;
default:
abort();
}
}
isConnected = InternetGetConnectedState(&flags, 0);
rc = (isConnected) ? 1 : 0;
if (vflag)
printf("%s", (rc == 1) ? "online" : "offline");
if (eflag)
rc = (argc == 1) ? 1 : flags;
exit(rc);
}