Commit 09991e75 authored by Jan Včelák's avatar Jan Včelák 🚀

server: sockaddr instead of sockaddr_storage for const params

parent 302ff946
......@@ -614,7 +614,8 @@ struct sockaddr_storage conf_addr(
free(tmp);
}
} else if (no_port) {
sockaddr_port_set(&out, val->item->var.a.dflt_port);
sockaddr_port_set((struct sockaddr *)&out,
val->item->var.a.dflt_port);
}
} else {
const char *dflt_socket = val->item->var.a.dflt_socket;
......@@ -691,11 +692,14 @@ bool conf_addr_range_match(
min = conf_addr_range(range, &max, &mask);
if (max.ss_family == AF_UNSPEC) {
if (sockaddr_net_match(addr, &min, mask)) {
if (sockaddr_net_match((struct sockaddr *)addr,
(struct sockaddr *)&min, mask)) {
return true;
}
} else {
if (sockaddr_range_match(addr, &min, &max)) {
if (sockaddr_range_match((struct sockaddr *)addr,
(struct sockaddr *)&min,
(struct sockaddr *)&max)) {
return true;
}
}
......
......@@ -390,14 +390,14 @@ static int rosedb_log_message(char *stream, size_t *maxlen, knot_pkt_t *pkt,
/* Field 2/3 Remote, local address. */
const struct sockaddr *remote = (const struct sockaddr *)qdata->param->remote;
memcpy(&addr, remote, sockaddr_len(remote));
int client_port = sockaddr_port(&addr);
sockaddr_port_set(&addr, 0);
STREAM_WRITE(stream, maxlen, sockaddr_tostr, &addr);
int client_port = sockaddr_port((struct sockaddr *)&addr);
sockaddr_port_set((struct sockaddr *)&addr, 0);
STREAM_WRITE(stream, maxlen, sockaddr_tostr, (struct sockaddr *)&addr);
STREAM_WRITE(stream, maxlen, snprintf, "\t");
getsockname(qdata->param->socket, (struct sockaddr *)&addr, &addr_len);
int server_port = sockaddr_port(&addr);
sockaddr_port_set(&addr, 0);
STREAM_WRITE(stream, maxlen, sockaddr_tostr, &addr);
int server_port = sockaddr_port((struct sockaddr *)&addr);
sockaddr_port_set((struct sockaddr *)&addr, 0);
STREAM_WRITE(stream, maxlen, sockaddr_tostr, (struct sockaddr *)&addr);
STREAM_WRITE(stream, maxlen, snprintf, "\t");
/* Field 4/5 Local, remote port. */
......@@ -485,8 +485,7 @@ static int rosedb_send_log(int sock, struct sockaddr_storage *dst_addr, knot_pkt
}
/* Send log message line. */
net_dgram_send(sock, (uint8_t *)buf, sizeof(buf) - maxlen, dst_addr);
net_dgram_send(sock, (uint8_t *)buf, sizeof(buf) - maxlen, (struct sockaddr *)dst_addr);
return ret;
}
......@@ -550,7 +549,7 @@ static int rosedb_synth(knot_pkt_t *pkt, const knot_dname_t *key, struct iter *i
/* Send message to syslog. */
struct sockaddr_storage syslog_addr;
if (sockaddr_set(&syslog_addr, AF_INET, entry.syslog_ip, DEFAULT_PORT) == KNOT_EOK) {
int sock = net_unbound_socket(SOCK_DGRAM, &syslog_addr);
int sock = net_unbound_socket(SOCK_DGRAM, (struct sockaddr *)&syslog_addr);
if (sock > 0) {
rosedb_send_log(sock, &syslog_addr, pkt,
entry.threat_code, qdata);
......
......@@ -339,11 +339,15 @@ static int template_match(int state, synth_template_t *tpl, knot_pkt_t *pkt, str
return state;
}
if (tpl->addr_max.ss_family == AF_UNSPEC) {
if (!sockaddr_net_match(&query_addr, &tpl->addr, tpl->mask)) {
if (!sockaddr_net_match((struct sockaddr *)&query_addr,
(struct sockaddr *)&tpl->addr,
tpl->mask)) {
return state; /* Out of our netblock, not applicable. */
}
} else {
if (!sockaddr_range_match(&query_addr, &tpl->addr, &tpl->addr_max)) {
if (!sockaddr_range_match((struct sockaddr *)&query_addr,
(struct sockaddr *)&tpl->addr,
(struct sockaddr *)&tpl->addr_max)) {
return state; /* Out of our netblock, not applicable. */
}
}
......
......@@ -27,6 +27,6 @@
*/
#define NS_PROC_LOG(priority, zone, remote, operation, msg, ...) do { \
char addr[SOCKADDR_STRLEN] = ""; \
sockaddr_tostr(addr, sizeof(addr), remote); \
sockaddr_tostr(addr, sizeof(addr), (struct sockaddr *)remote); \
log_msg_zone(priority, zone, "%s, %s: " msg, operation, addr, ##__VA_ARGS__); \
} while (0)
......@@ -584,7 +584,7 @@ bool process_query_acl_check(conf_t *conf, const knot_dname_t *zone_name,
conf_val_t acl = conf_zone_get(conf, C_ACL, zone_name);
if (!acl_allowed(conf, &acl, action, query_source, &tsig)) {
char addr_str[SOCKADDR_STRLEN] = { 0 };
sockaddr_tostr(addr_str, sizeof(addr_str), query_source);
sockaddr_tostr(addr_str, sizeof(addr_str), (struct sockaddr *)query_source);
const knot_lookup_t *act = knot_lookup_by_id((knot_lookup_t *)acl_actions,
action);
char *key_name = knot_dname_to_str_alloc(tsig.name);
......
......@@ -346,7 +346,7 @@ static void send_update_response(conf_t *conf, const zone_t *zone, struct knot_r
timeout);
} else {
net_dgram_send(req->fd, req->resp->wire, req->resp->size,
&req->remote);
(struct sockaddr *)&req->remote);
}
}
}
......
......@@ -36,7 +36,9 @@ static int request_ensure_connected(struct knot_request *request)
}
int sock_type = use_tcp(request) ? SOCK_STREAM : SOCK_DGRAM;
request->fd = net_connected_socket(sock_type, &request->remote, &request->source);
request->fd = net_connected_socket(sock_type,
(struct sockaddr *)&request->remote,
(struct sockaddr *)&request->source);
if (request->fd < 0) {
return KNOT_ECONN;
}
......
......@@ -288,7 +288,7 @@ static void rrl_log_state(const struct sockaddr_storage *ss, uint16_t flags, uin
{
#ifdef RRL_ENABLE_LOG
char addr_str[SOCKADDR_STRLEN] = {0};
sockaddr_tostr(addr_str, sizeof(addr_str), ss);
sockaddr_tostr(addr_str, sizeof(addr_str), (struct sockaddr *)ss);
const char *what = "leaves";
if (flags & RRL_BF_ELIMIT) {
......
......@@ -148,7 +148,7 @@ static int server_init_iface(iface_t *new_if, struct sockaddr_storage *addr, int
/* Convert to string address format. */
char addr_str[SOCKADDR_STRLEN] = { 0 };
sockaddr_tostr(addr_str, sizeof(addr_str), addr);
sockaddr_tostr(addr_str, sizeof(addr_str), (struct sockaddr *)addr);
int udp_socket_count = 1;
int bind_flags = 0;
......@@ -174,10 +174,10 @@ static int server_init_iface(iface_t *new_if, struct sockaddr_storage *addr, int
/* Create bound UDP sockets. */
for (int i = 0; i < udp_socket_count; i++ ) {
int sock = net_bound_socket(SOCK_DGRAM, addr, bind_flags);
int sock = net_bound_socket(SOCK_DGRAM, (struct sockaddr *)addr, bind_flags);
if (sock == KNOT_EADDRNOTAVAIL) {
bind_flags |= NET_BIND_NONLOCAL;
sock = net_bound_socket(SOCK_DGRAM, addr, bind_flags);
sock = net_bound_socket(SOCK_DGRAM, (struct sockaddr *)addr, bind_flags);
if (sock >= 0 && !warn_bind) {
log_warning("address '%s' is not available", addr_str);
warn_bind = true;
......@@ -197,7 +197,7 @@ static int server_init_iface(iface_t *new_if, struct sockaddr_storage *addr, int
warn_bufsize = true;
}
if (sockaddr_is_any(addr) && !enable_pktinfo(sock, addr->ss_family)) {
if (sockaddr_is_any((struct sockaddr *)addr) && !enable_pktinfo(sock, addr->ss_family)) {
log_warning("failed to enable received packet information retrieval");
}
......@@ -206,7 +206,7 @@ static int server_init_iface(iface_t *new_if, struct sockaddr_storage *addr, int
}
/* Create bound TCP socket. */
int sock = net_bound_socket(SOCK_STREAM, addr, bind_flags);
int sock = net_bound_socket(SOCK_STREAM, (struct sockaddr *)addr, bind_flags);
if (sock < 0) {
log_error("cannot bind address '%s' (%s)", addr_str,
knot_strerror(sock));
......@@ -239,7 +239,7 @@ static void remove_ifacelist(struct ref *p)
char addr_str[SOCKADDR_STRLEN] = {0};
iface_t *n = NULL, *m = NULL;
WALK_LIST_DELSAFE(n, m, ifaces->u) {
sockaddr_tostr(addr_str, sizeof(addr_str), &n->addr);
sockaddr_tostr(addr_str, sizeof(addr_str), (struct sockaddr *)&n->addr);
log_info("removing interface '%s'", addr_str);
server_remove_iface(n);
}
......@@ -286,7 +286,8 @@ static int reconfigure_sockets(conf_t *conf, server_t *s)
if (s->ifaces) {
WALK_LIST(m, s->ifaces->u) {
/* Matching port and address. */
if (sockaddr_cmp(&addr, &m->addr) == 0) {
if (sockaddr_cmp((struct sockaddr *)&addr,
(struct sockaddr *)&m->addr) == 0) {
found_match = 1;
break;
}
......@@ -298,7 +299,7 @@ static int reconfigure_sockets(conf_t *conf, server_t *s)
rem_node((node_t *)m);
} else {
char addr_str[SOCKADDR_STRLEN] = { 0 };
sockaddr_tostr(addr_str, sizeof(addr_str), &addr);
sockaddr_tostr(addr_str, sizeof(addr_str), (struct sockaddr *)&addr);
log_info("binding to interface '%s'", addr_str);
/* Create new interface. */
......
......@@ -80,7 +80,7 @@ static enum fdset_sweep_state tcp_sweep(fdset_t *set, int i, void *data)
socklen_t len = sizeof(struct sockaddr_storage);
if (getpeername(fd, (struct sockaddr*)&ss, &len) == 0) {
char addr_str[SOCKADDR_STRLEN] = {0};
sockaddr_tostr(addr_str, sizeof(addr_str), &ss);
sockaddr_tostr(addr_str, sizeof(addr_str), (struct sockaddr *)&ss);
log_notice("TCP, terminated inactive client, address '%s'", addr_str);
}
......@@ -123,7 +123,7 @@ static int tcp_handle(tcp_context_t *tcp, int fd,
if (ret <= 0) {
if (ret == KNOT_EAGAIN) {
char addr_str[SOCKADDR_STRLEN] = {0};
sockaddr_tostr(addr_str, sizeof(addr_str), &ss);
sockaddr_tostr(addr_str, sizeof(addr_str), (struct sockaddr *)&ss);
log_warning("TCP, connection timed out, address '%s'",
addr_str);
}
......
......@@ -230,7 +230,9 @@ int static preferred_master(conf_t *conf, zone_t *zone, conf_remote_t *master)
for (size_t i = 0; i < addr_count; i++) {
conf_remote_t remote = conf_remote(conf, &masters, i);
if (sockaddr_net_match(&remote.addr, zone->preferred_master, -1)) {
if (sockaddr_net_match((struct sockaddr *)&remote.addr,
(struct sockaddr *)zone->preferred_master,
-1)) {
*master = remote;
pthread_mutex_unlock(&zone->preferred_lock);
return KNOT_EOK;
......@@ -274,7 +276,9 @@ int zone_master_try(conf_t *conf, zone_t *zone, zone_master_cb callback,
for (size_t i = 0; i < addr_count; i++) {
conf_remote_t master = conf_remote(conf, &masters, i);
if (preferred.addr.ss_family != AF_UNSPEC &&
sockaddr_net_match(&master.addr, &preferred.addr, -1)) {
sockaddr_net_match((struct sockaddr *)&master.addr,
(struct sockaddr *)&preferred.addr,
-1)) {
preferred.addr.ss_family = AF_UNSPEC;
continue;
}
......
......@@ -206,7 +206,7 @@ int knot_ctl_bind(knot_ctl_t *ctx, const char *path)
}
// Bind the socket.
ctx->listen_sock = net_bound_socket(SOCK_STREAM, &addr, 0);
ctx->listen_sock = net_bound_socket(SOCK_STREAM, (struct sockaddr *)&addr, 0);
if (ctx->listen_sock < 0) {
return ctx->listen_sock;
}
......@@ -232,7 +232,7 @@ void knot_ctl_unbind(knot_ctl_t *ctx)
socklen_t addr_len = sizeof(addr);
if (getsockname(ctx->listen_sock, (struct sockaddr *)&addr, &addr_len) == 0) {
char addr_str[SOCKADDR_STRLEN] = { 0 };
if (sockaddr_tostr(addr_str, sizeof(addr_str), &addr) > 0) {
if (sockaddr_tostr(addr_str, sizeof(addr_str), (struct sockaddr *)&addr) > 0) {
(void)unlink(addr_str);
}
}
......@@ -284,7 +284,7 @@ int knot_ctl_connect(knot_ctl_t *ctx, const char *path)
}
// Connect to socket.
ctx->sock = net_connected_socket(SOCK_STREAM, &addr, NULL);
ctx->sock = net_connected_socket(SOCK_STREAM, (struct sockaddr *)&addr, NULL);
if (ctx->sock < 0) {
return ctx->sock;
}
......
......@@ -944,7 +944,7 @@ struct sockaddr_storage yp_addr(
if (addr_len > 0) {
int64_t port = wire_read_u64(data + sizeof(uint8_t) + addr_len);
if (port >= 0) {
sockaddr_port_set(&ss, port);
sockaddr_port_set((struct sockaddr *)&ss, port);
*no_port = false;
} else {
*no_port = true;
......
......@@ -140,7 +140,7 @@ void get_addr_str(const struct sockaddr_storage *ss,
char addr_str[SOCKADDR_STRLEN] = {0};
// Get network address string and port number.
sockaddr_tostr(addr_str, sizeof(addr_str), ss);
sockaddr_tostr(addr_str, sizeof(addr_str), (struct sockaddr *)ss);
// Calculate needed buffer size
const char *sock_name = get_sockname(socktype);
......
......@@ -114,16 +114,19 @@ static void fill_remote_addr(net_t *net, Dnstap__Message *message, bool is_initi
break;
}
ProtobufCBinaryData *addr = NULL;
uint32_t port = 0;
if (is_initiator) {
sockaddr_set_raw(&ss, family, message->response_address.data,
message->response_address.len);
sockaddr_port_set(&ss, message->response_port);
addr = &message->response_address;
port = message->response_port;
} else {
sockaddr_set_raw(&ss, family, message->query_address.data,
message->query_address.len);
sockaddr_port_set(&ss, message->query_port);
addr = &message->query_address;
port = message->query_port;
}
sockaddr_set_raw(&ss, family, addr->data, addr->len);
sockaddr_port_set((struct sockaddr *)&ss, port);
get_addr_str(&ss, sock_type, &net->remote_str);
}
......
......@@ -215,12 +215,12 @@ static void handler_echo(int sock, void *_server)
addr = &remote;
}
int in = net_recv(sock, buffer, sizeof(buffer), addr, TIMEOUT);
int in = net_recv(sock, buffer, sizeof(buffer), (struct sockaddr *)addr, TIMEOUT);
if (in <= 0) {
return;
}
net_send(sock, buffer, in, addr, TIMEOUT);
net_send(sock, buffer, in, (struct sockaddr *)addr, TIMEOUT);
}
static void test_connected_one(const struct sockaddr_storage *server_addr,
......@@ -229,7 +229,7 @@ static void test_connected_one(const struct sockaddr_storage *server_addr,
{
int r;
int client = net_connected_socket(type, server_addr, NULL);
int client = net_connected_socket(type, (struct sockaddr *)server_addr, NULL);
ok(client >= 0, "%s, %s: client, create connected socket", name, addr_name);
const uint8_t out[] = "test message";
......@@ -266,7 +266,7 @@ static void test_connected(int type)
// setup server
int server = net_bound_socket(type, &local_addr, 0);
int server = net_bound_socket(type, (struct sockaddr *)&local_addr, 0);
ok(server >= 0, "%s: server, create bound socket", name);
if (socktype_is_stream(type)) {
......@@ -307,7 +307,7 @@ static void test_unconnected(void)
// server
int server = net_bound_socket(SOCK_DGRAM, &local, 0);
int server = net_bound_socket(SOCK_DGRAM, (struct sockaddr *)&local, 0);
ok(server >= 0, "UDP, create server socket");
server_ctx_t server_ctx = { 0 };
......@@ -316,7 +316,7 @@ static void test_unconnected(void)
// UDP
sock = net_unbound_socket(SOCK_DGRAM, &local);
sock = net_unbound_socket(SOCK_DGRAM, (struct sockaddr *)&local);
ok(sock >= 0, "UDP, create unbound socket");
ok(!net_is_connected(sock), "UDP, is not connected");
......@@ -328,14 +328,14 @@ static void test_unconnected(void)
ok(r == KNOT_ETIMEOUT, "UDP, receive timeout on unconnected socket");
struct sockaddr_storage server_addr = addr_from_socket(server);
r = net_dgram_send(sock, buffer, buffer_len, &server_addr);
r = net_dgram_send(sock, buffer, buffer_len, (struct sockaddr *)&server_addr);
ok(r == buffer_len, "UDP, send on defined address");
close(sock);
// TCP
sock = net_unbound_socket(SOCK_STREAM, &local);
sock = net_unbound_socket(SOCK_STREAM, (struct sockaddr *)&local);
ok(sock >= 0, "TCP, create unbound socket");
ok(!net_is_connected(sock), "TCP, is not connected");
......@@ -399,14 +399,14 @@ static void test_refused(void)
// listening, not accepting
addr = addr_local();
server = net_bound_socket(SOCK_STREAM, &addr, 0);
server = net_bound_socket(SOCK_STREAM, (struct sockaddr *)&addr, 0);
ok(server >= 0, "server, create server");
addr = addr_from_socket(server);
r = listen(server, LISTEN_BACKLOG);
ok(r == 0, "server, start listening");
client = net_connected_socket(SOCK_STREAM, &addr, NULL);
client = net_connected_socket(SOCK_STREAM, (struct sockaddr *)&addr, NULL);
ok(client >= 0, "client, connect");
r = net_stream_send(client, (uint8_t *)"", 1, TIMEOUT);
......@@ -419,7 +419,7 @@ static void test_refused(void)
// listening, closed immediately
client = net_connected_socket(SOCK_STREAM, &addr, NULL);
client = net_connected_socket(SOCK_STREAM, (struct sockaddr *)&addr, NULL);
ok(client >= 0, "client, connect");
r = close(server);
......@@ -539,7 +539,7 @@ static void test_dns_tcp(void)
};
struct sockaddr_storage addr = addr_local();
int server = net_bound_socket(SOCK_STREAM, &addr, 0);
int server = net_bound_socket(SOCK_STREAM, (struct sockaddr *)&addr, 0);
ok(server >= 0, "%s, server, create socket", t->name);
int r = listen(server, LISTEN_BACKLOG);
......@@ -550,7 +550,7 @@ static void test_dns_tcp(void)
ok(r, "%s, server, start handler", t->name);
addr = addr_from_socket(server);
int client = net_connected_socket(SOCK_STREAM, &addr, NULL);
int client = net_connected_socket(SOCK_STREAM, (struct sockaddr *)&addr, NULL);
ok(client >= 0, "%s, client, create connected socket", t->name);
sync_wait(client);
......@@ -574,12 +574,12 @@ static void test_nonblocking_mode(int type)
const char *name = socktype_name(type);
const struct sockaddr_storage addr = addr_local();
int client = net_unbound_socket(type, &addr);
int client = net_unbound_socket(type, (struct sockaddr *)&addr);
ok(client >= 0, "%s: unbound, create", name);
ok(!socket_is_blocking(client), "%s: unbound, nonblocking mode", name);
close(client);
int server = net_bound_socket(type, &addr, 0);
int server = net_bound_socket(type, (struct sockaddr *)&addr, 0);
ok(server >= 0, "%s: bound, create", name);
ok(!socket_is_blocking(server), "%s: bound, nonblocking mode", name);
......@@ -589,7 +589,7 @@ static void test_nonblocking_mode(int type)
}
struct sockaddr_storage server_addr = addr_from_socket(server);
client = net_connected_socket(type, &server_addr, NULL);
client = net_connected_socket(type, (struct sockaddr *)&server_addr, NULL);
ok(client >= 0, "%s: connected, create", name);
ok(!socket_is_blocking(client), "%s: connected, nonblocking mode", name);
......@@ -605,7 +605,7 @@ static void test_nonblocking_accept(void)
struct sockaddr_storage addr_server = addr_local();
int server = net_bound_socket(SOCK_STREAM, &addr_server, 0);
int server = net_bound_socket(SOCK_STREAM, (struct sockaddr *)&addr_server, 0);
ok(server >= 0, "server, create socket");
r = listen(server, LISTEN_BACKLOG);
......@@ -615,7 +615,7 @@ static void test_nonblocking_accept(void)
// create client
int client = net_connected_socket(SOCK_STREAM, &addr_server, NULL);
int client = net_connected_socket(SOCK_STREAM, (struct sockaddr *)&addr_server, NULL);
ok(client >= 0, "client, create connected socket");
struct sockaddr_storage addr_client = addr_from_socket(client);
......@@ -631,14 +631,22 @@ static void test_nonblocking_accept(void)
ok(!socket_is_blocking(accepted), "accepted, nonblocking mode");
ok(sockaddr_cmp(&addr_client, &addr_accepted) == 0, "accepted, correct address");
char buf[128] = "";
sockaddr_tostr(buf, sizeof(buf), (struct sockaddr *)&addr_client);
diag("client %s", buf);
sockaddr_tostr(buf, sizeof(buf), (struct sockaddr *)&addr_accepted);
diag("accepted %s", buf);
ok(sockaddr_cmp((struct sockaddr *)&addr_client,
(struct sockaddr *)&addr_accepted) == 0,
"accepted, correct address");
close(client);
// client reconnect
close(client);
client = net_connected_socket(SOCK_STREAM, &addr_server, NULL);
client = net_connected_socket(SOCK_STREAM, (struct sockaddr *)&addr_server, NULL);
ok(client >= 0, "client, reconnect");
r = poll_read(server);
......@@ -672,7 +680,7 @@ static void test_socket_types(void)
};
for (const struct testcase *t = testcases; t->name != NULL; t++) {
int sock = net_unbound_socket(t->type, &addr);
int sock = net_unbound_socket(t->type, (struct sockaddr *)&addr);
ok(sock >= 0, "%s, create socket", t->name);
is_int(t->type, net_socktype(sock), "%s, socket type", t->name);
......@@ -692,7 +700,7 @@ static void test_bind_multiple(void)
// bind first socket
int sock_one = net_bound_socket(SOCK_DGRAM, &addr, NET_BIND_MULTIPLE);
int sock_one = net_bound_socket(SOCK_DGRAM, (struct sockaddr *)&addr, NET_BIND_MULTIPLE);
if (sock_one == KNOT_ENOTSUP) {
skip("not supported on this system");
return;
......@@ -702,7 +710,7 @@ static void test_bind_multiple(void)
// bind second socket to the same address
const struct sockaddr_storage addr_one = addr_from_socket(sock_one);
int sock_two = net_bound_socket(SOCK_DGRAM, &addr_one, NET_BIND_MULTIPLE);
int sock_two = net_bound_socket(SOCK_DGRAM, (struct sockaddr *)&addr_one, NET_BIND_MULTIPLE);
ok(sock_two >= 0, "bind second socket");
// compare sockets
......@@ -710,7 +718,9 @@ static void test_bind_multiple(void)
ok(sock_one != sock_two, "descriptors are different");
const struct sockaddr_storage addr_two = addr_from_socket(sock_two);
ok(sockaddr_cmp(&addr_one, &addr_two) == 0, "addresses are the same");
ok(sockaddr_cmp((struct sockaddr *)&addr_one,
(struct sockaddr *)&addr_two) == 0,
"addresses are the same");
close(sock_one);
close(sock_two);
......
......@@ -85,7 +85,7 @@ int main(int argc, char *argv[])
// create TCP server
struct sockaddr_storage addr = localhost();
int server = net_bound_socket(SOCK_STREAM, &addr, 0);
int server = net_bound_socket(SOCK_STREAM, (struct sockaddr *)&addr, 0);
ok(server >= 0, "server: bind socket");
r = listen(server, 0);
......@@ -98,7 +98,7 @@ int main(int argc, char *argv[])
// create TCP client
int client = net_connected_socket(SOCK_STREAM, &addr, NULL);
int client = net_connected_socket(SOCK_STREAM, (struct sockaddr *)&addr, NULL);
ok(client >= 0, "client: connect to server");
int optval = 8192;
......
......@@ -34,26 +34,26 @@ static void test_sockaddr_is_any(void)
ok(!sockaddr_is_any(SA(&path)), "sockaddr_is_any: unix");
struct sockaddr_storage ipv4_local = { 0 };
sockaddr_set(SA(&ipv4_local), AF_INET, "127.0.0.1", 0);
sockaddr_set(&ipv4_local, AF_INET, "127.0.0.1", 0);
ok(!sockaddr_is_any(SA(&ipv4_local)), "sockaddr_is_any: IPv4 local");
struct sockaddr_storage ipv4_any = { 0 };
sockaddr_set(SA(&ipv4_any), AF_INET, "0.0.0.0", 0);
sockaddr_set(&ipv4_any, AF_INET, "0.0.0.0", 0);
ok(sockaddr_is_any(SA(&ipv4_any)), "sockaddr_is_any: IPv4 any");
struct sockaddr_storage ipv6_local = { 0 };
sockaddr_set(SA(&ipv6_local), AF_INET6, "::1", 0);
sockaddr_set(&ipv6_local, AF_INET6, "::1", 0);
ok(!sockaddr_is_any(SA(&ipv6_local)), "sockaddr_is_any: IPv6 local");
struct sockaddr_storage ipv6_any = { 0 };
sockaddr_set(SA(&ipv6_any), AF_INET6, "::", 0);
sockaddr_set(&ipv6_any, AF_INET6, "::", 0);
ok(sockaddr_is_any(SA(&ipv6_any)), "sockaddr_is_any: IPv6 any");
}
static void check_sockaddr_set(struct sockaddr_storage *ss, int family,
const char *straddr, int port)
{
int ret = sockaddr_set(SA(ss), family, straddr, port);
int ret = sockaddr_set(ss, family, straddr, port);
ok(ret == KNOT_EOK, "set address '%s'", straddr);
}
......
......@@ -132,7 +132,7 @@ int main(int argc, char *argv[])
sockaddr_set(&server, AF_INET, "127.0.0.1", 0);
/* Bind to random port. */
int responder_fd = net_bound_socket(SOCK_STREAM, &server, 0);
int responder_fd = net_bound_socket(SOCK_STREAM, (struct sockaddr *)&server, 0);
assert(responder_fd >= 0);
socklen_t addr_len = sockaddr_len((struct sockaddr *)&server);
getsockname(responder_fd, (struct sockaddr *)&server, &addr_len);
......@@ -150,7 +150,7 @@ int main(int argc, char *argv[])
test_connected(&requestor, &server, &client);
/* Terminate responder. */
int conn = net_connected_socket(SOCK_STREAM, &server, NULL);
int conn = net_connected_socket(SOCK_STREAM, (struct sockaddr *)&server, NULL);
assert(conn > 0);
net_dns_tcp_send(conn, (uint8_t *)"", 1, TIMEOUT);
pthread_join(thread, NULL);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment