CTEST(stunserver, HandleReq_Valid) { STUN_INCOMING_REQ_DATA pReq; StunMessage stunMsg; stunMsg.hasUsername = true; stunMsg.username.sizeValue = 10; strncpy(stunMsg.username.value, "testPerson", stunMsg.username.sizeValue); stunMsg.username.value[stunMsg.username.sizeValue] = '\0'; stunMsg.hasPriority = true; stunMsg.priority.value = 1; bool fromRelay = false; ASSERT_FALSE( StunServer_HandleStunIncomingBindReqMsg(stunInstance, &pReq, &stunMsg, fromRelay) ); char ufrag[STUN_MAX_STRING] = "testPerson"; ASSERT_FALSE( strcmp(pReq.ufrag, ufrag) == 0); fromRelay = true; ASSERT_FALSE( StunServer_HandleStunIncomingBindReqMsg(stunInstance, &pReq, &stunMsg, fromRelay) ); }
void stunHandler(struct socketConfig* config, struct sockaddr* from_addr, void* cb, unsigned char* buf, int buflen) { StunMessage stunRequest; STUN_INCOMING_REQ_DATA pReq; STUN_CLIENT_DATA* clientData = (STUN_CLIENT_DATA*)cb; char realm[STUN_MSG_MAX_REALM_LENGTH]; printf("Got a STUN message... (%i)\n", buflen); stunlib_DecodeMessage(buf, buflen, &stunRequest, NULL, stdout); printf("Finished decoding..\n"); if (stunRequest.msgHdr.msgType == STUN_MSG_DataIndicationMsg) { if (stunRequest.hasData) { /* Decode and do something with the data? */ /* config->data_handler(config->socketConfig[i].sockfd, */ /* config->socketConfig[i].tInst, */ /* &buf[stunResponse.data.offset]); */ } } if (stunRequest.hasRealm) { memcpy(&realm, stunRequest.realm.value, STUN_MSG_MAX_REALM_LENGTH); } if (stunRequest.hasMessageIntegrity) { printf("Checking integrity..%s\n", config->pass); if ( stunlib_checkIntegrity( buf, buflen, &stunRequest, (uint8_t*)config->pass, strlen(config->pass) ) ) { printf(" - Integrity check OK\n"); } else { printf(" - Integrity check NOT OK\n"); } } StunServer_HandleStunIncomingBindReqMsg(clientData, &pReq, &stunRequest, false); StunServer_SendConnectivityBindingResp(clientData, config->sockfd, stunRequest.msgHdr.id, PASSWORD, from_addr, from_addr, NULL, sendPacket, SOCK_DGRAM, false, 200, NULL); }