about summary refs log tree commit diff stats
path: root/inc/packet.h
blob: a404d495c0bc6186e3209a362bcc0c13996dcfa7 (plain) (blame)
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
#ifndef NBD_TFTP_PACKET_H
#define NBD_TFTP_PACKET_H

#include <stdint.h>
#include <unistd.h>

typedef enum {
	RRQ	= 1,
	WRQ	= 2,
	DAT	= 3,
	ACK	= 4,
	ERR	= 5,
} nbd_tftp_opcode;

typedef enum {
	ERROR		= 0,
	ENOTFOUND	= 1,
	EACCESS		= 2,
	ENOSPACE	= 3,
	EOPERATION	= 4,
	ETRANS		= 5,
	EEXISTS		= 6,
	EUSER		= 7,
} nbd_tftp_ecode;

typedef struct {
	uint16_t opcode;
	char *filename;
	char *mode;
} nbd_tftp_packet_rq;

typedef struct {
	uint16_t opcode;
	uint16_t block_num;
	char *data;
	size_t datalen;
} nbd_tftp_packet_data;

typedef struct {
	uint16_t opcode;
	uint16_t block_num;
} nbd_tftp_packet_ack;

typedef struct {
	uint16_t opcode;
	uint16_t err;
	char *emsg;
} nbd_tftp_packet_error;

char *nbd_tftp_error_to_message(nbd_tftp_ecode error);
char *nbd_tftp_ser_data(nbd_tftp_packet_data d);
char *nbd_tftp_ser_data_from_parts(uint16_t blocknum, char *data, size_t datalen);
nbd_tftp_packet_ack nbd_tftp_de_ack(char *buf, ssize_t buflen);

#endif