-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcommon.h
89 lines (63 loc) · 2.51 KB
/
common.h
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
#ifndef COMMON_H
#define COMMON_H
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <errno.h>
#include <sys/types.h>
#include <sys/time.h>
#include <sys/resource.h>
#include <sys/wait.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <unistd.h>
#include <netdb.h>
#include "tftp.h"
#define stshort(sval, addr) (*((unsigned short int *)(addr)) = htons(sval))
#define ldshort(addr) (ntohs (*((unsigned short int *)(addr))))
#define SHORT_SIZE sizeof(unsigned short int)
#define MAX_BUFFER 1024
#define PARAMS_TEXT_SIZE 50
#define TRIVIALD 1
#define TRIVIAL 2
struct PARAMS
{
int sc;
int port;
int verbose;
int rexmt;
int read_write;
char host[PARAMS_TEXT_SIZE];
char file[PARAMS_TEXT_SIZE];
};
//====================
int create_socket(int domain, int type, int protocol);
int make_bind(int sockID, short int family, unsigned short int port, char *host);
//====================
void help(struct PARAMS *params);
void param_parser(int argc, char *argv[], struct PARAMS *params);
//====================
int rwq_serialize(tftp_rwq_hdr *rwq, char *buffer);
void rwq_deserialize(tftp_rwq_hdr *rwq, char *buffer);
int ack_serialize(tftp_ack_hdr *ack, char *buffer);
void ack_deserialize(tftp_ack_hdr *ack, char *buffer);
int data_serialize(tftp_data_hdr *data, char *buffer, int dsz);
void data_deserialize(tftp_data_hdr *data, char *buffer, int dsz);
int error_serialize(tftp_error_hdr *error, char *buffer);
void error_deserialize(tftp_error_hdr *error, char *buffer, int dsz);
//====================
int sendACKOpt(int sockID, struct sockaddr_in sockInfo, char *opt, int value);
int sendInfo(int sockID, struct sockaddr_in sockInfo, char *buffer, int sz);
int sendACK(int sockID, struct sockaddr_in sockInfo, unsigned short int ack);
int sendError(int sockID, struct sockaddr_in sockInfo, unsigned short int opcode, unsigned short int errcode, char *errtext);
//====================
int mode_transfer(char *modeFound, char *modeCorrect, struct PARAMS *params);
int timeout_option(tftp_rwq_hdr *rwq, struct PARAMS *params);
int get_data(tftp_data_hdr *data, int sockID, struct sockaddr_in sockInfo, struct PARAMS *param);
int get_ack(tftp_ack_hdr *ack, int sockID, struct sockaddr_in sockInfo, struct PARAMS *params);
int select_func(int sockID, int time);
FILE *open_file(char *fName, char *mode, struct PARAMS *params);
int file_exists(char *fName);
#endif