miniupnpd/pcpserver.c: take care of "nonce" value

This commit is contained in:
Thomas Bernard 2014-03-24 10:21:26 +01:00
parent 4a7f97c7f3
commit b1fb9cfdc4
1 changed files with 21 additions and 14 deletions

View File

@ -1,4 +1,4 @@
/* $Id: pcpserver.c,v 1.12 2014/02/28 17:50:22 nanard Exp $ */ /* $Id: pcpserver.c,v 1.20 2014/03/22 12:06:15 nanard Exp $ */
/* MiniUPnP project /* MiniUPnP project
* Website : http://miniupnp.free.fr/ * Website : http://miniupnp.free.fr/
* Author : Peter Tatrai * Author : Peter Tatrai
@ -84,6 +84,7 @@ typedef struct pcp_info {
uint32_t lifetime; /* lifetime of the mapping */ uint32_t lifetime; /* lifetime of the mapping */
uint32_t epochtime; uint32_t epochtime;
/* both MAP and PEER opcode specific information */ /* both MAP and PEER opcode specific information */
uint32_t nonce[3]; /* random value generated by client */
uint8_t protocol; uint8_t protocol;
uint16_t int_port; uint16_t int_port;
const struct in6_addr *int_ip; /* in network order */ const struct in6_addr *int_ip; /* in network order */
@ -214,11 +215,13 @@ static void printMAPOpcodeVersion1(pcp_map_v1_t *map_buf)
static void printMAPOpcodeVersion2(pcp_map_v2_t *map_buf) static void printMAPOpcodeVersion2(pcp_map_v2_t *map_buf)
{ {
char map_addr[INET6_ADDRSTRLEN]; char map_addr[INET6_ADDRSTRLEN];
syslog(LOG_DEBUG, "PCP MAP: v2 Opcode specific information. \n"); syslog(LOG_DEBUG, "PCP MAP: v2 Opcode specific information.");
syslog(LOG_DEBUG, "MAP protocol: \t\t %d\n",map_buf->protocol ); syslog(LOG_DEBUG, "MAP nonce: \t%08x%08x%08x",
syslog(LOG_DEBUG, "MAP int port: \t\t %d\n", ntohs(map_buf->int_port) ); map_buf->nonce[0], map_buf->nonce[1], map_buf->nonce[2]);
syslog(LOG_DEBUG, "MAP ext port: \t\t %d\n", ntohs(map_buf->ext_port) ); syslog(LOG_DEBUG, "MAP protocol:\t%d", map_buf->protocol);
syslog(LOG_DEBUG, "MAP Ext IP: \t\t %s\n", inet_ntop(AF_INET6, syslog(LOG_DEBUG, "MAP int port:\t%d", ntohs(map_buf->int_port));
syslog(LOG_DEBUG, "MAP ext port:\t%d", ntohs(map_buf->ext_port));
syslog(LOG_DEBUG, "MAP Ext IP: \t%s", inet_ntop(AF_INET6,
&map_buf->ext_ip, map_addr, INET6_ADDRSTRLEN)); &map_buf->ext_ip, map_addr, INET6_ADDRSTRLEN));
} }
#endif /* DEBUG */ #endif /* DEBUG */
@ -241,10 +244,11 @@ static int parsePCPMAP_version1(pcp_map_v1_t *map_v1,
return 0; return 0;
} }
static int parsePCPMAP_version2(pcp_map_v2_t *map_v2, static int parsePCPMAP_version2(const pcp_map_v2_t *map_v2,
pcp_info_t *pcp_msg_info) pcp_info_t *pcp_msg_info)
{ {
pcp_msg_info->is_map_op = 1; pcp_msg_info->is_map_op = 1;
memcpy(pcp_msg_info->nonce, map_v2->nonce, 12);
pcp_msg_info->protocol = map_v2->protocol; pcp_msg_info->protocol = map_v2->protocol;
pcp_msg_info->int_port = ntohs(map_v2->int_port); pcp_msg_info->int_port = ntohs(map_v2->int_port);
pcp_msg_info->ext_port = ntohs(map_v2->ext_port); pcp_msg_info->ext_port = ntohs(map_v2->ext_port);
@ -282,15 +286,17 @@ static void printPEEROpcodeVersion2(pcp_peer_v2_t *peer_buf)
char ext_addr[INET6_ADDRSTRLEN]; char ext_addr[INET6_ADDRSTRLEN];
char peer_addr[INET6_ADDRSTRLEN]; char peer_addr[INET6_ADDRSTRLEN];
syslog(LOG_DEBUG, "PCP PEER: v2 Opcode specific information. \n"); syslog(LOG_DEBUG, "PCP PEER: v2 Opcode specific information.");
syslog(LOG_DEBUG, "Protocol: \t\t %d\n",peer_buf->protocol ); syslog(LOG_DEBUG, "nonce: \t%08x%08x%08x",
syslog(LOG_DEBUG, "Internal port: \t\t %d\n", ntohs(peer_buf->int_port) ); map_buf->nonce[0], map_buf->nonce[1], map_buf->nonce[2]);
syslog(LOG_DEBUG, "External IP: \t\t %s\n", inet_ntop(AF_INET6, &peer_buf->ext_ip, syslog(LOG_DEBUG, "Protocol: \t%d",peer_buf->protocol );
syslog(LOG_DEBUG, "Internal port:\t%d", ntohs(peer_buf->int_port) );
syslog(LOG_DEBUG, "External IP: \t%s", inet_ntop(AF_INET6, &peer_buf->ext_ip,
ext_addr,INET6_ADDRSTRLEN)); ext_addr,INET6_ADDRSTRLEN));
syslog(LOG_DEBUG, "External port port: \t\t %d\n", ntohs(peer_buf->ext_port) ); syslog(LOG_DEBUG, "External port:\t%d", ntohs(peer_buf->ext_port) );
syslog(LOG_DEBUG, "PEER IP: \t\t %s\n", inet_ntop(AF_INET6, &peer_buf->peer_ip, syslog(LOG_DEBUG, "PEER IP: \t%s", inet_ntop(AF_INET6, &peer_buf->peer_ip,
peer_addr,INET6_ADDRSTRLEN)); peer_addr,INET6_ADDRSTRLEN));
syslog(LOG_DEBUG, "PEER port port: \t\t %d\n", ntohs(peer_buf->peer_port) ); syslog(LOG_DEBUG, "PEER port: \t%d", ntohs(peer_buf->peer_port) );
} }
#endif /* DEBUG */ #endif /* DEBUG */
@ -326,6 +332,7 @@ static int parsePCPPEER_version2(pcp_peer_v2_t *peer_buf, \
pcp_info_t *pcp_msg_info) pcp_info_t *pcp_msg_info)
{ {
pcp_msg_info->is_peer_op = 1; pcp_msg_info->is_peer_op = 1;
memcpy(pcp_msg_info->nonce, peer_buf->nonce, 12);
pcp_msg_info->protocol = peer_buf->protocol; pcp_msg_info->protocol = peer_buf->protocol;
pcp_msg_info->int_port = ntohs(peer_buf->int_port); pcp_msg_info->int_port = ntohs(peer_buf->int_port);
pcp_msg_info->ext_port = ntohs(peer_buf->ext_port); pcp_msg_info->ext_port = ntohs(peer_buf->ext_port);