UDPC_Context* UDPC_init(uint16_t listenPort, uint32_t listenAddr, int isClient)
{
UDPC_Context *context = malloc(sizeof(UDPC_Context));
+ context->protocolID = UDPC_PKT_DEFAULT_PROTOCOL_ID;
context->error = UDPC_SUCCESS;
context->flags = 0x4C;
if(isClient != 0) context->flags |= 0x2;
if((ctx->flags & 0x1) != 0) { mtx_unlock(&ctx->tCVMtx); }
}
+uint32_t UDPC_get_protocol_id(UDPC_Context *ctx)
+{
+ if((ctx->flags & 0x1) != 0) { mtx_lock(&ctx->tCVMtx); }
+
+ uint32_t id = ctx->protocolID;
+
+ if((ctx->flags & 0x1) != 0) { mtx_unlock(&ctx->tCVMtx); }
+
+ return id;
+}
+
+void UDPC_set_protocol_id(UDPC_Context *ctx, uint32_t id)
+{
+ if((ctx->flags & 0x1) != 0) { mtx_lock(&ctx->tCVMtx); }
+
+ ctx->protocolID = id;
+
+ if((ctx->flags & 0x1) != 0) { mtx_unlock(&ctx->tCVMtx); }
+}
+
uint32_t UDPC_get_error(UDPC_Context *ctx)
{
if((ctx->flags & 0x1) != 0) { mtx_lock(&ctx->tCVMtx); }
}
uint32_t temp = ntohl(*((uint32_t*)ctx->recvBuf));
- if(temp != UDPC_PKT_PROTOCOL_ID)
+ if(temp != ctx->protocolID)
{
UDPC_INTERNAL_log(ctx, 2, "Got invalid packet from %s port %d (invalid protocol id)",
UDPC_INTERNAL_atostr(ctx, receivedData.sin_addr.s_addr),
char *data = malloc(20);
UDPC_INTERNAL_prepare_pkt(
data,
+ us->ctx->protocolID,
UDPC_ID_CONNECT,
0,
0xFFFFFFFF,
char *data = malloc(20);
UDPC_INTERNAL_prepare_pkt(
data,
+ us->ctx->protocolID,
UDPC_ID_CONNECT | cd->id,
cd->rseq,
cd->ack,
}
char *data = malloc(20);
- UDPC_INTERNAL_prepare_pkt(data, cd->id, cd->rseq, cd->ack, &cd->lseq, 0);
+ UDPC_INTERNAL_prepare_pkt(
+ data, us->ctx->protocolID, cd->id, cd->rseq, cd->ack, &cd->lseq, 0);
struct sockaddr_in destinationInfo;
destinationInfo.sin_family = AF_INET;
char *data = malloc(20 + pinfo->size);
UDPC_INTERNAL_prepare_pkt(
data,
+ us->ctx->protocolID,
cd->id,
cd->rseq,
cd->ack,
void UDPC_INTERNAL_prepare_pkt(
void *data,
+ uint32_t protocolID,
uint32_t conID,
uint32_t rseq,
uint32_t ack,
char *d = data;
uint32_t temp;
- temp = htonl(UDPC_PKT_PROTOCOL_ID);
+ temp = htonl(protocolID);
memcpy(d, &temp, 4);
if((flags & 0x4) == 0)
{
* 0x1 - thread should stop
*/
uint32_t threadFlags;
+ uint32_t protocolID;
uint32_t error;
int socketHandle;
struct sockaddr_in socketInfo;
*/
void UDPC_set_accept_new_connections(UDPC_Context *ctx, int isAccepting);
+/// Gets the currently set protocol id
+uint32_t UDPC_get_protocol_id(UDPC_Context *ctx);
+
+/// Sets the protocol id
+/*!
+ * Note that UDPC can only connect to other UDPC instances that use the same
+ * protocol id.
+ */
+void UDPC_set_protocol_id(UDPC_Context *ctx, uint32_t id);
+
/*!
* \brief Get the currently set error code, and clear it internally
* Error codes and their meanings are defined in UDPC_Defines.h .
*/
void UDPC_INTERNAL_prepare_pkt(
void *data,
+ uint32_t protocolID,
uint32_t conID,
uint32_t rseq,
uint32_t ack,