From 57d45923fc62be7d11ac20abba8618ca4b90bea4 Mon Sep 17 00:00:00 2001 From: me_desk Date: Thu, 19 Sep 2013 18:08:52 +0000 Subject: fixes for enabling build of pica-node on Windows using MinGW git-svn-id: svn://localhost/project_picapica/trunk@275 fb96df88-216d-11de-830c-f3023f12d8ac --- PICA_node.c | 14 ++++++++++---- PICA_node.h | 2 +- PICA_nodeaddrlist.h | 7 +++++++ PICA_nodewait.c | 6 ++++++ 4 files changed, 24 insertions(+), 5 deletions(-) diff --git a/PICA_node.c b/PICA_node.c index 21f622e..b3cba2c 100755 --- a/PICA_node.c +++ b/PICA_node.c @@ -20,6 +20,12 @@ #include "PICA_rand_seed.h" #endif +#ifdef WIN32 +typedef u_long in_addr_t; +typedef u_short in_port_t; +typedef u_short uint16_t; +#endif + #define MAX_NEWCONNS 64 #define NEWCONN_TIMEOUT 10 //sec @@ -579,7 +585,7 @@ mp = nodelink_wbuf_push(n, PICA_PROTO_NEWNODE_IPV4, PICA_PROTO_NEWNODE_IPV4_SIZE if (mp) { *((in_addr_t*)(mp->tail))=inet_addr(nodecfg.announced_addr); - *((uint16_t*)(mp->tail+4))=(nodecfg.listen_port ? htons(atoi(nodecfg.listen_port)) : htons(PICA_COMM_PORT));//CONF; + *((in_port_t*)(mp->tail+4))=(nodecfg.listen_port ? htons(atoi(nodecfg.listen_port)) : htons(PICA_COMM_PORT));//CONF; } else return 0; @@ -619,7 +625,7 @@ PICA_debug1("received NEWNODE"); switch (buf[0]) { case PICA_PROTO_NEWNODE_IPV4: - PICA_debug1("NEWNODE_IPV4: ip %.16s port %hu\n",inet_ntoa(*(struct in_addr*)(buf+2)),ntohs(*(uint16_t*)(buf+6))); + PICA_debug1("NEWNODE_IPV4: ip %.16s port %hu\n",inet_ntoa(*(struct in_addr*)(buf+2)),ntohs(*(in_port_t*)(buf+6))); { struct PICA_nodeaddr_ipv4 na_ipv4; @@ -684,7 +690,7 @@ if (!nl_buf) //собственный адрес узла nl_buf[nl_size]=PICA_PROTO_NEWNODE_IPV4; *((in_addr_t*)(nl_buf+nl_size+1))=inet_addr(my_addr); -*((uint16_t*)(nl_buf+nl_size+5))=(nodecfg.listen_port ? htons(atoi(nodecfg.listen_port)) : htons(PICA_COMM_PORT));//CONF +*((in_port_t*)(nl_buf+nl_size+5))=(nodecfg.listen_port ? htons(atoi(nodecfg.listen_port)) : htons(PICA_COMM_PORT));//CONF nl_size+=PICA_PROTO_NODELIST_ITEM_IPV4_SIZE; } @@ -701,7 +707,7 @@ while(nlp && nl_size < 65532)//MAP nl_buf[nl_size]=PICA_PROTO_NEWNODE_IPV4; *((in_addr_t*)(nl_buf+nl_size+1)) = ((struct PICA_nodeaddr_ipv4*)nlp->node_addr)->addr; - *((uint16_t*)(nl_buf+nl_size+5)) = ((struct PICA_nodeaddr_ipv4*)nlp->node_addr)->port; + *((in_port_t*)(nl_buf+nl_size+5)) = ((struct PICA_nodeaddr_ipv4*)nlp->node_addr)->port; nl_size += PICA_PROTO_NODELIST_ITEM_IPV4_SIZE;//CONF break; } diff --git a/PICA_node.h b/PICA_node.h index 27011ee..e635df2 100755 --- a/PICA_node.h +++ b/PICA_node.h @@ -3,8 +3,8 @@ #ifdef WIN32 -#include #include +#include #else diff --git a/PICA_nodeaddrlist.h b/PICA_nodeaddrlist.h index 6f57bed..0cfd771 100755 --- a/PICA_nodeaddrlist.h +++ b/PICA_nodeaddrlist.h @@ -4,10 +4,17 @@ #define PICA_NODEADDRLIST_H #ifndef WIN32 + #include + #else + +#define _WIN32_WINNT 0x501 #include #include + +typedef u_long in_addr_t; +typedef u_short in_port_t; #endif #include diff --git a/PICA_nodewait.c b/PICA_nodewait.c index c3479b7..d9b49b0 100644 --- a/PICA_nodewait.c +++ b/PICA_nodewait.c @@ -9,6 +9,8 @@ #ifdef WIN32 +#include +#include #include #else @@ -82,11 +84,15 @@ char portbuf[8]; memset(&h,0,sizeof(struct addrinfo)); +#ifdef AI_ADDRCONFIG #ifdef AI_IDN #define H_AI_FLAGS (AI_ADDRCONFIG | AI_IDN) #else #define H_AI_FLAGS AI_ADDRCONFIG #endif +#else +#define H_AI_FLAGS 0 +#endif h.ai_flags=H_AI_FLAGS; h.ai_family=AF_INET;//CONF - IPv4, IPv6, IPv4 then IPv6, IPv6 then IPv4 -- cgit v1.2.1