summaryrefslogtreecommitdiffabout
path: root/pumpkin/TFTPPacket.h
authorMichael Krelin <hacker@klever.net>2012-12-08 21:19:17 (UTC)
committer Michael Krelin <hacker@klever.net>2012-12-11 21:59:29 (UTC)
commit8808689fe340bec6e90ab13dd502292b0579cf1f (patch) (unidiff)
tree45b7c863151341f687b74e40bffcbd7ab5468783 /pumpkin/TFTPPacket.h
parent6e7e413ca364d79673e523c09767c18e7cff1bec (diff)
downloadpumpkin-osx/0.0.zip
pumpkin-osx/0.0.tar.gz
pumpkin-osx/0.0.tar.bz2
initial osx portosx/0.0
Signed-off-by: Michael Krelin <hacker@klever.net>
Diffstat (limited to 'pumpkin/TFTPPacket.h') (more/less context) (ignore whitespace changes)
-rw-r--r--pumpkin/TFTPPacket.h87
1 files changed, 87 insertions, 0 deletions
diff --git a/pumpkin/TFTPPacket.h b/pumpkin/TFTPPacket.h
new file mode 100644
index 0000000..a46d5bc
--- a/dev/null
+++ b/pumpkin/TFTPPacket.h
@@ -0,0 +1,87 @@
1
2#import <Cocoa/Cocoa.h>
3#include <stdint.h>
4
5enum TFTPOp {
6 tftpOpRRQ=1, tftpOpWRQ=2,
7 tftpOpDATA=3,
8 tftpOpACK=4,
9 tftpOpERROR=5,
10 tftpOpOACK=6
11};
12
13enum TFTPError {
14 tftpErrUndefined=0,
15 tftpErrNotFound=1,
16 tftpErrAccessViolation=2,
17 tftpErrDiskFull=3,
18 tftpErrIllegalOp=4,
19 tftpErrUnknownTID=5,
20 tftpErrFileExists=6,
21 tftpErrNoUser=7,
22 tftpErrOption=8
23};
24
25#pragma pack(push,1)
26struct AnyTFTPPacket {
27 uint16_t op;
28 union {
29 struct {
30 char data[1];
31 } any;
32 struct {
33 char data[1];
34 } rq;
35 struct {
36 char data[1];
37 } rrq;
38 struct {
39 char data[1];
40 } wrq;
41 struct {
42 uint16_t block;
43 char data[1];
44 } data;
45 struct {
46 uint16_t block;
47 } ack;
48 struct {
49 uint16_t code;
50 char data[1];
51 } err;
52 struct {
53 char data[1];
54 } oack;
55 };
56};
57#pragma pack(pop)
58
59@interface TFTPPacket : NSObject {
60 NSData *data;
61 struct AnyTFTPPacket *packet;
62}
63
64@property (readonly) enum TFTPOp op;
65@property (readonly) NSString* rqFilename;
66@property (readonly) NSString* rqType;
67@property (readonly) NSDictionary* rqOptions;
68@property (readonly) NSData *data;
69@property (readonly) uint16_t block;
70@property (readonly) NSData *rqData;
71@property (readonly) uint16_t rqCode;
72@property (readonly) NSString* rqMessage;
73
74-(TFTPPacket*)initWithData:(NSData*)d;
75
76+(TFTPPacket*)packetWithData:(NSData*)d;
77+(TFTPPacket*)packetWithBytesNoCopy:(void*)b andLength:(size_t)l;
78
79+(TFTPPacket*)packetErrorWithCode:(enum TFTPError)c andMessage:(NSString*)m;
80+(TFTPPacket*)packetErrorWithErrno:(int)en andFallback:(NSString*)fb;
81+(TFTPPacket*)packetOACKWithOptions:(NSDictionary*)o;
82+(TFTPPacket*)packetDataWithBlock:(uint16_t)b andData:(NSData*)d;
83+(TFTPPacket*)packetACKWithBlock:(uint16_t)b;
84+(TFTPPacket*)packetRRQWithFile:(NSString*)f xferType:(NSString*)t andOptions:(NSDictionary*)o;
85+(TFTPPacket*)packetWRQWithFile:(NSString*)f xferType:(NSString*)t andOptions:(NSDictionary*)o;
86
87@end