summaryrefslogtreecommitdiff
path: root/ecp/src/platform/posix/transport.c
diff options
context:
space:
mode:
Diffstat (limited to 'ecp/src/platform/posix/transport.c')
-rw-r--r--ecp/src/platform/posix/transport.c17
1 files changed, 11 insertions, 6 deletions
diff --git a/ecp/src/platform/posix/transport.c b/ecp/src/platform/posix/transport.c
index c41f0df..30822b6 100644
--- a/ecp/src/platform/posix/transport.c
+++ b/ecp/src/platform/posix/transport.c
@@ -1,4 +1,5 @@
#include <stdlib.h>
+#include <string.h>
#include <unistd.h>
#include <sys/socket.h>
#include <netinet/in.h>
@@ -14,13 +15,18 @@ int ecp_tr_init(ECPContext *ctx) {
return ECP_OK;
}
-int ecp_tr_addr_eq(ECPNetAddr *addr1, ECPNetAddr *addr2) {
+unsigned int ecp_tr_addr_hash(ecp_tr_addr_t *addr) {
+ unsigned int ret = *((unsigned int *)addr->host);
+ return ret ^ ((unsigned int)addr->port << 16);
+}
+
+int ecp_tr_addr_eq(ecp_tr_addr_t *addr1, ecp_tr_addr_t *addr2) {
if (addr1->port != addr2->port) return 0;
if (memcmp(addr1->host, addr2->host, sizeof(addr1->host)) != 0) return 0;
return 1;
}
-int ecp_tr_addr_set(ECPNetAddr *addr, void *addr_s) {
+int ecp_tr_addr_set(ecp_tr_addr_t *addr, void *addr_s) {
int rv;
char addr_c[ADDR_S_MAX];
char *colon = NULL;
@@ -49,7 +55,7 @@ int ecp_tr_open(ECPSocket *sock, void *addr_s) {
memset((char *)&_myaddr, 0, sizeof(_myaddr));
_myaddr.sin_family = AF_INET;
if (addr_s) {
- ECPNetAddr addr;
+ ecp_tr_addr_t addr;
int rv = ecp_tr_addr_set(&addr, addr_s);
if (rv) return rv;
@@ -75,7 +81,7 @@ void ecp_tr_close(ECPSocket *sock) {
close(sock->sock);
}
-ssize_t ecp_tr_send(ECPSocket *sock, ECPBuffer *packet, size_t msg_size, ECPNetAddr *addr, unsigned char flags) {
+ssize_t ecp_tr_send(ECPSocket *sock, ECPBuffer *packet, size_t msg_size, ecp_tr_addr_t *addr, unsigned char flags) {
struct sockaddr_in servaddr;
memset((void *)&servaddr, 0, sizeof(servaddr));
@@ -85,7 +91,7 @@ ssize_t ecp_tr_send(ECPSocket *sock, ECPBuffer *packet, size_t msg_size, ECPNetA
return sendto(sock->sock, packet->buffer, msg_size, 0, (struct sockaddr *)&servaddr, sizeof(servaddr));
}
-ssize_t ecp_tr_recv(ECPSocket *sock, ECPBuffer *packet, ECPNetAddr *addr, int timeout) {
+ssize_t ecp_tr_recv(ECPSocket *sock, ECPBuffer *packet, ecp_tr_addr_t *addr, int timeout) {
struct sockaddr_in servaddr;
socklen_t addrlen = sizeof(servaddr);
struct pollfd fds[] = {
@@ -111,4 +117,3 @@ ssize_t ecp_tr_recv(ECPSocket *sock, ECPBuffer *packet, ECPNetAddr *addr, int ti
void ecp_tr_release(ECPBuffer *packet, unsigned char more) {}
void ecp_tr_flag_set(unsigned char flags) {}
void ecp_tr_flag_clear(unsigned char flags) {}
-