lanplus: Make byteswapping generic

Get rid of lanplus-specific yet very generic in nature
lanplus_swap() function that unconditionally swaps bytes
in an arbitrary byte array. Move it to helper module and
add two conditionally working interfaces to it:

 - array_ntoh() for network (BE) to host conversion, and
 - array_letoh() for ipmi (LE) to host conversion.

The added functions will only perform byte swapping if
the target architecture differs in endianness from the
data source. array_ntoh() will only do swap on LE machines,
while array_letoh() will only do it on BE ones.

These functions are introduced for future use in other
places of ipmitool.

Partially resolves ipmitool/ipmitool#26

Signed-off-by: Alexander Amelkin <alexander@amelkin.msk.ru>
This commit is contained in:
Alexander Amelkin
2018-08-01 11:33:44 +03:00
parent 5491b12596
commit 7747d86cc4
3 changed files with 63 additions and 77 deletions

View File

@@ -165,6 +165,9 @@ static inline void htoipmi32(uint32_t h, uint8_t *ipmi)
ipmi[3] = (h >> 24) & 0xFF; /* MSB */
}
uint8_t *array_ntoh(uint8_t *buffer, size_t length);
uint8_t *array_letoh(uint8_t *buffer, size_t length);
#define ipmi_open_file_read(file) ipmi_open_file(file, 0)
#define ipmi_open_file_write(file) ipmi_open_file(file, 1)