decoding of IPv6 fixed

This commit is contained in:
Matej Sekoranja
2014-09-02 01:23:57 +02:00
parent 45b14f1455
commit 6bd1efa313
5 changed files with 30 additions and 53 deletions
+19
View File
@@ -64,6 +64,25 @@ void encodeAsIPv6Address(ByteBuffer* buffer, const osiSockAddr* address) {
buffer->putByte((int8)(ipv4Addr&0xFF));
}
bool decodeAsIPv6Address(ByteBuffer* buffer, osiSockAddr* address) {
// IPv4 compatible IPv6 address expected
// first 80-bit are 0
if (buffer->getLong() != 0) return false;
if (buffer->getShort() != 0) return false;
if (buffer->getShort() != (int16)0xFFFF) return false;
uint32_t ipv4Addr =
((uint32_t)(buffer->getByte()&0xFF))<<24 |
((uint32_t)(buffer->getByte()&0xFF))<<16 |
((uint32_t)(buffer->getByte()&0xFF))<<8 |
((uint32_t)(buffer->getByte()&0xFF));
address->ia.sin_addr.s_addr = htonl(ipv4Addr);
return true;
}
bool isMulticastAddress(const osiSockAddr* address) {
uint32_t ipv4Addr = ntohl(address->ia.sin_addr.s_addr);
uint8_t msB = (uint8_t)((ipv4Addr>>24)&0xFF);
+8
View File
@@ -49,6 +49,14 @@ namespace pvAccess {
*/
epicsShareFunc void encodeAsIPv6Address(epics::pvData::ByteBuffer* buffer, const osiSockAddr* address);
/**
* Decode IPv6 address (as IPv4 address).
* @param buffer byte-buffer where to get encoded data.
* @param address address where to decode.
* @return success status (true on success).
*/
epicsShareFunc bool decodeAsIPv6Address(epics::pvData::ByteBuffer* buffer, osiSockAddr* address);
/**
* Check if an IPv4 address is a multicast address.
* @param address IPv4 address to check.