Skip to content

Commit c756305

Browse files
author
Lukáš Ondráček
committed
daemon/defer: fix port byte order in sigsafe_format
1 parent 79c021e commit c756305

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

daemon/defer.c

+4-2
Original file line numberDiff line numberDiff line change
@@ -129,12 +129,14 @@ int sigsafe_format(char *str, size_t size, const char *fmt, ...) {
129129
case AF_INET: {
130130
struct sockaddr_in *addr4 = (struct sockaddr_in *)addr;
131131
uint8_t *ipv4 = (uint8_t *)&(addr4->sin_addr);
132-
strp += sigsafe_format(strp, stre-strp, "%u.%u.%u.%u#%u", ipv4[0], ipv4[1], ipv4[2], ipv4[3], addr4->sin_port);
132+
uint8_t *port = (uint8_t *)&(addr4->sin_port);
133+
strp += sigsafe_format(strp, stre-strp, "%u.%u.%u.%u#%u", ipv4[0], ipv4[1], ipv4[2], ipv4[3], (port[0] << 8) | port[1]);
133134
append_str = "";
134135
} break;
135136
case AF_INET6: {
136137
struct sockaddr_in6 *addr6 = (struct sockaddr_in6 *)addr;
137138
uint8_t *ipv6 = (uint8_t *)&(addr6->sin6_addr);
139+
uint8_t *port = (uint8_t *)&(addr6->sin6_port);
138140
int mzb = -2, mze = 0; // maximal zero-filled gap begin (incl.) and end (excl.)
139141
{ // find longest gap
140142
int zb = 0, ze = 0;
@@ -162,7 +164,7 @@ int sigsafe_format(char *str, size_t size, const char *fmt, ...) {
162164
strp += sigsafe_format(strp, stre-strp, "%x", (ipv6[i] << 8) | ipv6[i+1]);
163165
}
164166
}
165-
strp += sigsafe_format(strp, stre-strp, "#%u", addr6->sin6_port);
167+
strp += sigsafe_format(strp, stre-strp, "#%u", (port[0] << 8) | port[1]);
166168
append_str = "";
167169
} break;
168170
case AF_UNSPEC:

0 commit comments

Comments
 (0)