#include <arpa/inet.h>
#include <stdio.h>
#include <string.h>
);
printf("Received message: %s on port %d\n",
}
};
}
}
int main() {
transport_properties,
AVOID);
NULL, 0, remotes, 1, transport_properties, NULL);
.
ready = send_message_and_receive,
.closed = free_on_connection_closed
};
preconnection,
&connection_callbacks);
if (rc < 0) {
perror("Error in initiating connection\n");
return rc;
}
return 0;
}
const ct_local_endpoint_t * ct_message_context_get_local_endpoint(const ct_message_context_t *message_context)
Get the local endpoint from a message context.
void ct_connection_close(ct_connection_t *connection)
Close a connection gracefully.
int ct_receive_message(ct_connection_t *connection, const ct_receive_callbacks_t *receive_callbacks)
Register callbacks to receive messages on a connection.
int ct_send_message(ct_connection_t *connection, const ct_message_t *message)
Send a message over a connection with default properties.
void ct_connection_free(ct_connection_t *connection)
Free resources in a connection.
int ct_start_event_loop(void)
Start the CTaps event loop (blocking operation).
int ct_close(void)
Close and cleanup the CTaps library.
int ct_initialize(void)
Initialize the CTaps library.
uint16_t ct_local_endpoint_get_resolved_port(const ct_local_endpoint_t *local_endpoint)
Get the resolved port for a local endpoint after binding.
const char * ct_message_get_content(const ct_message_t *message)
Get the content buffer of a message.
ct_message_t * ct_message_new_with_content(const char *content, size_t length)
Allocate a new message with content.
void ct_message_free(ct_message_t *message)
Free all resources in a message including the structure.
ct_preconnection_t * ct_preconnection_new(const ct_local_endpoint_t *const *local_endpoints, size_t num_local_endpoints, const ct_remote_endpoint_t *const *remote_endpoints, size_t num_remote_endpoints, const ct_transport_properties_t *transport_properties, const ct_security_parameters_t *security_parameters)
Create a new preconnection with transport properties and endpoints.
void ct_preconnection_free(ct_preconnection_t *preconnection)
Free a preconnection object.
int ct_preconnection_initiate(const ct_preconnection_t *preconnection, const ct_connection_callbacks_t *connection_callbacks)
Initiate a connection.
int ct_remote_endpoint_with_ipv4(ct_remote_endpoint_t *remote_endpoint, in_addr_t ipv4_addr)
Set the IPv4 address for a remote endpoint.
ct_remote_endpoint_t * ct_remote_endpoint_new(void)
Create a new heap-allocated remote endpoint.
void ct_remote_endpoint_free(ct_remote_endpoint_t *remote_endpoint)
Free all resources in a remote endpoint including the structure itself.
void ct_remote_endpoint_with_port(ct_remote_endpoint_t *remote_endpoint, uint16_t port)
Set the port number for a remote endpoint.
void ct_transport_properties_set_preserve_msg_boundaries(ct_transport_properties_t *transport_props, ct_selection_preference_enum_t val)
@ AVOID
Prefer protocols without this property if possible.
void ct_transport_properties_free(ct_transport_properties_t *props)
Free a transport properties object.
ct_transport_properties_t * ct_transport_properties_new(void)
Create a new transport properties object with default values.
Callback functions for connection lifecycle events.
void(* ready)(ct_connection_t *connection)
Called when connection is established and ready for data transfer.
Opaque handle representing a connection.
Opaque handle representing message metadata to pass to sending protocol.
Opaque handle representing a single message to be sent or received.
Opaque handle representing a preconnection.
Callback functions for receiving messages on a connection.
void(* receive_callback)(ct_connection_t *connection, ct_message_t *received_message, ct_message_context_t *ctx)
Called when a complete message is received.
Opaque handle representing a remote endpoint (generic or resolved to specific ip address and port).
Opaque handle representing transport properties used for selecting and configuring protocols.