Fix issue5 for endian safe

Make eSEL request data be endian-safe.
Redefine the struct of esel_request_t.
Use le16toh() of <endian.h>

Signed-off-by: Nan Li <bjlinan@cn.ibm.com>
diff --git a/oemhandler.C b/oemhandler.C
index 026e0d1..8d522c2 100644
--- a/oemhandler.C
+++ b/oemhandler.C
@@ -4,6 +4,7 @@
 #include <stdio.h>
 #include <string.h>
 #include <systemd/sd-bus.h>
+#include <endian.h>
 
 void register_netfn_oem_partial_esel() __attribute__((constructor));
 
@@ -26,25 +27,23 @@
                                      ipmi_request_t request, ipmi_response_t response,
                                      ipmi_data_len_t data_len, ipmi_context_t context)
 {
-	esel_request_t *reqptr = (esel_request_t*) request;
+	uint8_t *reqptr = (uint8_t *) request;
+	esel_request_t esel_req;
 	FILE *fp;
 	int r = 0;
-	// TODO: Issue 5: This is not endian-safe.
-	short *recid  =  (short*) &reqptr->selrecordls;
-	short *offset =  (short*) &reqptr->offsetls;
 	uint8_t rlen;
 	ipmi_ret_t rc = IPMI_CC_OK;
 	const char *pio;
 
-	unsigned short used_res_id = 0;
-	unsigned short req_res_id = 0;
+	esel_req.resid     = le16toh((((uint16_t) reqptr[1]) << 8) + reqptr[0]);
+	esel_req.selrecord = le16toh((((uint16_t) reqptr[3]) << 8) + reqptr[2]);
+	esel_req.offset    = le16toh((((uint16_t) reqptr[5]) << 8) + reqptr[4]);
+	esel_req.progress  = reqptr[6];
 
-	used_res_id = get_sel_reserve_id();
-
-	req_res_id = (((unsigned short)reqptr->residms) << 8) + reqptr->residls;
+	uint16_t used_res_id = get_sel_reserve_id();
 
 	// According to IPMI spec, Reservation ID must be checked.
-	if ( used_res_id != req_res_id ) {
+	if ( used_res_id != esel_req.resid ) {
 		// 0xc5 means Reservation Cancelled or Invalid Reservation ID.
 		printf("Used Reservation ID = %d\n", used_res_id);
 		rc = IPMI_CC_INVALID_RESERVATION_ID;
@@ -59,7 +58,7 @@
 
     // OpenPOWER Host Interface spec says if RecordID and Offset are
 	// 0 then then this is a new request
-	if (!*recid && !*offset)
+	if (!esel_req.selrecord && !esel_req.offset)
 		pio = "wb";
 	else
 		pio = "rb+";
@@ -67,11 +66,11 @@
 	rlen = (*data_len) - (uint8_t) (sizeof(esel_request_t));
 
 	printf("IPMI PARTIAL ESEL for %s  Offset = %d Length = %d\n",
-		g_esel_path, *offset, rlen);
+		g_esel_path, esel_req.offset, rlen);
 
 	if ((fp = fopen(g_esel_path, pio)) != NULL) {
-		fseek(fp, *offset, SEEK_SET);
-		fwrite(reqptr+1,rlen,1,fp);
+		fseek(fp, esel_req.offset, SEEK_SET);
+		fwrite(reqptr+(uint8_t) (sizeof(esel_request_t)), rlen, 1, fp);
 		fclose(fp);
 
 		*data_len = sizeof(g_record_id);
@@ -86,7 +85,7 @@
 	// coming down.  If that is the case advance the record id so we
 	// don't overlap logs.  This allows anyone to establish a log
 	// directory system.
-	if (reqptr->progress & 1 ) {
+	if (esel_req.progress & 1 ) {
 		g_record_id++;
 	}