From: Joseph C. Lehner Date: Tue, 2 Feb 2016 11:11:55 +0000 (+0200) Subject: Many Windows fixes X-Git-Tag: v0.9~67 X-Git-Url: https://git.librecmc.org/?a=commitdiff_plain;h=daddb523052af032601fe7616a3bb011eb75260b;p=oweals%2Fnmrpflash.git Many Windows fixes --- diff --git a/ethsock.c b/ethsock.c index ab15089..f1e9bdf 100644 --- a/ethsock.c +++ b/ethsock.c @@ -7,11 +7,7 @@ #include "ethsock.h" #include "nmrpd.h" -#if defined(NMRPFLASH_WINDOWS) -#include -#include -#else -#include +#if !defined(NMRPFLASH_WINDOWS) #include #if defined(NMRPFLASH_LINUX) #include diff --git a/nmrp.c b/nmrp.c index 0330c63..7cb3689 100644 --- a/nmrp.c +++ b/nmrp.c @@ -18,12 +18,6 @@ */ #define _BSD_SOURCE -#include -//#include -#include -#include -#include -#include #include #include #include @@ -34,12 +28,18 @@ #include "ethsock.h" #include "nmrpd.h" +#ifndef NMRPFLASH_WINDOWS +#include +#else +#include +#endif + #define NMRP_HDR_LEN 6 #define NMRP_OPT_LEN 4 -#define NMRP_MIN_PKT_LEN (sizeof(struct ether_header) + NMRP_HDR_LEN) +#define NMRP_MIN_PKT_LEN (sizeof(struct eth_hdr) + NMRP_HDR_LEN) -#define MAX_OPT_SIZE 12 -#define MAX_OPT_NUM 2 +#define NMRP_MAX_OPT_SIZE 12 +#define NMRP_MAX_OPT_NUM 2 #define ETH_P_NMRP 0x0912 #define IP_LEN 4 @@ -88,8 +88,14 @@ struct nmrp_msg { uint32_t num_opts; } PACKED; +struct eth_hdr { + uint8_t ether_shost[8]; + uint8_t ether_dhost[8]; + uint16_t ether_type; +}; + struct nmrp_pkt { - struct ether_header eh; + struct eth_hdr eh; struct nmrp_msg msg; } PACKED; @@ -162,7 +168,7 @@ static int msg_ntoh(struct nmrp_msg *msg) // FIXME maximum of two options supported, maximum option // size is 12 - if (remaining < MAX_OPT_NUM * MAX_OPT_SIZE) { + if (remaining < NMRP_MAX_OPT_NUM * NMRP_MAX_OPT_SIZE) { while (remaining > 0) { if (remaining < NMRP_OPT_LEN) { break; @@ -171,7 +177,7 @@ static int msg_ntoh(struct nmrp_msg *msg) opt->type = ntohs(opt->type); opt->len = ntohs(opt->len); - if (opt->len > MAX_OPT_SIZE) { + if (opt->len > NMRP_MAX_OPT_SIZE) { break; } @@ -206,7 +212,7 @@ static int pkt_recv(struct ethsock *sock, struct nmrp_pkt *pkt) } else if (!bytes) { return 2; } else if (bytes < NMRP_MIN_PKT_LEN) { - fprintf(stderr, "Short packet (%zi bytes)\n", bytes); + fprintf(stderr, "Short packet (%d bytes)\n", (int)bytes); return 1; } @@ -214,7 +220,7 @@ static int pkt_recv(struct ethsock *sock, struct nmrp_pkt *pkt) len = pkt->msg.len + sizeof(pkt->eh); if (bytes != len) { - fprintf(stderr, "Unexpected message length (%zi bytes).\n", len); + fprintf(stderr, "Unexpected message length (%d bytes).\n", (int)len); return 1; } @@ -267,7 +273,7 @@ int nmrp_do(struct nmrpd_args *args) time_t beg; int i, err, ulreqs, expect; struct ethsock *sock; - sig_t sigh_orig; + void (*sigh_orig)(int); if (args->op != NMRP_UPLOAD_FW) { fprintf(stderr, "Operation not implemented.\n"); @@ -279,12 +285,12 @@ int nmrp_do(struct nmrpd_args *args) return 1; } - if (!inet_aton(args->ipaddr, &ipaddr)) { - fprintf(stderr, "Invalid IP address '%s'.\n", args->ipaddr); + if ((ipaddr.s_addr = inet_addr(args->ipaddr)) == INADDR_NONE) { + fprintf(stderr, "Invalid IP address '%s'.\n", args->ipaddr); return 1; } - if (!inet_aton(args->ipmask, &ipmask)) { + if ((ipmask.s_addr = inet_addr(args->ipmask)) == INADDR_NONE) { fprintf(stderr, "Invalid subnet mask '%s'.\n", args->ipmask); return 1; } diff --git a/nmrpd.h b/nmrpd.h index 374448d..bd258ee 100644 --- a/nmrpd.h +++ b/nmrpd.h @@ -33,6 +33,17 @@ #warning "nmrp-flash is not fully supported on your operating system" #endif +#ifndef NMRPFLASH_WINDOWS +#define _BSD_SOURCE +#include +#include +#include +#else +#include +#include +#include +#endif + #define NMRPD_VERSION "0.9" enum nmrp_op { diff --git a/tftp.c b/tftp.c index f1d0a6b..002beb1 100644 --- a/tftp.c +++ b/tftp.c @@ -18,9 +18,6 @@ */ #define _BSD_SOURCE -#include -#include -#include #include #include #include @@ -81,11 +78,8 @@ static inline void pkt_print(char *pkt, FILE *fp) static ssize_t tftp_recvfrom(int sock, char *pkt, struct sockaddr_in *src) { - socklen_t socklen; ssize_t len; - (void)src, (void)socklen; - len = recvfrom(sock, pkt, TFTP_PKT_SIZE, 0, NULL, NULL); if (len < 0) { if (errno != EAGAIN) { @@ -153,7 +147,7 @@ int sock_set_rx_timeout(int fd, unsigned msec) if (msec) { tv.tv_usec = (msec % 1000) * 1000; tv.tv_sec = msec / 1000; - if (setsockopt(fd, SOL_SOCKET, SO_RCVTIMEO, &tv, sizeof(tv)) < 0) { + if (setsockopt(fd, SOL_SOCKET, SO_RCVTIMEO, (char*)&tv, sizeof(tv)) < 0) { perror("setsockopt(SO_RCVTIMEO)"); return 1; } @@ -191,9 +185,8 @@ int tftp_put(struct nmrpd_args *args) goto cleanup; } - err = !inet_aton(args->ipaddr, &addr.sin_addr); - if (err) { - perror("inet_aton"); + if ((addr.sin_addr.s_addr = inet_addr(args->ipaddr)) == INADDR_NONE) { + perror("inet_addr"); goto cleanup; }