--- tftpd/src/srv.c 2014/02/21 08:40:00 1.4.2.2 +++ tftpd/src/srv.c 2014/02/21 09:01:30 1.4.2.3 @@ -76,7 +76,7 @@ txData(sched_task_t *task) len = pread(cli.fd, RPACK_NEXT(pkt), len, (cli.seq - 1) * cli.siz); if (len == -1) { ESYSERR(0); - code = htole16(3); + code = htons(3); goto end; } else { rpack_rnext(pkt, len); @@ -94,7 +94,7 @@ end: n = htons(TFTP_OPC_ERROR); rpack_uint16(pkt, &n, 0); rpack_uint16(pkt, &code, 0); - rpack_rdata(pkt, errs[le16toh(code)].err_msg, strlen(errs[le16toh(code)].err_msg) + 1); + rpack_rdata(pkt, errs[ntohs(code)].err_msg, strlen(errs[ntohs(code)].err_msg) + 1); schedEvent(TASK_ROOT(task), txPkt, (void*) -1, TASK_FD(task), TASK_DATA(task), RPACK_OFF(pkt)); @@ -256,10 +256,10 @@ RQ(sched_task_t *task) strlcpy(cli.mode, TFTP_MODE_OCTET, sizeof cli.mode); else if (!strcasecmp(str, TFTP_MODE_MAIL)) { strlcpy(cli.mode, TFTP_MODE_MAIL, sizeof cli.mode); - code = htole16(4); + code = htons(4); goto end; } else { - code = htole16(1); + code = htons(1); goto end; } } @@ -281,13 +281,13 @@ RQ(sched_task_t *task) cli.fd = open(cli.file, code, 0644); if (cli.fd == -1) { if (errno == EACCES) - code = htole16(2); + code = htons(2); else if (errno == ENFILE) - code = htole16(3); + code = htons(3); else if (errno == EEXIST) - code = htole16(6); + code = htons(6); else - code = htole16(0); + code = htons(0); ESYSERR(0); goto end; } else @@ -330,7 +330,7 @@ end: RPACK_REWIND(pkt); rpack_uint16(pkt, NULL, 0); rpack_uint16(pkt, &code, 0); - rpack_rdata(pkt, errs[le16toh(code)].err_msg, strlen(errs[le16toh(code)].err_msg) + 1); + rpack_rdata(pkt, errs[ntohs(code)].err_msg, strlen(errs[ntohs(code)].err_msg) + 1); schedEvent(TASK_ROOT(task), txPkt, (void*) -1, TASK_FD(task), TASK_DATA(task), RPACK_OFF(pkt)); @@ -349,13 +349,13 @@ ACK(sched_task_t *task) RPACK_REWIND(pkt); code = rpack_uint16(pkt, NULL, 0); if (ntohs(code) != TFTP_OPC_ACK) { - code = htole16(5); + code = htons(5); goto end; } code = rpack_uint16(pkt, NULL, 0); if (ntohs(code) > cli.seq || (ntohs(code) < (cli.seq - 1))) { - code = htole16(5); + code = htons(5); goto end; } else if (ntohs(code) == cli.seq) { /* check for rollover seq id */ @@ -382,7 +382,7 @@ end: RPACK_REWIND(pkt); rpack_uint16(pkt, NULL, 0); rpack_uint16(pkt, &code, 0); - rpack_rdata(pkt, errs[le16toh(code)].err_msg, strlen(errs[le16toh(code)].err_msg) + 1); + rpack_rdata(pkt, errs[ntohs(code)].err_msg, strlen(errs[ntohs(code)].err_msg) + 1); schedEvent(TASK_ROOT(task), txPkt, (void*) -1, TASK_FD(task), TASK_DATA(task), RPACK_OFF(pkt)); @@ -402,13 +402,13 @@ DATA(sched_task_t *task) RPACK_REWIND(pkt); code = rpack_uint16(pkt, NULL, 0); if (ntohs(code) != TFTP_OPC_DATA) { - code = htole16(5); + code = htons(5); goto end; } code = rpack_uint16(pkt, NULL, 0); if (ntohs(code) < cli.seq || ntohs(code) > cli.seq + 1) { - code = htole16(5); + code = htons(5); goto end; } else cli.seq = ntohs(code); @@ -425,7 +425,7 @@ DATA(sched_task_t *task) len = pwrite(cli.fd, RPACK_NEXT(pkt), len, (cli.seq - 1) * cli.siz); if (len == -1) { ESYSERR(0); - code = htole16(3); + code = htons(3); goto end; } else { rpack_rnext(pkt, len); @@ -439,7 +439,7 @@ end: RPACK_REWIND(pkt); rpack_uint16(pkt, NULL, 0); rpack_uint16(pkt, &code, 0); - rpack_rdata(pkt, errs[le16toh(code)].err_msg, strlen(errs[le16toh(code)].err_msg) + 1); + rpack_rdata(pkt, errs[ntohs(code)].err_msg, strlen(errs[ntohs(code)].err_msg) + 1); schedEvent(TASK_ROOT(task), txPkt, (void*) -1, TASK_FD(task), TASK_DATA(task), RPACK_OFF(pkt)); @@ -477,7 +477,7 @@ rxPkt(sched_task_t *task) RPACK_REWIND(pkt); code = htons(TFTP_OPC_ERROR); rpack_uint16(pkt, &code, 0); - code = htole16(4); + code = htons(4); rpack_uint16(pkt, &code, 0); rpack_rdata(pkt, errs[4].err_msg, strlen(errs[4].err_msg) + 1); @@ -505,7 +505,7 @@ rxPkt(sched_task_t *task) RPACK_REWIND(pkt); code = htons(TFTP_OPC_ERROR); rpack_uint16(pkt, &code, 0); - code = htole16(4); + code = htons(4); rpack_uint16(pkt, &code, 0); rpack_rdata(pkt, errs[4].err_msg, strlen(errs[4].err_msg) + 1);