Many Windows fixes
This commit is contained in:
parent
c53185dfbf
commit
daddb52305
4 changed files with 39 additions and 33 deletions
|
@ -7,11 +7,7 @@
|
|||
#include "ethsock.h"
|
||||
#include "nmrpd.h"
|
||||
|
||||
#if defined(NMRPFLASH_WINDOWS)
|
||||
#include <winsock2.h>
|
||||
#include <iphlpapi.h>
|
||||
#else
|
||||
#include <sys/socket.h>
|
||||
#if !defined(NMRPFLASH_WINDOWS)
|
||||
#include <ifaddrs.h>
|
||||
#if defined(NMRPFLASH_LINUX)
|
||||
#include <linux/if_packet.h>
|
||||
|
|
42
nmrp.c
42
nmrp.c
|
@ -18,12 +18,6 @@
|
|||
*/
|
||||
|
||||
#define _BSD_SOURCE
|
||||
#include <netinet/if_ether.h>
|
||||
//#include <linux/if_packet.h>
|
||||
#include <arpa/inet.h>
|
||||
#include <sys/socket.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <net/if.h>
|
||||
#include <signal.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
@ -34,12 +28,18 @@
|
|||
#include "ethsock.h"
|
||||
#include "nmrpd.h"
|
||||
|
||||
#ifndef NMRPFLASH_WINDOWS
|
||||
#include <arpa/inet.h>
|
||||
#else
|
||||
#include <winsock2.h>
|
||||
#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;
|
||||
}
|
||||
|
|
11
nmrpd.h
11
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 <arpa/inet.h>
|
||||
#include <sys/socket.h>
|
||||
#include <net/if.h>
|
||||
#else
|
||||
#include <winsock2.h>
|
||||
#include <iphlpapi.h>
|
||||
#include <ws2tcpip.h>
|
||||
#endif
|
||||
|
||||
#define NMRPD_VERSION "0.9"
|
||||
|
||||
enum nmrp_op {
|
||||
|
|
13
tftp.c
13
tftp.c
|
@ -18,9 +18,6 @@
|
|||
*/
|
||||
|
||||
#define _BSD_SOURCE
|
||||
#include <arpa/inet.h>
|
||||
#include <sys/socket.h>
|
||||
#include <net/if.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include <stdio.h>
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue