usnic: ensure to use ntohl() for network-order values
Этот коммит содержится в:
родитель
51240394a7
Коммит
dac2fe1589
@ -11,7 +11,7 @@
|
||||
* All rights reserved.
|
||||
* Copyright (c) 2006 Sandia National Laboratories. All rights
|
||||
* reserved.
|
||||
* Copyright (c) 2013-2015 Cisco Systems, Inc. All rights reserved.
|
||||
* Copyright (c) 2013-2016 Cisco Systems, Inc. All rights reserved.
|
||||
* $COPYRIGHT$
|
||||
*
|
||||
* Additional copyrights may follow
|
||||
@ -69,6 +69,7 @@ typedef struct opal_btl_usnic_modex_t {
|
||||
uint32_t ipv4_addr;
|
||||
/* Stored in host order */
|
||||
uint32_t ports[USNIC_NUM_CHANNELS];
|
||||
/* Stored in network order */
|
||||
uint32_t netmask;
|
||||
/* Stored in host order */
|
||||
uint32_t connectivity_udp_port;
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2013-2015 Cisco Systems, Inc. All rights reserved.
|
||||
* Copyright (c) 2013-2016 Cisco Systems, Inc. All rights reserved.
|
||||
* $COPYRIGHT$
|
||||
*
|
||||
* Additional copyrights may follow
|
||||
@ -115,24 +115,27 @@ opal_btl_usnic_dump_hex(void *vaddr, int len)
|
||||
* using inet_ntop()).
|
||||
*/
|
||||
void opal_btl_usnic_snprintf_ipv4_addr(char *out, size_t maxlen,
|
||||
uint32_t addr, uint32_t netmask)
|
||||
uint32_t addr_be, uint32_t netmask_be)
|
||||
{
|
||||
int prefixlen;
|
||||
uint32_t netmask = ntohl(netmask_be);
|
||||
uint32_t addr = ntohl(addr_be);
|
||||
uint8_t *p = (uint8_t*) &addr;
|
||||
|
||||
if (netmask != 0) {
|
||||
prefixlen = 33 - ffs(netmask);
|
||||
snprintf(out, maxlen, "%u.%u.%u.%u/%u",
|
||||
p[0],
|
||||
p[1],
|
||||
p[2],
|
||||
p[3],
|
||||
p[2],
|
||||
p[1],
|
||||
p[0],
|
||||
prefixlen);
|
||||
} else {
|
||||
snprintf(out, maxlen, "%u.%u.%u.%u",
|
||||
p[0],
|
||||
p[1],
|
||||
p[3],
|
||||
p[2],
|
||||
p[3]);
|
||||
p[1],
|
||||
p[0]);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2013-2014 Cisco Systems, Inc. All rights reserved.
|
||||
* Copyright (c) 2013-2016 Cisco Systems, Inc. All rights reserved.
|
||||
* $COPYRIGHT$
|
||||
*
|
||||
* Additional copyrights may follow
|
||||
@ -113,7 +113,7 @@ void opal_btl_usnic_util_abort(const char *msg, const char *file, int line);
|
||||
* expected to be in network byte order.
|
||||
*/
|
||||
void opal_btl_usnic_snprintf_ipv4_addr(char *out, size_t maxlen,
|
||||
uint32_t addr, uint32_t netmask);
|
||||
uint32_t addr_be, uint32_t netmask_be);
|
||||
|
||||
void opal_btl_usnic_snprintf_bool_array(char *s, size_t slen, bool a[], size_t alen);
|
||||
|
||||
|
Загрузка…
Ссылка в новой задаче
Block a user