Skip to content

Commit 2e1e9ee

Browse files
committed
usnic: ensure to use ntohl() for network-order values
(cherry-picked from open-mpi/ompi@dac2fe1)
1 parent 984d204 commit 2e1e9ee

File tree

3 files changed

+12
-8
lines changed

3 files changed

+12
-8
lines changed

ompi/mca/btl/usnic/btl_usnic_endpoint.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ typedef struct opal_btl_usnic_modex_t {
6969
uint32_t ipv4_addr;
7070
/* Stored in host order */
7171
uint32_t ports[USNIC_NUM_CHANNELS];
72+
/* Stored in network order */
7273
uint32_t netmask;
7374
/* Stored in host order */
7475
uint32_t connectivity_udp_port;

ompi/mca/btl/usnic/btl_usnic_util.c

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -115,24 +115,27 @@ opal_btl_usnic_dump_hex(void *vaddr, int len)
115115
* using inet_ntop()).
116116
*/
117117
void opal_btl_usnic_snprintf_ipv4_addr(char *out, size_t maxlen,
118-
uint32_t addr, uint32_t netmask)
118+
uint32_t addr_be, uint32_t netmask_be)
119119
{
120120
int prefixlen;
121+
uint32_t netmask = ntohl(netmask_be);
122+
uint32_t addr = ntohl(addr_be);
121123
uint8_t *p = (uint8_t*) &addr;
124+
122125
if (netmask != 0) {
123126
prefixlen = 33 - ffs(netmask);
124127
snprintf(out, maxlen, "%u.%u.%u.%u/%u",
125-
p[0],
126-
p[1],
127-
p[2],
128128
p[3],
129+
p[2],
130+
p[1],
131+
p[0],
129132
prefixlen);
130133
} else {
131134
snprintf(out, maxlen, "%u.%u.%u.%u",
132-
p[0],
133-
p[1],
135+
p[3],
134136
p[2],
135-
p[3]);
137+
p[1],
138+
p[0]);
136139
}
137140
}
138141

ompi/mca/btl/usnic/btl_usnic_util.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ void opal_btl_usnic_util_abort(const char *msg, const char *file, int line);
113113
* expected to be in network byte order.
114114
*/
115115
void opal_btl_usnic_snprintf_ipv4_addr(char *out, size_t maxlen,
116-
uint32_t addr, uint32_t netmask);
116+
uint32_t addr_be, uint32_t netmask_be);
117117

118118
void opal_btl_usnic_snprintf_bool_array(char *s, size_t slen, bool a[], size_t alen);
119119

0 commit comments

Comments
 (0)