mirror of
https://github.com/systemd/systemd.git
synced 2025-03-19 22:50:17 +03:00
sd-dhcp: network - don't hardcode ports
We want to reuse these functions for the server library too.
This commit is contained in:
parent
818dc5e72a
commit
080ab27621
@ -30,10 +30,10 @@
|
||||
#include "dhcp-protocol.h"
|
||||
|
||||
int dhcp_network_bind_raw_socket(int index, union sockaddr_union *link);
|
||||
int dhcp_network_bind_udp_socket(int index, be32_t client_address);
|
||||
int dhcp_network_bind_udp_socket(int index, be32_t address, uint16_t port);
|
||||
int dhcp_network_send_raw_socket(int s, const union sockaddr_union *link,
|
||||
const void *packet, size_t len);
|
||||
int dhcp_network_send_udp_socket(int s, be32_t server_address,
|
||||
int dhcp_network_send_udp_socket(int s, be32_t address, uint16_t port,
|
||||
const void *packet, size_t len);
|
||||
|
||||
int dhcp_option_append(uint8_t **buf, size_t *buflen, uint8_t code,
|
||||
|
@ -56,13 +56,13 @@ int dhcp_network_bind_raw_socket(int index, union sockaddr_union *link)
|
||||
return s;
|
||||
}
|
||||
|
||||
int dhcp_network_bind_udp_socket(int index, be32_t client_address)
|
||||
int dhcp_network_bind_udp_socket(int index, be32_t address, uint16_t port)
|
||||
{
|
||||
int s;
|
||||
union sockaddr_union src = {
|
||||
.in.sin_family = AF_INET,
|
||||
.in.sin_port = htobe16(DHCP_PORT_CLIENT),
|
||||
.in.sin_addr.s_addr = client_address,
|
||||
.in.sin_port = htobe16(port),
|
||||
.in.sin_addr.s_addr = address,
|
||||
};
|
||||
|
||||
s = socket(AF_INET, SOCK_DGRAM | SOCK_CLOEXEC | SOCK_NONBLOCK, 0);
|
||||
@ -90,13 +90,13 @@ int dhcp_network_send_raw_socket(int s, const union sockaddr_union *link,
|
||||
return 0;
|
||||
}
|
||||
|
||||
int dhcp_network_send_udp_socket(int s, be32_t server_address,
|
||||
int dhcp_network_send_udp_socket(int s, be32_t address, uint16_t port,
|
||||
const void *packet, size_t len)
|
||||
{
|
||||
union sockaddr_union dest = {
|
||||
.in.sin_family = AF_INET,
|
||||
.in.sin_port = htobe16(DHCP_PORT_SERVER),
|
||||
.in.sin_addr.s_addr = server_address,
|
||||
.in.sin_port = htobe16(port),
|
||||
.in.sin_addr.s_addr = address,
|
||||
};
|
||||
|
||||
if (sendto(s, packet, len, 0, &dest.sa, sizeof(dest.in)) < 0)
|
||||
|
@ -324,6 +324,7 @@ static int client_send_request(sd_dhcp_client *client, uint16_t secs) {
|
||||
if (client->state == DHCP_STATE_RENEWING) {
|
||||
err = dhcp_network_send_udp_socket(client->fd,
|
||||
client->lease->server_address,
|
||||
DHCP_PORT_SERVER,
|
||||
&request->dhcp,
|
||||
len - DHCP_IP_UDP_SIZE);
|
||||
} else {
|
||||
@ -535,7 +536,8 @@ static int client_timeout_t1(sd_event_source *s, uint64_t usec,
|
||||
client->attempt = 1;
|
||||
|
||||
r = dhcp_network_bind_udp_socket(client->index,
|
||||
client->lease->address);
|
||||
client->lease->address,
|
||||
DHCP_PORT_CLIENT);
|
||||
if (r < 0) {
|
||||
client_stop(client, r);
|
||||
return 0;
|
||||
|
@ -191,12 +191,12 @@ int dhcp_network_bind_raw_socket(int index, union sockaddr_union *link)
|
||||
return test_fd[0];
|
||||
}
|
||||
|
||||
int dhcp_network_bind_udp_socket(int index, be32_t client_address)
|
||||
int dhcp_network_bind_udp_socket(int index, be32_t address, uint16_t port)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
int dhcp_network_send_udp_socket(int s, be32_t server_address,
|
||||
int dhcp_network_send_udp_socket(int s, be32_t address, uint16_t port,
|
||||
const void *packet, size_t len)
|
||||
{
|
||||
return 0;
|
||||
|
Loading…
x
Reference in New Issue
Block a user