miniupnpd/pcpserver.c: Some IPv6 related work on PCP.

This commit is contained in:
Markus Stenberg 2014-05-03 07:28:40 +03:00 committed by Thomas Bernard
parent 0e49fe7e94
commit 2f5c3ce959
1 changed files with 20 additions and 2 deletions

View File

@ -120,8 +120,8 @@ typedef struct pcp_info {
uint8_t is_peer_op;
const struct in6_addr *thirdp_ip;
int pfailure_present;
char senderaddrstr[INET_ADDRSTRLEN]; /* only if IPv4 sender */
char senderaddrstr[48]; /* can be either IPv4 or IPv6 */
struct in6_addr sender_ip;
} pcp_info_t;
@ -1429,7 +1429,25 @@ int ProcessIncomingPCPPacket(int s, unsigned char *buff, int len,
sizeof(pcp_msg_info.senderaddrstr))) {
syslog(LOG_ERR, "inet_ntop(pcpserver): %m");
}
pcp_msg_info.sender_ip.s6_addr[11] = 0xff;
pcp_msg_info.sender_ip.s6_addr[10] = 0xff;
memcpy(pcp_msg_info.sender_ip.s6_addr+12,
&senderaddr_v4->sin_addr, 4);
} else if(senderaddr->sa_family == AF_INET6) {
const struct sockaddr_in6 * senderaddr_v6;
senderaddr_v6 = (const struct sockaddr_in6 *)senderaddr;
if(!inet_ntop(AF_INET6, &senderaddr_v6->sin6_addr,
pcp_msg_info.senderaddrstr,
sizeof(pcp_msg_info.senderaddrstr))) {
syslog(LOG_ERR, "inet_ntop(pcpserver): %m");
}
pcp_msg_info.sender_ip = senderaddr_v6->sin6_addr;
} else {
syslog(LOG_WARNING, "unknown PCP packet sender address family %d",
senderaddr->sa_family);
return 0;
}
if(sockaddr_to_string(senderaddr, addr_str, sizeof(addr_str)))
syslog(LOG_DEBUG, "PCP request received from %s %dbytes",
addr_str, len);