-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathDeveloper.c
More file actions
119 lines (102 loc) · 2.72 KB
/
Developer.c
File metadata and controls
119 lines (102 loc) · 2.72 KB
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
// 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;
}
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;
char bugId[10];
//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{
printf("\nEnter Bug Id: ");
scanf("%s",bugId);
clearBuf(net_buf);
strcpy(net_buf,bugId);
sendto(sockfd, net_buf, NET_BUF_SIZE,
sendrecvflag, (struct sockaddr*)&addr_con,
addrlen);
return 0;
}
}
}