Exemplo n.º 1
0
static void
parse_metadata(struct ofpbuf *b, char *arg)
{
    struct ofpact_metadata *om;
    char *mask = strchr(arg, '/');

    om = ofpact_put_WRITE_METADATA(b);

    if (mask) {
        *mask = '\0';
        om->mask = htonll(str_to_u64(mask + 1));
    } else {
        om->mask = htonll(UINT64_MAX);
    }

    om->metadata = htonll(str_to_u64(arg));
}
Exemplo n.º 2
0
	std::string getUniqueName()
	{
		size_t time = std::chrono::high_resolution_clock::now().time_since_epoch().count();

		time = htonll(time);

		return binToHexString(&time, sizeof(time) );
	}
Exemplo n.º 3
0
ucs_status_t uct_dc_mlx5_ep_atomic_fadd64(uct_ep_h tl_ep, uint64_t add,
                                          uint64_t remote_addr, uct_rkey_t rkey,
                                          uint64_t *result, uct_completion_t *comp)
{
    return uct_dc_mlx5_ep_atomic(ucs_derived_of(tl_ep, uct_dc_mlx5_ep_t),
                                 MLX5_OPCODE_ATOMIC_FA, result, 0, sizeof(uint64_t),
                                 remote_addr, rkey, 0, 0, htonll(add), comp);
}
Exemplo n.º 4
0
bool cRequestPacket::add_U64(uint64_t ull)
{
  if (!checkExtend(sizeof(uint64_t))) return false;
  *(uint64_t*)&buffer[bufUsed] = htonll(ull);
  bufUsed += sizeof(uint64_t);
  if (!lengthSet) *(uint32_t*)&buffer[userDataLenPos] = htonl(bufUsed - headerLength);
  return true;
}
Exemplo n.º 5
0
Arquivo: cidr.c Projeto: Neg9/namedrop
static inline void cidr_in6inc(void *a) {
#if BIGENDIAN == 0
	union {
		uint8_t *c;
		uint64_t *dw;
		void *p;
	} p_u;
	uint64_t dw;
#endif
	u128_t tmp;

#if BIGENDIAN == 0
	p_u.p=a;
	tmp.l=ntohll(*p_u.dw);
	p_u.dw++;
	tmp.u=ntohll(*p_u.dw);
#else
	memcpy(&tmp, a, sizeof(tmp));
#endif

#if BIGENDIAN == 0
	tmp.u++;
	if (tmp.u == 0ULL) {
		tmp.l++;
	}
#else
	tmp.l++;
	if (tmp.l == 0ULL) {
		tmp.u++;
	}
#endif


#if BIGENDIAN == 0
	dw=htonll(tmp.l);
	p_u.p=a;
	memcpy(p_u.p, &dw, sizeof(dw));
	p_u.dw++;
	dw=htonll(tmp.u);
	memcpy(p_u.p, &dw, sizeof(dw));
#else
	memcpy(a, &tmp, sizeof(tmp));
#endif

        return;
}
Exemplo n.º 6
0
 SERVER_EXPORT void TransportDataHToN ( net_transport_data_t* src_params, net_transport_data_t* dst_params )
 {
     dst_params->fNewState = htonl(src_params->fNewState);
     dst_params->fTimebaseMaster = htonl(src_params->fTimebaseMaster);
     dst_params->fState = htonl(src_params->fState);
     dst_params->fPosition.unique_1 = htonll(src_params->fPosition.unique_1);
     dst_params->fPosition.usecs = htonl(src_params->fPosition.usecs);
     dst_params->fPosition.frame_rate = htonl(src_params->fPosition.frame_rate);
     dst_params->fPosition.frame = htonl(src_params->fPosition.frame);
     dst_params->fPosition.valid = (jack_position_bits_t)htonl((uint32_t)src_params->fPosition.valid);
     dst_params->fPosition.bar = htonl(src_params->fPosition.bar);
     dst_params->fPosition.beat = htonl(src_params->fPosition.beat);
     dst_params->fPosition.tick = htonl(src_params->fPosition.tick);
     dst_params->fPosition.bar_start_tick = htonll((uint64_t)src_params->fPosition.bar_start_tick);
     dst_params->fPosition.beats_per_bar = htonl((uint32_t)src_params->fPosition.beats_per_bar);
     dst_params->fPosition.beat_type = htonl((uint32_t)src_params->fPosition.beat_type);
     dst_params->fPosition.ticks_per_beat = htonll((uint64_t)src_params->fPosition.ticks_per_beat);
     dst_params->fPosition.beats_per_minute = htonll((uint64_t)src_params->fPosition.beats_per_minute);
     dst_params->fPosition.frame_time = htonll((uint64_t)src_params->fPosition.frame_time);
     dst_params->fPosition.next_time = htonll((uint64_t)src_params->fPosition.next_time);
     dst_params->fPosition.bbt_offset = htonl(src_params->fPosition.bbt_offset);
     dst_params->fPosition.audio_frames_per_video_frame = htonl((uint32_t)src_params->fPosition.audio_frames_per_video_frame);
     dst_params->fPosition.video_offset = htonl(src_params->fPosition.video_offset);
     dst_params->fPosition.unique_2 = htonll(src_params->fPosition.unique_2);
 }
Exemplo n.º 7
0
uint32_t TBinaryProtocol::writeDouble(const double dub) {
  BOOST_STATIC_ASSERT(sizeof(double) == sizeof(uint64_t));
  BOOST_STATIC_ASSERT(std::numeric_limits<double>::is_iec559);

  uint64_t bits = bitwise_cast<uint64_t>(dub);
  bits = htonll(bits);
  trans_->write((uint8_t*)&bits, 8);
  return 8;
}
Exemplo n.º 8
0
uint32_t
sff_index_write(FILE *fp, sff_index_t *idx)
{
  int32_t i;
  uint32_t n = 0;
  uint64_t len = 0;

  if(NULL == idx) {
      return 0;
  }

  // convert values to big-endian
  sff_index_hton(idx);

  // index header
  if(1 != fwrite(&idx->index_magic_number, sizeof(uint32_t), 1, fp)
     || 1 != fwrite(&idx->index_version, sizeof(uint32_t), 1, fp)
     || 1 != fwrite(&idx->num_rows, sizeof(int32_t), 1, fp)
     || 1 != fwrite(&idx->num_cols, sizeof(int32_t), 1, fp)
     || 1 != fwrite(&idx->type, sizeof(int32_t), 1, fp)) {
      ion_error(__func__, "fwrite", Exit, WriteFileError);
  }
  n += sizeof(uint32_t)*2 + sizeof(int32_t)*3;

  // convert values from big-endian
  sff_index_ntoh(idx);

  // offsets
  if(SFF_INDEX_ROW_ONLY == idx->type) {
      len = 1 + idx->num_rows;
  }
  else if(SFF_INDEX_ALL == idx->type) {
      len = 1 + (idx->num_rows * idx->num_cols);
  }
  else {
      ion_error(__func__, "could not understand index type", Exit, OutOfRange);
  }

  // convert values to big-endian
  for(i=0;i<len;i++) {
      idx->offset[i] = htonll(idx->offset[i]);
  }
  // write
  if(len != fwrite(idx->offset, sizeof(uint64_t), len, fp)) {
      ion_error(__func__, "fwrite", Exit, WriteFileError);
  }
  n += sizeof(uint64_t) * len;
  // convert values from big-endian
  for(i=0;i<len;i++) {
      idx->offset[i] = ntohll(idx->offset[i]);
  }

  // padding
  n += ion_write_padding(fp, n);

  return n;
}
Exemplo n.º 9
0
/** =========================================================================
 */
void ssa_db_dataset_init(struct db_dataset * p_dataset,
			 uint8_t version, uint8_t size,
			 uint8_t access, uint8_t db_id,
			 uint8_t table_id, uint8_t field_id,
			 uint64_t epoch, uint64_t set_size,
			 uint64_t set_offset, uint64_t set_count)
{
	p_dataset->version	= version;
	p_dataset->size		= size;
	p_dataset->access	= access;
	p_dataset->id.db	= db_id;
	p_dataset->id.table	= table_id;
	p_dataset->id.field	= field_id;
	p_dataset->epoch	= htonll(epoch);
	p_dataset->set_size	= htonll(set_size);
	p_dataset->set_offset	= htonll(set_offset);
	p_dataset->set_count	= htonll(set_count);
}
Exemplo n.º 10
0
 T netEnc64(T & in)
 {
   uint64_t a = 0;
   T b;
   memcpy((void*)&a, (void*)&in, sizeof(uint64_t));
   a = htonll(a);
   memcpy((void*)&b, (void*)&a, sizeof(uint64_t));
   return b;
 }
Exemplo n.º 11
0
extern int 
proto_session_body_marshall_ll(Proto_Session *s, long long v){
  if (s && ((s->slen + sizeof(long long)) < PROTO_SESSION_BUF_SIZE)) {
    *((int *)(s->sbuf + s->slen)) = htonll(v);
    s->slen+=sizeof(long long);
    return 1;
  }
  return -1;
}
Exemplo n.º 12
0
static void _set_field64(void *buf, int base_offs, const ib_field_t * f,
			 uint64_t val)
{
	uint64_t nval;

	nval = htonll(val);
	memcpy((char *)buf + base_offs + f->bitoffs / 8, &nval,
	       sizeof(uint64_t));
}
Exemplo n.º 13
0
// Copies data from the the PI into RDRAM.
static int pi_dma_write(struct pi_controller *pi) {
  uint32_t dest = pi->regs[PI_DRAM_ADDR_REG] & 0x7FFFFF;
  uint32_t source = pi->regs[PI_CART_ADDR_REG] & 0xFFFFFFF;
  uint32_t length = (pi->regs[PI_WR_LEN_REG] & 0xFFFFFF) + 1;

  if (length & 7)
    length = (length + 7) & ~7;

  if (pi->bus->dd->ipl_rom && (source & 0x06000000) == 0x06000000) {
    source &= 0x003FFFFF;

    if (source + length > 0x003FFFFF)
      length = 0x003FFFFF - source;

    memcpy(pi->bus->ri->ram + dest, pi->bus->dd->ipl_rom + source, length);
  }

  else if ((source & 0x05000000) == 0x05000000)
    dd_dma_write(pi->bus->dd, source, dest, length);

  // SRAM and FlashRAM
  else if (source >= 0x08000000 && source < 0x08010000) {
    uint32_t addr = source & 0x00FFFFF;

    if (pi->sram->ptr != NULL && addr + length <= 0x8000)
      memcpy(pi->bus->ri->ram + dest, pi->sram->ptr + addr, length);

    else if (pi->flashram.data != NULL) {
      // SRAM
      if (pi->flashram.mode == FLASHRAM_STATUS) {
        uint64_t status = htonll(pi->flashram.status);
        memcpy(pi->bus->ri->ram + dest, &status, 8);
      }

      // FlashRAM
      else if (pi->flashram.mode == FLASHRAM_READ)
        memcpy(pi->bus->ri->ram + dest, pi->flashram.data + addr * 2, length);
    }
  }

  else if (source >= 0x18000000 && source < 0x18400000) {
    // TODO: 64DD modem
  }

  else if (pi->rom) {
    if (source + length > pi->rom_size) {
      length = pi->rom_size - source;
      //assert(0);
    }

    // TODO: Very hacky.
    if (source < pi->rom_size)
      memcpy(pi->bus->ri->ram + dest, pi->rom + source, length);
  }

  return 0;
}
Exemplo n.º 14
0
	bool BufferHelper::WriteFixUInt64(Buffer& buffer, uint64_t i,
			bool toNetwork)
	{
		if (toNetwork)
		{
			i = htonll(i);
		}
		return sizeof(uint64_t) == buffer.Write(&i, sizeof(uint64_t));
	}
Exemplo n.º 15
0
Packet& Packet::operator<<(uint64_t value)
{
  uint64_t *tmp = reinterpret_cast<uint64_t*>(&static_cast<char*>(_data->_vec.iov_base)[_windex]);
  *tmp = htonll(value);
  _windex += sizeof(value);
  if (_size < _windex)
 	_size = _windex;
  return *this;
}
Exemplo n.º 16
0
ucs_status_t uct_rc_mlx5_ep_atomic_swap64(uct_ep_h tl_ep, uint64_t swap,
                                          uint64_t remote_addr, uct_rkey_t rkey,
                                          uint64_t *result, uct_completion_t *comp)
{
    return uct_rc_mlx5_ep_atomic(ucs_derived_of(tl_ep, uct_rc_mlx5_ep_t),
                                 MLX5_OPCODE_ATOMIC_MASKED_CS,result,  sizeof(uint64_t),
                                 uct_rc_ep_atomic_handler_64_be1, remote_addr,
                                 rkey, 0, 0, htonll(swap), comp);
}
Exemplo n.º 17
0
char* grist_point_ser(grist_point* p, size_t* sz) {
    size_t newsz = sizeof(grist_coord);
    char* serialized = malloc(newsz);
    assert(serialized);
    uint64_t x;
    uint64_t y;
    uint64_t z;
    x = htonll(dtoll(p->coord->x));
    y = htonll(dtoll(p->coord->y));
    z = htonll(dtoll(p->coord->z));
    memcpy(serialized, &x, sizeof(uint64_t));
    size_t offset = sizeof(uint64_t);
    memcpy((serialized+offset), &y, sizeof(uint64_t));
    offset += sizeof(uint64_t);
    memcpy((serialized+offset), &z, sizeof(uint64_t));
    *sz = newsz;
    return serialized;
}
Exemplo n.º 18
0
bool cResponsePacket::add_double(double d)
{
  if (!checkExtend(sizeof(double))) return false;
  uint64_t ull;
  memcpy(&ull,&d,sizeof(double));
  *(uint64_t*)&buffer[bufUsed] = htonll(ull);
  bufUsed += sizeof(uint64_t);
  return true;
}
Exemplo n.º 19
0
static void
check_bitwise_is_all_zeros(void)
{
    int n_loops;

    n_loops = 0;
    for (n_loops = 0; n_loops < 100; n_loops++) {
        ovs_be64 x = htonll(0);
        int i;

        for (i = 0; i < 64; i++) {
            ovs_be64 bit;
            int ofs, n;

            /* Change a random 0-bit into a 1-bit. */
            do {
                bit = htonll(UINT64_C(1) << (random_uint32() % 64));
            } while (x & bit);
            x |= bit;

            for (ofs = 0; ofs < 64; ofs++) {
                for (n = 0; n <= 64 - ofs; n++) {
                    bool expect;
                    bool answer;

                    expect = (n == 64
                              ? x == 0
                              : !(x & htonll(((UINT64_C(1) << n) - 1)
                                             << ofs)));
                    answer = bitwise_is_all_zeros(&x, sizeof x, ofs, n);
                    if (expect != answer) {
                        fprintf(stderr,
                                "bitwise_is_all_zeros(0x%016"PRIx64",8,%d,%d "
                                "returned %s instead of %s\n",
                                ntohll(x), ofs, n,
                                answer ? "true" : "false",
                                expect ? "true" : "false");
                        abort();
                    }
                }
            }
        }
    }
}
Exemplo n.º 20
0
void buildTossimEvent(uint16_t moteID, uint16_t type, long long ftime, void *data,
                      unsigned char **msgp, int *lenp) {
  unsigned char *msg;
  int payload_size, total_size;
  
  // Determine payload size
  
  switch (type) {
  case AM_DEBUGMSGEVENT: 
    payload_size = sizeof(DebugMsgEvent);
    break;
  case AM_RADIOMSGSENTEVENT:
    payload_size = sizeof(RadioMsgSentEvent);
    break;
  case AM_UARTMSGSENTEVENT:
    payload_size = sizeof(RadioMsgSentEvent);
    break;
  case AM_ADCDATAREADYEVENT:
    payload_size = sizeof(ADCDataReadyEvent);
    break;
  case AM_TOSSIMINITEVENT:
    payload_size = sizeof(TossimInitEvent);
    break;
  case AM_VARIABLERESOLVERESPONSE:
    payload_size = sizeof(VariableResolveResponse);
    break;
  case AM_VARIABLEREQUESTRESPONSE:
    payload_size = sizeof(VariableRequestResponse);
    break;
  case AM_INTERRUPTEVENT:
    payload_size = sizeof(InterruptEvent);
    dbg(DBG_TEMP, "SIM: Sending InterruptEvent, payload is %i\n", (int)payload_size);
    break;
  case AM_LEDEVENT:
    payload_size = sizeof(LedEvent);
    break;
  default:
    EC_DEBUG(fprintf(stderr, "buildTossimEvent for invalid type: %d", type));
    return;
  }

  total_size = GUI_MSG_HEADER_LENGTH + payload_size;
  msg = (unsigned char *)malloc(total_size);

  *(unsigned short *)(&msg[0]) = htons(type);
  *(unsigned short *)(&msg[2]) = htons(moteID);
  *(long long *)(&msg[4]) = htonll(ftime);
  *(unsigned short *)(&msg[12]) = htons(payload_size);
  memcpy(((unsigned char *)msg)+GUI_MSG_HEADER_LENGTH, data, payload_size);

  EC_DEBUG(fprintf(stderr, "buildTossimEvent: msgType %d (0x%02x) moteID %d (0x%02x) payload size %d total size %d\n", type, type, moteID, moteID, payload_size, total_size));


  *msgp = msg;
  *lenp = total_size;
}
Exemplo n.º 21
0
/* Returns NULL if successful, otherwise a malloc()'d string describing the
 * error.  The caller is responsible for freeing the returned string. */
static char * OVS_WARN_UNUSED_RESULT
learn_parse_load_immediate(const char *s, struct ofpact_learn_spec *spec)
{
    const char *full_s = s;
    const char *arrow = strstr(s, "->");
    struct mf_subfield dst;
    union mf_subvalue imm;
    char *error;

    memset(&imm, 0, sizeof imm);
    if (s[0] == '0' && (s[1] == 'x' || s[1] == 'X') && arrow) {
        const char *in = arrow - 1;
        uint8_t *out = imm.u8 + sizeof imm.u8 - 1;
        int n = arrow - (s + 2);
        int i;

        for (i = 0; i < n; i++) {
            int hexit = hexit_value(in[-i]);
            if (hexit < 0) {
                return xasprintf("%s: bad hex digit in value", full_s);
            }
            out[-(i / 2)] |= i % 2 ? hexit << 4 : hexit;
        }
        s = arrow;
    } else {
        ovs_be64 *last_be64 = &imm.be64[ARRAY_SIZE(imm.be64) - 1];
        *last_be64 = htonll(strtoull(s, (char **) &s, 0));
    }

    if (strncmp(s, "->", 2)) {
        return xasprintf("%s: missing `->' following value", full_s);
    }
    s += 2;

    error = mf_parse_subfield(&dst, s);
    if (error) {
        return error;
    }
    if (!mf_nxm_header(dst.field->id)) {
        return xasprintf("%s: experimenter OXM field '%s' not supported",
                         full_s, s);
    }

    if (!bitwise_is_all_zeros(&imm, sizeof imm, dst.n_bits,
                              (8 * sizeof imm) - dst.n_bits)) {
        return xasprintf("%s: value does not fit into %u bits",
                         full_s, dst.n_bits);
    }

    spec->n_bits = dst.n_bits;
    spec->src_type = NX_LEARN_SRC_IMMEDIATE;
    spec->src_imm = imm;
    spec->dst_type = NX_LEARN_DST_LOAD;
    spec->dst = dst;
    return NULL;
}
Exemplo n.º 22
0
/**
 * Pack a unsigned 64 bits integer into this byte array. If the byte array
 * capacity isn't enough, the buffer is increased with the exact size needed.
 * Consider resizing the byte array if performance becomes an issue.
 *
 * @see byte_array_resize()
 */
void _byte_array_pack64(struct byte_array *ba, uint64_t v)
{
	ensure_size(ba, sizeof(v));
	union {
		uint64_t i;
		char c[8];
	} nv = { htonll(v) };
	memcpy(ba->ptr + ba->len, nv.c, sizeof(v));
	ba->len += sizeof(v);
}
Exemplo n.º 23
0
static void ssa_db_dataset_load(FILE *fd, struct db_dataset *p_dataset)
{
	int res = 0;

	res = fscanf(fd, DATASET_DEF_FORMAT,
		     &p_dataset->version, &p_dataset->size,
		     &p_dataset->access, &p_dataset->id.db,
		     &p_dataset->id.table, &p_dataset->id.field,
		     &p_dataset->epoch, &p_dataset->set_size,
		     &p_dataset->set_offset, &p_dataset->set_count);
	if (res != 10)
		ssa_log_warn(SSA_LOG_DEFAULT,
			    "%d fields out of 10 were loaded\n", res);

	p_dataset->epoch = htonll(p_dataset->epoch);
	p_dataset->set_size = htonll(p_dataset->set_size);
	p_dataset->set_offset = htonll(p_dataset->set_offset);
	p_dataset->set_count = htonll(p_dataset->set_count);
}
Exemplo n.º 24
0
/* ARGSUSED */
static int hton_position_update(packet *pu, size_t s)
{
    if (s < sizeof(position_update))
        return 0;
    pu->pos.sequence = htonll(pu->pos.sequence);
    pu->pos.object_id = htonll(pu->pos.object_id);
    pu->pos.frame_number = htons(pu->pos.frame_number);
    pu->pos.x_pos = htonll(pu->pos.x_pos);
    pu->pos.y_pos = htonll(pu->pos.y_pos);
    pu->pos.z_pos = htonll(pu->pos.z_pos);
    pu->pos.x_orient = htonl(pu->pos.x_orient);
    pu->pos.y_orient = htonl(pu->pos.y_orient);
    pu->pos.z_orient = htonl(pu->pos.z_orient);
    pu->pos.w_orient = htonl(pu->pos.z_orient);
    pu->pos.x_look = htonl(pu->pos.x_look);
    pu->pos.y_look = htonl(pu->pos.y_look);
    pu->pos.z_look = htonl(pu->pos.z_look);
    return 1;
}
Exemplo n.º 25
0
Arquivo: utils.c Projeto: dtaht/tc-adv
int get_be64(__be64 *val, const char *arg, int base)
{
	__u64 v;
	int ret = get_u64(&v, arg, base);

	if (!ret)
		*val = htonll(v);

	return ret;
}
Exemplo n.º 26
0
/*---------------------------------------------------------------------------*/
size_t xio_write_tlv(uint32_t type, uint64_t len, uint8_t *buffer)
{
	struct xio_tlv *tlv = (struct xio_tlv *)buffer;

	tlv->magic	= htonl(XIO_MAGIC);
	tlv->type	= htonl(type);
	tlv->len	= htonll(len);

	return sizeof(struct xio_tlv) + len;
}
Exemplo n.º 27
0
static void
parse_set_tunnel(struct ofpbuf *b, const char *arg)
{
    uint64_t tun_id = str_to_u64(arg);
    if (tun_id > UINT32_MAX) {
        ofputil_put_NXAST_SET_TUNNEL64(b)->tun_id = htonll(tun_id);
    } else {
        ofputil_put_NXAST_SET_TUNNEL(b)->tun_id = htonl(tun_id);
    }
}
Exemplo n.º 28
0
/* Copies the 'n_bits' low-order bits of 'value' into the 'n_bits' bits
 * starting at bit 'dst_ofs' in 'dst', which is 'dst_len' bytes long.
 *
 * If you consider all of 'dst' to be a single unsigned integer in network byte
 * order, then bit N is the bit with value 2**N.  That is, bit 0 is the bit
 * with value 1 in dst[dst_len - 1], bit 1 is the bit with value 2, bit 2 is
 * the bit with value 4, ..., bit 8 is the bit with value 1 in dst[dst_len -
 * 2], and so on.
 *
 * Required invariants:
 *   dst_ofs + n_bits <= dst_len * 8
 *   n_bits <= 64
 */
void
bitwise_put(uint64_t value,
            void *dst, unsigned int dst_len, unsigned int dst_ofs,
            unsigned int n_bits)
{
    ovs_be64 n_value = htonll(value);
    bitwise_copy(&n_value, sizeof n_value, 0,
                 dst, dst_len, dst_ofs,
                 n_bits);
}
Exemplo n.º 29
0
message& message::operator<<(double const& double_precision)
{
	assert(sizeof(double) == 8);

	uint64_t const host_order = *reinterpret_cast<uint64_t const*>(&double_precision);
	uint64_t network_order = htonll(host_order);
	add(&network_order, sizeof(uint64_t));

	return *this;
}
Exemplo n.º 30
0
void TestInet::testHTON()
{
	uint16_t u16 = 1;
	uint32_t u32 = 2;
	uint64_t u64 = 3;

	CPPUNIT_ASSERT(u16 == ntohs(htons(u16)));
	CPPUNIT_ASSERT(u32 == ntohl(htonl(u32)));
	CPPUNIT_ASSERT(u64 == ntohll(htonll(u64)));
}