-
Notifications
You must be signed in to change notification settings - Fork 0
/
mcdel.c
44 lines (40 loc) · 1.02 KB
/
mcdel.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
// mcdel.c
// Created by Larry Williamson and Grant Garrett on 12/10/14
#include "csapp.h"
#define BUF_SIZE 256
int main(int argc, char **argv)
{
/* establish connection */
char *host, filename[80];
int clientfd, port;
unsigned int secretKey, requestType;
if (argc != 5)
{
fprintf(stderr, "usage: %s <host> <port> <secret key> <filename>\n", argv[0]);
exit(0);
}
host = argv[1];
port = atoi(argv[2]);
secretKey = htonl(atoi(argv[3]));
requestType = htonl(2);
strcpy(filename, argv[4]);
clientfd = Open_clientfd(host, port);
/* end connection setup */
/* send parameters to server */
Rio_writen(clientfd, &secretKey, sizeof(unsigned int));
Rio_writen(clientfd, &requestType, sizeof(unsigned int));
Rio_writen(clientfd, filename, 80);
/* end parameter send */
/* get return status and end connection */
unsigned int status;
Rio_readn(clientfd, &status, sizeof(unsigned int));
/*
if (status != 0)
{
printf("Error\n");
}
*/
Close(clientfd);
exit(0);
/* connection closed */
}