-
Notifications
You must be signed in to change notification settings - Fork 0
/
Tester.c
183 lines (149 loc) · 3.77 KB
/
Tester.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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
// client code for UDP socket programming
#include <arpa/inet.h>
#include <netinet/in.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/socket.h>
#include <sys/types.h>
#include <unistd.h>
#include "login.h"
#include <time.h>
#define IP_PROTOCOL 0
#define IP_ADDRESS "127.0.0.1" // localhost
#define PORT_NO 15050
#define NET_BUF_SIZE 2048
#define cipherKey 'S'
#define sendrecvflag 0
// function to clear buffer
void clearBuf(char* b)
{
int i;
for (i = 0; i < NET_BUF_SIZE; i++)
b[i] = '\0';
}
// function for decryption
char Cipher(char ch)
{
return ch ^ cipherKey;
}
// function to receive file
int recvFile(char* buf, int s)
{
int i;
char ch;
printf("\n");
printf("Status Bug ID Bug Name Date Reported Created By Assigned To\n");
printf("---------------------------------------------------------------------\n");
for (i = 0; i < s; i++) {
ch = buf[i];
ch = Cipher(ch);
if (ch == EOF)
return 1;
else
printf("%c",ch);
}
return 0;
}
// driver code
int main(int argc,char** argv)
{
int sockfd, nBytes;
struct sockaddr_in addr_con;
int addrlen = sizeof(addr_con);
addr_con.sin_family = AF_INET;
addr_con.sin_port = htons(PORT_NO);
addr_con.sin_addr.s_addr = inet_addr(IP_ADDRESS);
char net_buf[NET_BUF_SIZE];
FILE* fp;
//user login
char *res=login();
if(strlen(res)==6){
// socket()
sockfd = socket(AF_INET, SOCK_DGRAM,
IP_PROTOCOL);
if (sockfd < 0)
printf("\nConnection denied\n");
else
{
sendto(sockfd, res, sizeof(res),
sendrecvflag, (struct sockaddr*)&addr_con,
addrlen);
}
if (strcmp(argv[1],"view")==0){
strcpy(net_buf,"null");
sendto(sockfd, net_buf, NET_BUF_SIZE,
sendrecvflag, (struct sockaddr*)&addr_con,
addrlen);
while (1) {
// receive
clearBuf(net_buf);
nBytes = recvfrom(sockfd, net_buf, NET_BUF_SIZE,
sendrecvflag, (struct sockaddr*)&addr_con,
&addrlen);
// process
if (recvFile(net_buf, NET_BUF_SIZE)) {
break;
}
return 0;
}
}
else
{
char bugName[20];
int bugIdSequence;
char bugIdSequenceStirng[20];
char bugId[4];
char reportingDate[30];
char reportingTesterId[10];
char assignedToDeveloperId[]="null";
char bugStatus[]="new";
printf("\nPlease enter bug details:\n");
scanf("%s", bugName);
//creating bug info stroing format
strcpy(net_buf,bugStatus);
strcat(net_buf," ");
srand((unsigned int)time(NULL));
strcpy(bugId,"B");
bugIdSequence=rand()%900+100;
sprintf(bugIdSequenceStirng, "%d", bugIdSequence);
strcat(bugId,bugIdSequenceStirng);
strcat(net_buf,bugId);
strcat(net_buf," ");
strcat(net_buf,bugName);
strcat(net_buf," ");
//getting current date
time_t t = time(NULL);
struct tm tm = *localtime(&t);
char yearString[10];
char monthString[10];
char dayString[10];
sprintf(dayString, "%d", tm.tm_mday);
strcpy(reportingDate,dayString);
strcat(reportingDate,"/");
sprintf(monthString, "%d", tm.tm_mon + 1);
strcat(reportingDate,monthString);
strcat(reportingDate,"/");
sprintf(yearString, "%d", tm.tm_year + 1900);
strcat(reportingDate,yearString);
strcat(net_buf,reportingDate);
strcat(net_buf," ");
strcpy(reportingTesterId,res);
strcat(net_buf,reportingTesterId);
strcat(net_buf," ");
strcat(net_buf,assignedToDeveloperId);
sendto(sockfd, net_buf, NET_BUF_SIZE,
sendrecvflag, (struct sockaddr*)&addr_con,
addrlen);
//for clearing the values
strcpy(net_buf,"");
strcpy(bugIdSequenceStirng,"");
strcpy(bugId,"");
printf("\nBug reported\n");
}
}
else{
printf("Invalid credentials");
}
return 0;
}