-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtftp12.c
199 lines (187 loc) · 5.23 KB
/
tftp12.c
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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
#include "tftp12packet.h"
#include "tftp12header.h"
#include "stdlib.h"
#include "stdio.h"
#include "time.h"
#include "tftp12IObuffer.h"
#define TFTP_PORT (69)
const INT32 tranModeStrLen[2] = { 8,5 };
// TFTPRequestPacket_t *tftpBuildRequestPacket(INT32 opcode, char *filename, INT32 mode, INT32 blocksize, INT8 timeout, INT32 tsize)
// {
//
// }
INT32 tftpReadFrom(FILE *file, TFTP12Description *request)
{
// if (/*file==NULL||*/request==NULL||request->destFilename==NULL||request->sourceFilename==NULL)
// {
// return FALSE;
// }
//
// if (request->timeout>TFTP12_TIMEOUT_MAX|| request->timeout<TFTP12_TIMEOUT_MIN)
// {
// return FALSE;
// }
// if (request->blksize > TFTP12_BLOCKSIZE_MAX || request->blksize < TFTP12_BLOCKSIZE_MIN)
// {
// return FALSE;
// }
//
// INT32 streamLen = 0;
// char blksize_str[10];//int32最大值为10位数
// char timeout_str[10];//不可能到10位数
// INT32 filenameLen = strlen(request->sourceFilename);
//
// _itoa(request->blksize, blksize_str, 10);
// _itoa(request->timeout, timeout_str, 10);
//
// INT32 blksizeStrLen = strlen(blksize_str);
//
// streamLen += 2;//opcode
// streamLen += filenameLen + 1;//filename
// streamLen+= tranModeStrLen[request->transMode] + 1 ;//octet or netascii
// streamLen += strlen("blksize") + 1 + blksizeStrLen + 1;//blksize
// streamLen += strlen("timeout") + 1 + strlen(timeout_str) + 1;//timeout
// streamLen += strlen("tsize") + 1 + 1 + 1;//tsize.0.
//
// char *pSendStream = (char *)malloc(streamLen);
// if (pSendStream ==NULL)
// {
// printf("\nmemory alloc failed.");
// return FALSE;
// }
// memset(pSendStream, '\0', streamLen);
//
// char *pWalk = pSendStream;
//
// *pWalk = 0;
// pWalk++;
// *pWalk = 1;
// pWalk++;
// strcpy(pWalk, request->sourceFilename);
// pWalk += filenameLen+1;
// strcpy(pWalk, transMode[request->transMode]);
// pWalk += tranModeStrLen[request->transMode] + 1;
// strcpy(pWalk, "blksize");
// pWalk += strlen("blksize") + 1;
// strcpy(pWalk, blksize_str);
// pWalk += blksizeStrLen + 1;
// strcpy(pWalk, "timeout");
// pWalk += strlen("timeout") + 1;
// strcpy(pWalk, timeout_str);
// pWalk += strlen(timeout_str) + 1;
// strcpy(pWalk, "tsize");
// pWalk += strlen("tsize") + 1;
// *pWalk = 0;
//
// SOCKET sendSocket = socket(AF_INET, SOCK_DGRAM, 0);
// SOCKADDR_IN destAddr;
//
// memset(&sendSocket, 0, sizeof(sendSocket));
// memset(&destAddr, 0, sizeof(destAddr));
//
// destAddr.sin_addr.S_un.S_addr=inet_addr(request->hostIP);
// destAddr.sin_family = AF_INET;
// destAddr.sin_port = TFTP_PORT;
return TRUE;
}
INT32 test()
{
// TFTP12Description testDesc;
// //
FILE *fd = fopen("test.txt", "wb+");
char a[20];
for (INT32 i = 0; i < (1000000 / 500); i++)
{
for (int j = 0; j < 500; j++)
{
// _itoa(i, a, 10);
// fwrite(a, strlen(a), 1, fd);
fprintf(fd, "1");
}
}
// fprintf(fd, "123456");
fclose(fd);
//
//
// memset(&testDesc, 0, sizeof(testDesc));
//
// testDesc.option.blockSize = 8192;
// testDesc.option.timeout = 10;
// testDesc.option.tsize = 10000;
// testDesc.filename = "testfilename";
// testDesc.recvBuffer = malloc(TFTP12_BUFFER_SIZE(&testDesc));
// testDesc.writeOrRead = TFTP12_OPCODE_READ_REQUEST;
// //testDesc.openFile = 123;
// testDesc.mode = "ocete";
// //tftp12CreateRequestPkt(&testDesc);
//
// FILE *tFile = fopen("test.txt", "r");
//
// char *rea = malloc(5000000);
// INT32 x = fread(rea, 1, 5000000, tFile);
// for (INT32 i=0;i<x;i++)
// {
// if (rea[i]!='1')
// {
// printf("error");
// }
// }
// FILE *wFile = fopen("test_copy.txt", "w+");
// #define BLKSIZE 500
//
// if (tFile != NULL)
// {
// fseek(tFile, 0L, SEEK_END);
// INT32 size = ftell(tFile);
// fseek(tFile, 0, SEEK_SET);
// tftp12IOBufferInit(1, BLKSIZE, tFile, size, TFTP12_READ);
// tftp12IOBufferInit(2, BLKSIZE, wFile, size, TFTP12_WRITE);
// INT32 rsize = 0;
//
// //while (1)
// {
// // extern INT32 testNum, testNum2;
// // testNum = 0;
// // testNum2 = 0;
// //
// // fseek(tFile, 0, SEEK_SET);
// // tftp12IOBufferFree(1);
// // tftp12IOBufferInit(1, 500, tFile, size, TFTP12_READ);
// // while (1)
// // {
// // char *tem = tftp12ReadNextBlock(1, &rsize);
// // // for (INT32 i = 0; i < (rsize-1); i++)
// // // {
// // // // if ((*tem) != (*(tem + i))&&((*(tem+i-1)) != (*(tem + i))+1))
// // // // {
// // // // printf("\n错误,%c -- %c", *tem, *(tem + i));
// // // // //break;
// // // // }
// // // }
// // if (tftp12WriteNextBlock(2, tem, rsize) != rsize)
// // {
// // printf("error");
// // }
// // for (INT32 i = 0; i < rsize; i++)
// // {
// // *(tem + i) = 0;
// // }
// // if (rsize < BLKSIZE)
// // {
// // printf("\nfinish\n\n\n");
// // break;
// // }
// //
// // }
// //Sleep(100);
// }
// }
// tftp12IOBufferFree(1);
// tftp12IOBufferFree(2);
// fclose(wFile);
// fclose(tFile);
//tftp12ExtractOption(testDesc.sendBuffer, 512, &testDesc.option);
// tftp12ExtractOption("timeout\0123\0blksize\01x34\0tsize\0111\0", &testDesc.option);
// tftp12ExtractOption("blksize\01234\0timeout\0123\0tsize\0111\0", &testDesc.option);
return 1;
}