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) (side-by-side diff)
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 @@
+
+#import <Cocoa/Cocoa.h>
+#include <stdint.h>
+
+enum TFTPOp {
+ tftpOpRRQ=1, tftpOpWRQ=2,
+ tftpOpDATA=3,
+ tftpOpACK=4,
+ tftpOpERROR=5,
+ tftpOpOACK=6
+};
+
+enum TFTPError {
+ tftpErrUndefined=0,
+ tftpErrNotFound=1,
+ tftpErrAccessViolation=2,
+ tftpErrDiskFull=3,
+ tftpErrIllegalOp=4,
+ tftpErrUnknownTID=5,
+ tftpErrFileExists=6,
+ tftpErrNoUser=7,
+ tftpErrOption=8
+};
+
+#pragma pack(push,1)
+struct AnyTFTPPacket {
+ uint16_t op;
+ union {
+ struct {
+ char data[1];
+ } any;
+ struct {
+ char data[1];
+ } rq;
+ struct {
+ char data[1];
+ } rrq;
+ struct {
+ char data[1];
+ } wrq;
+ struct {
+ uint16_t block;
+ char data[1];
+ } data;
+ struct {
+ uint16_t block;
+ } ack;
+ struct {
+ uint16_t code;
+ char data[1];
+ } err;
+ struct {
+ char data[1];
+ } oack;
+ };
+};
+#pragma pack(pop)
+
+@interface TFTPPacket : NSObject {
+ NSData *data;
+ struct AnyTFTPPacket *packet;
+}
+
+@property (readonly) enum TFTPOp op;
+@property (readonly) NSString* rqFilename;
+@property (readonly) NSString* rqType;
+@property (readonly) NSDictionary* rqOptions;
+@property (readonly) NSData *data;
+@property (readonly) uint16_t block;
+@property (readonly) NSData *rqData;
+@property (readonly) uint16_t rqCode;
+@property (readonly) NSString* rqMessage;
+
+-(TFTPPacket*)initWithData:(NSData*)d;
+
++(TFTPPacket*)packetWithData:(NSData*)d;
++(TFTPPacket*)packetWithBytesNoCopy:(void*)b andLength:(size_t)l;
+
++(TFTPPacket*)packetErrorWithCode:(enum TFTPError)c andMessage:(NSString*)m;
++(TFTPPacket*)packetErrorWithErrno:(int)en andFallback:(NSString*)fb;
++(TFTPPacket*)packetOACKWithOptions:(NSDictionary*)o;
++(TFTPPacket*)packetDataWithBlock:(uint16_t)b andData:(NSData*)d;
++(TFTPPacket*)packetACKWithBlock:(uint16_t)b;
++(TFTPPacket*)packetRRQWithFile:(NSString*)f xferType:(NSString*)t andOptions:(NSDictionary*)o;
++(TFTPPacket*)packetWRQWithFile:(NSString*)f xferType:(NSString*)t andOptions:(NSDictionary*)o;
+
+@end