forked from abhijit13/Notification-Junction
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdummytcp.c
82 lines (71 loc) · 1.94 KB
/
dummytcp.c
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
/* The file contains code for dummy application that registers with NJ, request for notification and then unregisters from NJ using non-block library. */
#include "lib.h"
char str[512];
int times,i;
FILE* pidfd;
int fd;
char pidfilename[64];
char filebuffer[128];
/* SIGNAL HANDLER FOR SIGUSR1 SINGAL THAT IS SENT FORM NJ WHEN NOTIFICATION ARRIVES */
void sigusrhandler(int signum)
{
char ch;
if (signum == SIGUSR1) {
times++;
if(times == 1) {
if (!(pidfd = fopen(pidfilename, "r+"))) {
perror("dummyapp2.C : not able to open dummyapp file\n");
return;
}
}
printf("received SIGUSR1 %d \n\n\n",times);
i = 0;
printf("Signalhandler Notification is - ");
while(fgets(filebuffer, 1024, pidfd)) {
printf(" %s \n",filebuffer);
}
//scanf("%c", &ch);
return;
//exit(0);
}
}
int main(int argc, char *argv[])
{
struct stat s;
int pid;
char arr[512];
times = 0;
if (argc < 2) {
printf("Kindly enter the directory\n");
exit(0);
}
strcpy(arr, "npname::tcpdump##devicename::");
strcat(arr, argv[1]); // The directory to be watched.
strcat(arr, "##num_packets::");
strcat(arr, argv[2]);
strcat(arr, "##count::1");
printf("Arr is %s\n", arr);
pid = getpid();
sprintf(str, "%d", pid );
strcpy(pidfilename,str);
strcat(pidfilename, ".txt");
signal(SIGUSR1, sigusrhandler);
sigset_t mask;
sigemptyset(&mask);
sigaddset(&mask, SIGUSR1);
printf(" Dummy app signal handler set\n");
//sigprocmask (SIG_UNBLOCK, &mask, NULL);
sprintf(str, "%d", pid);
strcat(str, "::tcpdump");
appRegister(str); /* Application registers with inotify */
printf("Dummy app app register done\n");
printf("DUMMYAPP : Sending pid = %d\n", pid);
appGetnotify(pid, arr, 'B');
/* Application request for notification from inotify */
printf("Dummy app getnotify done \n");
//sigsuspend(&mask);
while (1);
//printf("*"); /* Loop to make application wait for notification */
printf("dummy app sigsuspend recieved\n");
return 0;
}