Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

init dst address #164

Merged
merged 6 commits into from
Oct 13, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/net/net.c
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ int net_dst_source_addr_get(const struct sa *dst, struct sa *ip)
int err;
struct udp_sock *us;

if (!dst || !ip) {
if (!dst || !ip || !sa_isset(dst, SA_ADDR)) {
return EINVAL;
}

Expand Down
4 changes: 4 additions & 0 deletions src/sa/sa.c
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ int sa_pton(const char *addr, struct sa *sa)
if (!addr || !sa)
return EINVAL;

memset(sa, 0, sizeof(*sa));
if (inet_pton(AF_INET, addr, &sa->u.in.sin_addr) > 0) {
sa->u.in.sin_family = AF_INET;
}
Expand Down Expand Up @@ -186,6 +187,7 @@ void sa_set_in(struct sa *sa, uint32_t addr, uint16_t port)
if (!sa)
return;

memset(sa, 0, sizeof(*sa));
sa->u.in.sin_family = AF_INET;
sa->u.in.sin_addr.s_addr = htonl(addr);
sa->u.in.sin_port = htons(port);
Expand All @@ -208,6 +210,7 @@ void sa_set_in6(struct sa *sa, const uint8_t *addr, uint16_t port)
return;

#ifdef HAVE_INET6
memset(sa, 0, sizeof(*sa));
sa->u.in6.sin6_family = AF_INET6;
memcpy(&sa->u.in6.sin6_addr, addr, 16);
sa->u.in6.sin6_port = htons(port);
Expand All @@ -232,6 +235,7 @@ int sa_set_sa(struct sa *sa, const struct sockaddr *s)
if (!sa || !s)
return EINVAL;

memset(sa, 0, sizeof(*sa));
switch (s->sa_family) {

case AF_INET:
Expand Down