int64_t InputFrame::unpackInt64() { int64_t nval; memcpy(&nval, data.c_str() + unpackptr, 8); unpackptr += 8; return ntohq(nval); }
int64_t InputFrame::unpackInt64() { int64_t nval; memcpy(&nval, body_buffer + unpackptr, 8); unpackptr += 8; return ntohq(nval); }
/* * Get the value of a QWORD TLV */ QWORD packet_get_tlv_value_qword(Packet *packet, TlvType type) { Tlv qwordTlv; if( ( packet_get_tlv( packet, type, &qwordTlv ) != ERROR_SUCCESS ) || ( qwordTlv.header.length < sizeof(QWORD) ) ) return 0; return ntohq( *(QWORD *)qwordTlv.buffer ); }
/* * Parse a recieved DME message. The space must be allready allocated in 'hdr'. */ int dme_header_parse(buff_t buff, dme_message_hdr_t * const msg) { dme_message_hdr_t * src = (dme_message_hdr_t *)buff.data; if (!msg || buff.data == NULL || buff.len < DME_MESSAGE_HEADER_LEN) { return ERR_DME_HDR; } msg->dme_magic = ntohl(src->dme_magic); msg->process_id = ntohq(src->process_id); msg->msg_type = ntohs(src->msg_type); msg->length = ntohs(src->length); msg->flags = ntohs(src->flags);; return 0; }
/* * Parse a recieved SUP message. The space must be allready allocated in 'msg'. */ int sup_msg_parse(buff_t buff, sup_message_t * const msg) { sup_message_t * src = (sup_message_t *)buff.data; if (!msg || buff.data == NULL || buff.len < SUPERVISOR_MESSAGE_LENGTH) { return ERR_SUP_HDR; } msg->sup_magic = ntohl(src->sup_magic); msg->process_id = ntohq(src->process_id); msg->msg_type = ntohs(src->msg_type); msg->sec_tdelta = ntohl(src->sec_tdelta); msg->nsec_tdelta = ntohl(src->nsec_tdelta); msg->flags = ntohl(src->flags); return 0; }
int report_luns(int argc, char **argv) { iscsi_iocommand_parameters_t io; int rc; size_t llen; uint32_t n; uint64_t *lp; (void) memset(&io, 0x0, sizeof(io)); if ((io.session_id = get_sessid(argc, argv, FALSE)) == 0) { return 1; } check_extra_args(argc, argv); io.req.cmdlen = 12; io.req.cmd[0] = 0xa0; n = htonl(sizeof(buf)); (void) memcpy(&io.req.cmd[6], &n, sizeof(n)); io.req.datalen = sizeof(buf); if ((rc = do_ioctl(&io, TRUE)) != 0) { return rc; } (void) memcpy(&n, buf, sizeof(n)); llen = ntohl(n); if (!llen) { printf("No LUNs!\n"); return 1; } if (llen + 8 > sizeof(buf)) printf("Partial "); printf("LUN List:\n"); lp = (uint64_t *)(void *) &buf[8]; for (llen = min(llen, sizeof(buf) - 8) / 8; llen; llen--) { printf(" 0x%" PRIx64 "\n", ntohq(*lp)); lp++; } return 0; }
/*! \brief Unpacks a 64 bit int from the buffer. \return The value unpacked. */ uint64_t Buffer::unpackInt64(){ uint64_t nval; memcpy(&nval, data + dataptr, 8); dataptr += 8; return ntohq(nval); }
STATIC void mod_pdu(pdu_t *pdu, iscsi_pdu_mod_t *mp) { int add = mp->flags & ISCSITEST_MOD_FLAG_ADD_VAL; int64_t val = *((int64_t *) mp->value); uint8_t *ptr; int len; switch (mp->offset) { case ISCSITEST_OFFSET_DATADIGEST: ptr = (uint8_t *) &pdu->data_digest; len = sizeof(pdu->data_digest); break; case ISCSITEST_OFFSET_HEADERDIGEST: ptr = (uint8_t *) &pdu->pdu.HeaderDigest; len = sizeof(pdu->pdu.HeaderDigest); break; case ISCSITEST_OFFSET_DATA: if ((len = pdu->io_vec[1].iov_len) == 0) return; ptr = pdu->io_vec[1].iov_base; break; case ISCSITEST_OFFSET_DRV_CMDSN: ptr = (uint8_t *) &pdu->connection->session->CmdSN; len = sizeof(pdu->connection->session->CmdSN); break; default: if (find_pdu_offset(pdu, mp->offset, &ptr, &len)) return; break; } len = min(len, mp->size); DEB(1, ("mod_pdu: mpoff=%d, size=%d, len=%d, val=%qx, *ptr=%qx\n", mp->offset, mp->size, len, val, *((uint64_t *) ptr))); if (!add) { if (mp->flags & ISCSITEST_MOD_FLAG_REORDER) val = htonq(val); memcpy(ptr, &val, len); } else if (len == mp->size) { switch (len) { case 1: *ptr += *mp->value; break; case 2: val += (int64_t) (ntohs(*((uint16_t *) ptr))); *((uint16_t *) ptr) = htons((uint16_t) val); break; case 3: val += (int64_t) (ntoh3(ptr)); hton3((uint32_t) val, ptr); break; case 4: val += (int64_t) (ntohl(*((uint32_t *) ptr))); *((uint32_t *) ptr) = htonl((uint32_t) val); break; case 8: val += ntohq(*((uint64_t *) ptr)); *((uint64_t *) ptr) = htonq(val); break; default: break; } } DEB(1, ("mod_pdu: *ptr=%qx\n", *((uint64_t *) ptr))); }
int evsql_result_next (struct evsql_result *res, ...) { va_list vargs; struct evsql_item_info *col; size_t col_idx, row_idx = res->row_offset; err_t err; // ensure that evsql_result_begin has been called assert(res->info); // check if we're past the end if (row_idx >= evsql_result_rows(res)) return 0; // varargs va_start(vargs, res); for (col = res->info->columns, col_idx = 0; col->type; col++, col_idx++) { const char *value = NULL; size_t length = 0; // check for NULLs, then try and get the field value if (evsql_result_null(res, row_idx, col_idx)) { if (!col->flags.null_ok) XERROR(err = EINVAL, "r%zu:c%zu: NULL", row_idx, col_idx); } else if (evsql_result_field(res, row_idx, col_idx, &value, &length)) { SERROR(err = EINVAL); } // read the arg switch (col->type) { case EVSQL_TYPE_BINARY: { struct evsql_item_binary *item_ptr = va_arg(vargs, struct evsql_item_binary *); if (value) { item_ptr->ptr = value; item_ptr->len = length; } } break; case EVSQL_TYPE_STRING: { const char **str_ptr = va_arg(vargs, const char **); if (value) { *str_ptr = value; } } break; case EVSQL_TYPE_UINT16: { uint16_t *uval_ptr = va_arg(vargs, uint16_t *); if (!value) break; if (length != sizeof(uint16_t)) XERROR(err = EINVAL, "r%zu:c%zu: wrong size for uint16_t: %zu", row_idx, col_idx, length); int16_t sval = ntohs(*((int16_t *) value)); if (sval < 0) XERROR(err = ERANGE, "r%zu:c%zu: out of range for uint16_t: %hd", row_idx, col_idx, (signed short) sval); *uval_ptr = sval; } break; case EVSQL_TYPE_UINT32: { uint32_t *uval_ptr = va_arg(vargs, uint32_t *); if (!value) break; if (length != sizeof(uint32_t)) XERROR(err = EINVAL, "r%zu:c%zu: wrong size for uint32_t: %zu", row_idx, col_idx, length); int32_t sval = ntohl(*((int32_t *) value)); if (sval < 0) XERROR(err = ERANGE, "r%zu:c%zu: out of range for uint32_t: %ld", row_idx, col_idx, (signed long) sval); *uval_ptr = sval; } break; case EVSQL_TYPE_UINT64: { uint64_t *uval_ptr = va_arg(vargs, uint64_t *); if (!value) break; if (length != sizeof(uint64_t)) XERROR(err = EINVAL, "r%zu:c%zu: wrong size for uint64_t: %zu", row_idx, col_idx, length); int64_t sval = ntohq(*((int64_t *) value)); if (sval < 0) XERROR(err = ERANGE, "r%zu:c%zu: out of range for uint64_t: %lld", row_idx, col_idx, (signed long long) sval); *uval_ptr = sval; } break; default: XERROR(err = EINVAL, "r%zu:c%zu: invalid type: %d", row_idx, col_idx, col->type); } } // advance row index res->row_offset++; // row handled succesfully return 1; error: return -err; }