Skip to content

Commit 34d4d64

Browse files
authored
Merge pull request #582 from h2o/kazuho/no-tcpip-in-headers
avoid dependency: picotls.h -> TCP/IP
2 parents e68c72b + ce442fb commit 34d4d64

File tree

2 files changed

+11
-13
lines changed

2 files changed

+11
-13
lines changed

include/picotls.h

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,6 @@ extern "C" {
3434
#include <inttypes.h>
3535
#include <string.h>
3636
#include <sys/types.h>
37-
#ifndef _WINDOWS
38-
#include <netinet/in.h>
39-
#include <arpa/inet.h>
40-
#endif
4137

4238
#if __GNUC__ >= 3
4339
#define PTLS_LIKELY(x) __builtin_expect(!!(x), 1)
@@ -1531,9 +1527,9 @@ typedef struct st_ptls_log_conn_state_t {
15311527
*/
15321528
float random_;
15331529
/**
1534-
* represents peer address; ipv4 addresses are stored using the mapped form (::ffff:192.0.2.1)
1530+
* represents the peer address using ipv6; ipv4 addresses are stored using the mapped form (::ffff:192.0.2.1)
15351531
*/
1536-
struct in6_addr address;
1532+
uint8_t address[16];
15371533
struct st_ptls_log_state_t state;
15381534
} ptls_log_conn_state_t;
15391535

@@ -1954,9 +1950,9 @@ char *ptls_hexdump(char *dst, const void *src, size_t len);
19541950
*/
19551951
char *ptls_jsonescape(char *buf, const char *s, size_t len);
19561952
/**
1957-
* builds a v4-mapped address (i.e., ::ffff:192.0.2.1)
1953+
* Builds a v4-mapped address (i.e., ::ffff:192.0.2.1). The v4 address must be in big-endian.
19581954
*/
1959-
void ptls_build_v4_mapped_v6_address(struct in6_addr *v6, const struct in_addr *v4);
1955+
void ptls_build_v4_mapped_v6_address(void *v6, const void *v4);
19601956

19611957
/**
19621958
* the default get_time callback

lib/picotls.c

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6773,10 +6773,11 @@ char *ptls_jsonescape(char *buf, const char *unsafe_str, size_t len)
67736773
return dst;
67746774
}
67756775

6776-
void ptls_build_v4_mapped_v6_address(struct in6_addr *v6, const struct in_addr *v4)
6776+
void ptls_build_v4_mapped_v6_address(void *v6, const void *v4)
67776777
{
6778-
*v6 = (struct in6_addr){.s6_addr[10] = 0xff, .s6_addr[11] = 0xff};
6779-
memcpy(&v6->s6_addr[12], &v4->s_addr, 4);
6778+
memset(v6, 0, 10);
6779+
memset((uint8_t *)v6 + 10, 0xff, 2);
6780+
memcpy((uint8_t *)v6 + 12, v4, 4);
67806781
}
67816782

67826783
struct st_ptls_log_t ptls_log = {
@@ -6939,7 +6940,8 @@ void ptls_log__recalc_conn(int caller_locked, struct st_ptls_log_conn_state_t *c
69396940
const char *sni = get_sni != NULL ? get_sni(get_sni_arg) : NULL;
69406941
for (size_t slot = 0; slot < PTLS_ELEMENTSOF(logctx.conns); ++slot) {
69416942
if (logctx.conns[slot].points != NULL && conn->random_ < logctx.conns[slot].sample_ratio &&
6942-
is_in_stringlist(logctx.conns[slot].snis, sni) && is_in_addresslist(logctx.conns[slot].addresses, &conn->address)) {
6943+
is_in_stringlist(logctx.conns[slot].snis, sni) &&
6944+
is_in_addresslist(logctx.conns[slot].addresses, (struct in6_addr *)&conn->address)) {
69436945
new_active |= (uint32_t)1 << slot;
69446946
}
69456947
}
@@ -7154,7 +7156,7 @@ void ptls_log_init_conn_state(ptls_log_conn_state_t *state, void (*random_bytes)
71547156

71557157
*state = (ptls_log_conn_state_t){
71567158
.random_ = (float)r / ((uint64_t)UINT32_MAX + 1), /* [0..1), so that any(r) < sample_ratio where sample_ratio is [0..1] */
7157-
.address = in6addr_any,
7159+
.address = {0}, /* inaddr6_any */
71587160
};
71597161
}
71607162

0 commit comments

Comments
 (0)