-
Notifications
You must be signed in to change notification settings - Fork 1
/
xmodemserver.h
52 lines (45 loc) · 1.55 KB
/
xmodemserver.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
/* This header file should be included in your xmodemserver.c file.
* You are welcome to add to it.
*/
/* Enumeration constants are similar to constants created with #define
* It is a nice way of being able to give a name to a state in this case.
* For example, you can use the enum below as follows:
* //first declare a variable:
* enum recstate state;
* //then give it a value (note that the value is not a string)
* state = check_block;
*/
#include <stdio.h>
enum recstate {
initial,
pre_block,
get_block,
check_block,
finished
};
//Helper functions
void bindandlisten();
void newconnection();
static void removeclient(int soc);
static void addclient(int soc);
/* The client struct contains the state that the server needs for each client.
*/
struct client {
int fd; // socket descriptor for this client
char buf[2048]; // buffer to hold data being read from client
int inbuf; // index into buf
char filename[20]; // name of the file being transferred
FILE *fp; // file pointer for where the file is written to
enum recstate state; // current state of data transfer for this client
int blocksize; // the size of the current block
int current_block; // the block number of the current block
struct client *next; // a pointer to the next client in the list
};
#define XMODEM_KEY 0x1021
//ASCII characters
#define SOH 1
#define STX 2
#define EOT 4
#define ACK 6
#define NAK 21
#define CAN 24