diff options
| author | Dirk Engling <erdgeist@erdgeist.org> | 2026-10-24 00:15:34 +0200 |
|---|---|---|
| committer | Dirk Engling <erdgeist@erdgeist.org> | 2026-10-24 00:15:34 +0200 |
| commit | 6d97e999f1e7b4476faf749abbb5e925d09208c6 (patch) | |
| tree | f22c04816949de04fc6b971c0a50f98f1cefd1ba /ot_livesync.c | |
| parent | 4ece9d359fd6668bfbc9c4260463f5b5913ae8fc (diff) | |
Replace endianess helpers and remove unused system and libowfat included
* Replace libowfat big endian packers with htonl/ntohl
* Turn bucket derivation in ot_mutex.c into its own helper
* remove unused includes
Diffstat (limited to 'ot_livesync.c')
| -rw-r--r-- | ot_livesync.c | 15 |
1 files changed, 10 insertions, 5 deletions
diff --git a/ot_livesync.c b/ot_livesync.c index efba4d7..b876ef8 100644 --- a/ot_livesync.c +++ b/ot_livesync.c | |||
| @@ -4,15 +4,14 @@ | |||
| 4 | $id$ */ | 4 | $id$ */ |
| 5 | 5 | ||
| 6 | /* System */ | 6 | /* System */ |
| 7 | #include <arpa/inet.h> | ||
| 7 | #include <pthread.h> | 8 | #include <pthread.h> |
| 8 | #include <stdlib.h> | 9 | #include <stdlib.h> |
| 9 | #include <string.h> | 10 | #include <string.h> |
| 10 | #include <sys/types.h> | 11 | #include <sys/types.h> |
| 11 | #include <sys/uio.h> | ||
| 12 | #include <unistd.h> | 12 | #include <unistd.h> |
| 13 | 13 | ||
| 14 | /* Libowfat */ | 14 | /* Libowfat */ |
| 15 | #include "byte.h" | ||
| 16 | #include "ip6.h" | 15 | #include "ip6.h" |
| 17 | #include "ndelay.h" | 16 | #include "ndelay.h" |
| 18 | #include "socket.h" | 17 | #include "socket.h" |
| @@ -58,6 +57,8 @@ static sync_buffer g_v4_buf; | |||
| 58 | 57 | ||
| 59 | static pthread_t thread_id; | 58 | static pthread_t thread_id; |
| 60 | void livesync_init(void) { | 59 | void livesync_init(void) { |
| 60 | uint32_t packet_type6 = htonl(OT_SYNC_PEER6); | ||
| 61 | uint32_t packet_type4 = htonl(OT_SYNC_PEER4); | ||
| 61 | 62 | ||
| 62 | if (g_socket_in == -1) | 63 | if (g_socket_in == -1) |
| 63 | exerr("No socket address for live sync specified."); | 64 | exerr("No socket address for live sync specified."); |
| @@ -66,8 +67,8 @@ void livesync_init(void) { | |||
| 66 | memcpy(g_v6_buf.data, &g_tracker_id, sizeof(g_tracker_id)); | 67 | memcpy(g_v6_buf.data, &g_tracker_id, sizeof(g_tracker_id)); |
| 67 | memcpy(g_v4_buf.data, &g_tracker_id, sizeof(g_tracker_id)); | 68 | memcpy(g_v4_buf.data, &g_tracker_id, sizeof(g_tracker_id)); |
| 68 | 69 | ||
| 69 | uint32_pack_big((char *)g_v6_buf.data + sizeof(g_tracker_id), OT_SYNC_PEER6); | 70 | memcpy(g_v6_buf.data + sizeof(g_tracker_id), &packet_type6, sizeof(packet_type6)); |
| 70 | uint32_pack_big((char *)g_v4_buf.data + sizeof(g_tracker_id), OT_SYNC_PEER4); | 71 | memcpy(g_v4_buf.data + sizeof(g_tracker_id), &packet_type4, sizeof(packet_type4)); |
| 71 | 72 | ||
| 72 | g_v6_buf.fill = sizeof(g_tracker_id) + sizeof(uint32_t); | 73 | g_v6_buf.fill = sizeof(g_tracker_id) + sizeof(uint32_t); |
| 73 | g_v4_buf.fill = sizeof(g_tracker_id) + sizeof(uint32_t); | 74 | g_v4_buf.fill = sizeof(g_tracker_id) + sizeof(uint32_t); |
| @@ -216,6 +217,8 @@ static void *livesync_worker(void *args) { | |||
| 216 | memcpy(in_ip, V4mappedprefix, sizeof(V4mappedprefix)); | 217 | memcpy(in_ip, V4mappedprefix, sizeof(V4mappedprefix)); |
| 217 | 218 | ||
| 218 | while (1) { | 219 | while (1) { |
| 220 | uint32_t packet_type; | ||
| 221 | |||
| 219 | ws.request_size = socket_recv4(g_socket_in, (char *)ws.inbuf, LIVESYNC_INCOMING_BUFFSIZE, 12 + (char *)in_ip, &in_port); | 222 | ws.request_size = socket_recv4(g_socket_in, (char *)ws.inbuf, LIVESYNC_INCOMING_BUFFSIZE, 12 + (char *)in_ip, &in_port); |
| 220 | 223 | ||
| 221 | /* Expect at least tracker id and packet type */ | 224 | /* Expect at least tracker id and packet type */ |
| @@ -228,7 +231,9 @@ static void *livesync_worker(void *args) { | |||
| 228 | continue; | 231 | continue; |
| 229 | } | 232 | } |
| 230 | 233 | ||
| 231 | switch (uint32_read_big(sizeof(g_tracker_id) + (char *)ws.inbuf)) { | 234 | memcpy(&packet_type, ws.inbuf + sizeof(g_tracker_id), sizeof(packet_type)); |
| 235 | |||
| 236 | switch (ntohl(packet_type)) { | ||
| 232 | case OT_SYNC_PEER6: | 237 | case OT_SYNC_PEER6: |
| 233 | livesync_handle_peersync(&ws, OT_PEER_SIZE6); | 238 | livesync_handle_peersync(&ws, OT_PEER_SIZE6); |
| 234 | break; | 239 | break; |
