forked from NavroopKaur/Notification-Junction
-
Notifications
You must be signed in to change notification settings - Fork 20
/
stats.c
110 lines (92 loc) · 3.04 KB
/
stats.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
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
/*
Notification-Junction is an interface between multiple applications and multiple Notification Providers.
Copyright (C) 2015 Navroop Kaur<[email protected]>,
Shivani Marathe<[email protected]>,
Kaveri Sangale<[email protected]>
All Rights Reserved.
This program is free software; you can redistribute it and/or modify it under the terms of the
GNU General Public License as published by the Free Software Foundation; either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with this program; if not, write to the
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
/*
* The function of this command is to print the registrations and related details, as listed below -
* NPs registered
* For every NP, print the count of apps registered with it
* Table - NP - Count of Apps
* Apps registered and the NPs they have registered with
* Table - App - Pid - Registered with
*
* Add as is thought
*
* The idea is to extract the details from the lists in the NJ.
*
*/
#include <sys/types.h>
#include <stdlib.h>
#include <sys/socket.h>
#include <sys/un.h>
#include <stdio.h>
#define NAME "./statsock"
#define StatSocketPrint "./statsockprint"
#define QLEN 32
int main(int argc, char *argv[])
{
int sock, retval = 0, sock_read, msgsock;
struct sockaddr_un server, server2;
char data[1024];
strcpy(data, argv[0]);
if (argc != 1) {
printf("Usage - ./%s\n", argv[0]);
exit(1);
}
sock_read = socket(AF_UNIX, SOCK_STREAM, 0);
if (sock_read < 0) {
perror("opening stream socket");
exit(EXIT_FAILURE);
}
server2.sun_family = AF_UNIX;
strcpy(server2.sun_path, StatSocketPrint);
if (bind(sock_read, (struct sockaddr *)&server2, sizeof(struct sockaddr_un))) {
perror("binding stream socket");
exit(EXIT_FAILURE);
}
if(listen(sock_read, QLEN) != 0 ) {
perror("Error in listening on stat socket");
}
sock = socket(AF_UNIX, SOCK_STREAM, 0);
if (sock < 0) {
perror("STATS : Opening Stream Socket");
exit(1);
}
server.sun_family = AF_UNIX;
strcpy(server.sun_path, NAME);
if (connect
(sock, (struct sockaddr *)&server,
sizeof(struct sockaddr_un)) < 0) {
close(sock);
perror("STATS : Connecting Stream Socket");
exit(1);
}
if (write(sock, data, sizeof(data)) < 0)
perror("STATS : Writing On Stream Socket");
msgsock = accept(sock_read, 0, 0);
if (msgsock == -1)
perror(" Error accept on stat socket");
else
do {
bzero(data, sizeof(data));
if ((retval = read(msgsock, data, 1024)) < 0)
perror("NJ.C : reading stream message");
else {
printf("%s", data);
}
} while (retval > 0);
close(sock);
close(sock_read);
return 0;
}