File: pppsubs.c

package info (click to toggle)
pppupd 0.23-6
  • links: PTS
  • area: main
  • in suites: hamm
  • size: 96 kB
  • ctags: 39
  • sloc: ansic: 399; makefile: 50; sh: 49; perl: 43
file content (123 lines) | stat: -rw-r--r-- 2,980 bytes parent folder | download
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
/*
 * PPPupd - pppsubs.c - misc subroutines for PPPupd.
 * Jake Bouvrie <swarthy@thetasys.com>
 * Fri Jan 26 04:11:01 EST 1996
 */

#include	"pppupd.h"

extern	int	outlog;
extern	FILE	*logfile;

int	PPPConnect(OPT	*options)
{
	char	cmd[255];
	FILE	*foo = NULL;
	
	if (outlog) {
		system("date");
		fprintf(stderr, "Attempting to connect... \n");
	}
	fprintf(logfile , "Attempting to connect... \n");
	strcpy(cmd, options->connectscriptpath);
	strcat(cmd, " &");
	if (system(cmd)) {
		sleep(30);
		if ( (foo = fopen(options->logpath, "r")) != NULL ) {
			fclose(foo);
			if (outlog)
				fprintf(stderr, "Connection Reestablished\n");
			fprintf(logfile, "Connection Reestablished\n");
			return 0;
		}
		else {
			if (outlog)
                                fprintf(stderr, "Connection could NOT be Reestablished\n");
                        fprintf(logfile, "Connection could NOT be Reestablished\n");
                        return -1;
		}
	}
	else
		return -1;
}

int	PPPConnectTest(OPT	*options)
{
	struct hostent	*host = NULL;
	FILE		*foo = NULL;

	host = gethostbyname(options->pingaddr);
	if (host == NULL) {
		if (outlog)
			fprintf(stderr, "Lost Connection. [%s]", getdate());
		fprintf(logfile, "LostConnection. [%s]", getdate());
		return 1;
	}
	else
#ifdef _DEBUG_
		printf("Hostlookup worked\n");
		if ( logfile != NULL)
			fprintf(logfile, "Hostlookup worked\n");
		else
			printf("Arg! Log file is NULL!\n");
#endif
		if ((foo = fopen(options->pidpath, "r")) == NULL) {
			if (outlog)
				fprintf(stderr, "Lost Connection. [%s]", getdate());
			fprintf(logfile, "LostConnection. [%s]", getdate());
			return 1;
		}
		else
			fclose(foo);
		return 0; 
}

int	PPPSendPing(OPT	*options)
{
        int     pid, exitcode;
	pid_t	wait();
#ifdef _DEBUG_
        printf("******PING PATH: %s\n", options->pingpath);
#endif
        pid = fork();
        if (pid == 0) {
                execl(options->pingpath, "ping", "-c", "1", options->pingaddr, NULL);
                exit(-1);
        }
         signal(SIGINT, SIG_IGN);
         signal(SIGQUIT, SIG_IGN);
         while( wait( &exitcode ) != pid )
                ;
         signal( SIGINT, SIG_DFL );
         signal( SIGQUIT, SIG_DFL );
#ifdef _DEBUG_
        printf("*******EXIT CODE: %d\n", exitcode);
#endif
        if (exitcode != 0)  {
                if (outlog)
                        fprintf(stderr, "J00 ping failed! We lost connection. [%s]", getdate());
                fprintf(logfile, "J00 ping failed! We lost connection. [%s]", getdate());
                return 1;
        }
        else
                return 0;
}

int	PPPKill(char	*killscriptpath)
{
	char    cmd[255];

        strcpy(cmd, killscriptpath);
        strcat(cmd, " &");
        if (system(cmd)) {
		if (outlog) {
			system("date");
			fprintf(stderr, "Killed connection. [%s]", getdate());
		}
		fprintf(logfile,"Killed connection. [%s]", getdate());
		sleep(5);
                return 0;
	}
        else
                return -1;
}