END_TEST START_TEST (sockaddr_IPv6_isSet) { fail_unless( sockaddr_isSet((struct sockaddr *)sockaddr_IPv6_1), "isSet failed"); fail_if( sockaddr_isSet(sockaddr_uninit), "isSet failed"); }
END_TEST START_TEST (sockaddr_IPv4_isSet) { fail_unless( sockaddr_isSet((struct sockaddr *)sockaddr_IPv4_1), "isSet failed"); }
int sendKeepalive(struct turn_info *turnInfo) { char m[] = "KeepAlive"; int len = 0; if (sockaddr_isSet((struct sockaddr *)&turnInfo->remoteIp4)) { if (sockaddr_isSet((struct sockaddr *)&turnInfo->turnAlloc_44.relAddrIPv4)) { len = sendRawUDP(turnInfo->turnAlloc_44.sockfd, m, sizeof(m), (struct sockaddr *)&turnInfo->remoteIp4, sizeof( struct sockaddr_storage)); } if (sockaddr_isSet((struct sockaddr *)&turnInfo->turnAlloc_46.relAddrIPv6)){ len = sendRawUDP(turnInfo->turnAlloc_46.sockfd, m, sizeof(m), (struct sockaddr *)&turnInfo->remoteIp4, sizeof( struct sockaddr_storage)); } } if (sockaddr_isSet((struct sockaddr *)&turnInfo->remoteIp6)){ if (sockaddr_isSet((struct sockaddr *)&turnInfo->turnAlloc_64.relAddrIPv4)) { len = sendRawUDP(turnInfo->turnAlloc_64.sockfd, m, sizeof(m), (struct sockaddr *)&turnInfo->remoteIp6, sizeof( struct sockaddr_storage)); } if (sockaddr_isSet((struct sockaddr *)&turnInfo->turnAlloc_66.relAddrIPv6)) { len = sendRawUDP(turnInfo->turnAlloc_66.sockfd, m, sizeof(m), (struct sockaddr *)&turnInfo->remoteIp6, sizeof( struct sockaddr_storage)); } } return len; }
bool CreateConnectivityBindingResp(StunMessage* stunMsg, StunMsgId transactionId, const struct sockaddr* mappedSockAddr, uint8_t reqTrnspCnt, uint8_t respTrnspCnt, uint16_t response, uint32_t responseCode, DiscussData* discussData) { StunIPAddress mappedAddr; if ( !sockaddr_isSet(mappedSockAddr) ) { return false; } memset(stunMsg, 0, sizeof *stunMsg); stunMsg->msgHdr.msgType = response; if (reqTrnspCnt != 0) { stunMsg->hasTransCount = true; stunMsg->transCount.respCnt = respTrnspCnt; stunMsg->transCount.reqCnt = reqTrnspCnt; } if (mappedSockAddr->sa_family == AF_INET) { mappedAddr.familyType = STUN_ADDR_IPv4Family; mappedAddr.addr.v4.port = ntohs( ( (struct sockaddr_in*)mappedSockAddr )->sin_port); mappedAddr.addr.v4.addr = ntohl( ( (struct sockaddr_in*)mappedSockAddr )->sin_addr.s_addr); } else if (mappedSockAddr->sa_family == AF_INET6) { mappedAddr.familyType = STUN_ADDR_IPv6Family; mappedAddr.addr.v6.port = ntohs( ( (struct sockaddr_in6*)mappedSockAddr )->sin6_port); /*TODO: will this be correct ? */ memcpy( mappedAddr.addr.v6.addr, ( (struct sockaddr_in6*)mappedSockAddr )->sin6_addr.s6_addr, sizeof(mappedAddr.addr.v6.addr) ); } else { return false; } /*id*/ stunMsg->msgHdr.id = transactionId; /* The XOR address MUST be added according to the RFC */ stunMsg->hasXorMappedAddress = true; stunMsg->xorMappedAddress = mappedAddr; if (discussData != NULL) { stunMsg->hasStreamType = true; stunMsg->streamType.type = discussData->streamType; stunMsg->streamType.interactivity = discussData->interactivity; stunMsg->hasNetworkStatus = true; stunMsg->networkStatus.flags = 0; stunMsg->networkStatus.nodeCnt = 0; stunMsg->networkStatus.upMaxBandwidth = 0; stunMsg->networkStatus.downMaxBandwidth = 0; stunMsg->hasNetworkStatusResp = true; stunMsg->networkStatusResp.flags = discussData->networkStatusResp_flags; stunMsg->networkStatusResp.nodeCnt = discussData->networkStatusResp_nodeCnt; stunMsg->networkStatusResp.upMaxBandwidth = discussData->networkStatusResp_upMaxBandwidth; stunMsg->networkStatusResp.downMaxBandwidth = discussData->networkStatusResp_downMaxBandwidth; } if (responseCode != 200) { stunMsg->hasErrorCode = true; stunMsg->errorCode.errorClass = responseCode / 100; stunMsg->errorCode.number = (uint8_t) (responseCode % 100); if (responseCode == 487) { strncpy( stunMsg->errorCode.reason, "Role Conflict", sizeof (stunMsg->errorCode.reason) ); stunMsg->errorCode.sizeReason = strlen(stunMsg->errorCode.reason); } else if (responseCode == 400) { strncpy( stunMsg->errorCode.reason, "Bad Request", sizeof (stunMsg->errorCode.reason) ); stunMsg->errorCode.sizeReason = strlen(stunMsg->errorCode.reason); } } return true; }