/* Read IPFIX message header from file. Return true on success. Set *err to * 0 on EOF, any other value for "real" errors (EOF is ok, since return * value is still FALSE) */ static gboolean ipfix_read_message_header(ipfix_message_header_t *pfx_hdr, FILE_T fh, int *err, gchar **err_info) { wtap_file_read_expected_bytes(pfx_hdr, IPFIX_MSG_HDR_SIZE, fh, err, err_info); /* macro which does a return if read fails */ /* fix endianess, because IPFIX files are always big-endian */ pfx_hdr->version = g_ntohs(pfx_hdr->version); pfx_hdr->message_length = g_ntohs(pfx_hdr->message_length); pfx_hdr->export_time_secs = g_ntohl(pfx_hdr->export_time_secs); pfx_hdr->sequence_number = g_ntohl(pfx_hdr->sequence_number); pfx_hdr->observation_id = g_ntohl(pfx_hdr->observation_id); /* is the version number one we expect? */ if (pfx_hdr->version != IPFIX_VERSION) { /* Not an ipfix file. */ *err = WTAP_ERR_BAD_FILE; *err_info = g_strdup_printf("ipfix: wrong version %d", pfx_hdr->version); return FALSE; } if (pfx_hdr->message_length < 16) { *err = WTAP_ERR_BAD_FILE; *err_info = g_strdup_printf("ipfix: message length %u is too short", pfx_hdr->message_length); return FALSE; } /* go back to before header */ if (file_seek(fh, 0 - IPFIX_MSG_HDR_SIZE, SEEK_CUR, err) == -1) { ipfix_debug0("ipfix_read: couldn't go back in file before header"); return FALSE; } return TRUE; }
gint handler_src_dst_ip_compare_nodes(tree_node_t *node_a, tree_node_t *node_b) { guint src_mask_a = pow(2, 32 - node_a->src_dst_ip.src_network_bits) - 1; guint src_mask_b = pow(2, 32 - node_b->src_dst_ip.src_network_bits) - 1; guint src_addr_a = g_ntohl(node_a->src_dst_ip.src_addr.s_addr) & ~src_mask_a; guint src_addr_b = g_ntohl(node_b->src_dst_ip.src_addr.s_addr) & ~src_mask_b; // check the src addresses first if (src_addr_a < src_addr_b) { return -1; } else if (src_addr_a > src_addr_b) { return 1; } guint dst_mask_a = pow(2, 32 - node_a->src_dst_ip.dst_network_bits) - 1; guint dst_mask_b = pow(2, 32 - node_b->src_dst_ip.dst_network_bits) - 1; guint dst_addr_a = g_ntohl(node_a->src_dst_ip.dst_addr.s_addr) & ~dst_mask_a; guint dst_addr_b = g_ntohl(node_b->src_dst_ip.dst_addr.s_addr) & ~dst_mask_b; // if we hit here, we know src_addresses are equal, so compare dst_address if (dst_addr_a < dst_addr_b) { return -1; } else if (dst_addr_a > dst_addr_b) { return 1; } // if we hit here, we know both the src and dst addresses are equal return 0; }
/* Read & swap values appropriately for ovl header */ uint8_t * ovl_get_header ( struct ovl_t * ovl, struct ovl_header_t * dest ) { int offset, i; uint32_t * ptr; /* Get offset to header */ offset = g_ntohl( *(uint32_t*)(ovl->data + ovl->filesize - 4) ); /* Invalid offset? */ if( offset > ovl->filesize || (offset % 4) ) { /* Yes... */ ovl_set_error( "not an overlay file" ); return NULL; } /* Set the word pointer */ ptr = (uint32_t*)(ovl->data + ovl->filesize - offset); /* Read it in... */ for( i = 0; i < sizeof(struct ovl_header_t) / 4; i++ ) { uint32_t w; /* Get next word & swap */ w = g_ntohl( ptr[i] ); /* Copy it over */ ((uint32_t*)dest)[i] = w; } return (uint8_t*)ptr; }
void compressed_rindex::get_data(glong idx, guint32 &entry_offset, guint32 &entry_size) { gchar *p1 = filelist[idx]+strlen(filelist[idx])+sizeof(gchar); entry_offset = g_ntohl(get_uint32(p1)); p1 += sizeof(guint32); entry_size = g_ntohl(get_uint32(p1)); }
static int imap4_header_load (CamelFolderSummary *summary) { CamelIMAP4Summary *imap4_summary = (CamelIMAP4Summary *) summary; if (CAMEL_FOLDER_SUMMARY_CLASS (parent_class)->summary_header_load (summary) == -1) return -1; imap4_summary->version = g_ntohl(get_unaligned_u32(summary->filepos)); summary->filepos += 4; if (imap4_summary->version > CAMEL_IMAP4_SUMMARY_VERSION) { g_warning ("Unknown IMAP4 summary version\n"); errno = EINVAL; return -1; } if (imap4_summary->version == 2) { /* check that we have Mailing-List info */ int have_mlist; have_mlist = g_ntohl(get_unaligned_u32(summary->filepos)); summary->filepos += 4; if (have_mlist) summary->flags |= CAMEL_IMAP4_SUMMARY_HAVE_MLIST; else summary->flags ^= CAMEL_IMAP4_SUMMARY_HAVE_MLIST; } imap4_summary->uidvalidity = g_ntohl(get_unaligned_u32(summary->filepos)); summary->filepos += 4; return 0; }
void print_index(std::string& idx_file_name) { glib::CharStr contents; gsize cont_len; if(!g_file_get_contents(idx_file_name.c_str(), get_addr(contents), &cont_len, NULL)) { std::cerr << "Unable to open file " << idx_file_name << std::endl; return; } if(!quiet_mode) { if(syn_file) std::cout << " INDEX KEY" << std::endl; else std::cout << " OFFSET SIZE KEY" << std::endl; } gchar *p1 = get_impl(contents); gchar *end = p1+cont_len; int rec_no = 0; const gchar* key; if(syn_file) { guint32 index; while(p1<end) { key = p1; p1 += strlen(p1) + 1; index = g_ntohl(*reinterpret_cast<guint32*>(p1)); p1 += sizeof(guint32); ++rec_no; if(key_only) std::cout << key << std::endl; else std::cout << std::setw(10) << index << " " << key << std::endl; } } else { guint32 offset, size; while(p1<end) { key = p1; p1 += strlen(p1) + 1; offset = g_ntohl(*reinterpret_cast<guint32*>(p1)); p1 += sizeof(guint32); size = g_ntohl(*reinterpret_cast<guint32*>(p1)); p1 += sizeof(guint32); ++rec_no; if(key_only) std::cout << key << std::endl; else std::cout << std::setw(10) << offset << " " << std::setw(10) << size << " "<< key << std::endl; } } if(!quiet_mode) std::cout << "number of entries: " << rec_no << std::endl; }
void offset_rindex::page_t::fill(gchar *data, gint nent, glong page_idx_) { page_idx=page_idx_; gchar *p=data; glong len; for (gint i=0; i<nent; ++i) { entries[i].keystr=p; len=strlen(p); p+=len+1; entries[i].off=g_ntohl(get_uint32(p)); p+=sizeof(guint32); entries[i].size=g_ntohl(get_uint32(p)); p+=sizeof(guint32); } }
guint32 rtp_packet_get_ssrc(Rtp_Packet packet) { g_return_val_if_fail(packet != NULL, 0); return g_ntohl(((Rtp_Header) packet -> data) -> ssrc); }
guint32 rtp_packet_get_timestamp(Rtp_Packet packet) { g_return_val_if_fail(packet != NULL, 0); return g_ntohl(((Rtp_Header) packet -> data) -> timestamp); }
MESSAGE message_unmarshall(const guint8 *buf, gsize len, GError ** error) { if (!buf || len < 4) { GSETERROR(error, "Invalid parameter"); return NULL; } guint32 l0 = *((guint32*)buf); l0 = g_ntohl(l0); if (l0 > len-4) { GSETERROR(error, "l4v: uncomplete"); return NULL; } MESSAGE m = NULL; asn_codec_ctx_t codec_ctx; codec_ctx.max_stack_size = ASN1C_MAX_STACK; size_t s = l0; asn_dec_rval_t rc = ber_decode(&codec_ctx, &asn_DEF_Message, (void**)&m, buf+4, s); if (rc.code == RC_OK) return m; if (rc.code == RC_WMORE) GSETERROR(error, "%s (%"G_GSIZE_FORMAT" bytes consumed)", "uncomplete content", rc.consumed); else GSETERROR(error, "%s (%"G_GSIZE_FORMAT" bytes consumed)", "invalid content", rc.consumed); metautils_message_destroy (m); return NULL; }
static void gfire_p2p_natcheck_udpread(gpointer p_data, gint p_fd, PurpleInputCondition p_condition) { gfire_p2p_natcheck *nat = (gfire_p2p_natcheck*)p_data; if(!nat) return; static unsigned char buffer[10]; struct sockaddr_in addr; guint addr_len = sizeof(addr); int len = recvfrom(p_fd, buffer, 10, 0, (struct sockaddr*)&addr, &addr_len); if(len != 10) { purple_debug_error("gfire", "P2P: NAT Check: Received too less data\n"); return; } int server; for(server = 0; server < 3; server++) if(addr.sin_addr.s_addr == nat->nat_servers[server].sin_addr.s_addr) break; if(server == 3) { guint32 ip = g_ntohl(addr.sin_addr.s_addr); purple_debug_error("gfire", "P2P: NAT Check: Received response from unknown server (%u.%u.%u.%u:%u)\n", (ip & 0xff000000) >> 24, (ip & 0xff0000) >> 16, (ip & 0xff00) >> 8, ip & 0xff, addr.sin_port); return; }
static int dissect_bp_address(tvbuff_t *tvb, int offset, proto_tree *tree, int hfindex) { guint32 type; guint32 ipaddr; type = tvb_get_ntohl(tvb, offset); offset = dissect_rpc_uint32(tvb, tree, hf_bootparams_addresstype, offset); switch(type){ case 1: ipaddr = ((tvb_get_guint8(tvb, offset+3 )&0xff)<<24) |((tvb_get_guint8(tvb, offset+7 )&0xff)<<16) |((tvb_get_guint8(tvb, offset+11)&0xff)<<8 ) |((tvb_get_guint8(tvb, offset+15)&0xff) ); proto_tree_add_ipv4(tree, hfindex, tvb, offset, 16, g_ntohl(ipaddr)); offset += 16; break; default: break; } return offset; }
char *bt_uuid2string(uuid_t *uuid) { gchar *str; uuid_t uuid128; unsigned int data0; unsigned short data1; unsigned short data2; unsigned short data3; unsigned int data4; unsigned short data5; if (!uuid) return NULL; switch (uuid->type) { case SDP_UUID16: sdp_uuid16_to_uuid128(&uuid128, uuid); break; case SDP_UUID32: sdp_uuid32_to_uuid128(&uuid128, uuid); break; case SDP_UUID128: memcpy(&uuid128, uuid, sizeof(uuid_t)); break; default: /* Type of UUID unknown */ return NULL; } memcpy(&data0, &uuid128.value.uuid128.data[0], 4); memcpy(&data1, &uuid128.value.uuid128.data[4], 2); memcpy(&data2, &uuid128.value.uuid128.data[6], 2); memcpy(&data3, &uuid128.value.uuid128.data[8], 2); memcpy(&data4, &uuid128.value.uuid128.data[10], 4); memcpy(&data5, &uuid128.value.uuid128.data[14], 2); str = g_try_malloc0(MAX_LEN_UUID_STR); if (!str) return NULL; sprintf(str, "%.8x-%.4x-%.4x-%.4x-%.8x%.4x", g_ntohl(data0), g_ntohs(data1), g_ntohs(data2), g_ntohs(data3), g_ntohl(data4), g_ntohs(data5)); return str; }
EXPORT_C #endif guint32 gst_rtp_buffer_get_timestamp (GstBuffer * buffer) { return g_ntohl (GST_RTP_HEADER_TIMESTAMP (GST_BUFFER_DATA (buffer))); }
EXPORT_C #endif guint32 gst_rtp_buffer_get_ssrc (GstBuffer * buffer) { return g_ntohl (GST_RTP_HEADER_SSRC (GST_BUFFER_DATA (buffer))); }
/* read four bytes as "guint32" from buf, * return the number of bytes read if succeeds, otherwise return -1 */ gint read_packet_dw(guint8 *buf, guint8 **cursor, gint buflen, guint32 *dw) { if (*cursor <= buf + buflen - sizeof(*dw)) { *dw = g_ntohl(**(guint32 **) cursor); *cursor += sizeof(*dw); return sizeof(*dw); } else { return -1; } }
/** * gst_rtp_buffer_list_get_ssrc: * @list: the buffer list * * Get the SSRC of the first RTP packet in @list. * All RTP packets within @list have the same SSRC. * * Returns: the SSRC of @list in host order. * * Since: 0.10.24 */ guint32 gst_rtp_buffer_list_get_ssrc (GstBufferList * list) { GstBuffer *buffer; buffer = gst_buffer_list_get (list, 0, 0); g_return_val_if_fail (buffer != NULL, 0); return g_ntohl (GST_RTP_HEADER_SSRC (GST_BUFFER_DATA (buffer))); }
/** * gst_rtp_buffer_list_get_timestamp: * @list: the buffer list * * Get the timestamp of the first RTP packet in @list. * All packets within @list have the same timestamp. * * Returns: The timestamp in host order. * * Since: 0.10.24 */ guint32 gst_rtp_buffer_list_get_timestamp (GstBufferList * list) { GstBuffer *buffer; buffer = gst_buffer_list_get (list, 0, 0); g_return_val_if_fail (buffer != NULL, 0); return g_ntohl (GST_RTP_HEADER_TIMESTAMP (GST_BUFFER_DATA (buffer))); }
EXPORT_C #endif guint32 gst_rtp_buffer_get_timestamp (GstBuffer * buffer) { g_return_val_if_fail (GST_IS_BUFFER (buffer), 0); g_return_val_if_fail (GST_BUFFER_DATA (buffer) != NULL, 0); return g_ntohl (GST_RTP_HEADER_TIMESTAMP (buffer)); }
static void test_send_message(void) { GIOChannel* in, * out; gint fds[2]; GError* err = NULL; wsh_message_size_t msg_size; wsh_cmd_res_t res = { .std_output_len = 2, .std_error_len = 1, .exit_status = 0, }; gchar* buf = g_malloc0(encoded_res_len); gsize read; res.std_output = g_new0(gchar*, 3); res.std_error = g_new0(gchar*, 2); res.std_output[0] = "foo"; res.std_output[1] = "bar"; res.std_output[2] = NULL; res.std_error[0] = "baz"; res.std_error[1] = NULL; if (pipe(fds)) g_assert_not_reached(); in = g_io_channel_unix_new(fds[0]); out = g_io_channel_unix_new(fds[1]); wshd_send_message(out, &res, err); g_io_channel_set_encoding(in, NULL, NULL); g_io_channel_read_chars(in, msg_size.buf, 4, &read, NULL); g_assert(g_ntohl(msg_size.size) == encoded_res_len); g_io_channel_read_chars(in, buf, encoded_res_len, &read, NULL); g_assert_no_error(err); g_assert(read == encoded_res_len); for (gint i = 0; i < encoded_res_len; i++) g_assert(buf[i] == encoded_res[i]); g_free(res.std_output); g_free(res.std_error); g_free(buf); } int main(int argc, char** argv) { g_test_init(&argc, &argv, NULL); g_test_add_func("/Server/Output/SendMessage", test_send_message); return g_test_run(); }
EXPORT_C #endif guint32 gst_rtp_buffer_get_ssrc (GstBuffer * buffer) { g_return_val_if_fail (GST_IS_BUFFER (buffer), 0); g_return_val_if_fail (GST_BUFFER_DATA (buffer) != NULL, 0); return g_ntohl (GST_RTP_HEADER_SSRC (buffer)); }
void TreeDict::load_model(gchar **buffer, GtkTreeIter *parent, guint32 count) { GtkTreeIter iter; gchar *p1; guint32 offset, size, subentry_count; for (guint32 i=0; i< count; i++) { p1 = *buffer + strlen(*buffer) +1; offset = g_ntohl(get_uint32(p1)); p1 += sizeof(guint32); size = g_ntohl(get_uint32(p1)); p1 += sizeof(guint32); subentry_count = g_ntohl(get_uint32(p1)); p1 += sizeof(guint32); gtk_tree_store_append(model, &iter, parent); gtk_tree_store_set(model, &iter, 0, *buffer, 1, offset, 2, size, -1); *buffer = p1; if (subentry_count) load_model(buffer, &iter, subentry_count); } }
static gboolean source_next_uint32 (SerialSource* source, guint32 *ptr) { guint32 x; if (! source->source_read (source, (guint8*) &x, sizeof (x))) return FALSE; (*ptr) = g_ntohl (x); return TRUE; }
EXPORT_C #endif guint16 gst_rtp_buffer_list_get_seq (GstBufferList * list) { GstBuffer *buffer; buffer = gst_buffer_list_get (list, 0, 0); g_return_val_if_fail (buffer != NULL, 0); return g_ntohl (GST_RTP_HEADER_SEQ (GST_BUFFER_DATA (buffer))); }
static gboolean btsnoop_seek_read(wtap *wth, gint64 seek_off, union wtap_pseudo_header *pseudo_header, guint8 *pd, int length, int *err, gchar **err_info) { int bytes_read; struct btsnooprec_hdr hdr; guint32 flags; if (file_seek(wth->random_fh, seek_off, SEEK_SET, err) == -1) return FALSE; /* Read record header. */ errno = WTAP_ERR_CANT_READ; bytes_read = file_read(&hdr, sizeof hdr, wth->random_fh); if (bytes_read != sizeof hdr) { *err = file_error(wth->random_fh, err_info); if (*err == 0 && bytes_read != 0) *err = WTAP_ERR_SHORT_READ; return FALSE; } flags = g_ntohl(hdr.flags); /* * Read the packet data. */ if (!snoop_read_rec_data(wth->random_fh, pd, length, err, err_info)) return FALSE; /* failed */ if(wth->file_encap == WTAP_ENCAP_BLUETOOTH_H4_WITH_PHDR) { pseudo_header->p2p.sent = (flags & KHciLoggerControllerToHost) ? FALSE : TRUE; } else if(wth->file_encap == WTAP_ENCAP_BLUETOOTH_HCI) { pseudo_header->bthci.sent = (flags & KHciLoggerControllerToHost) ? FALSE : TRUE; if(flags & KHciLoggerCommandOrEvent) { if(pseudo_header->bthci.sent) { pseudo_header->bthci.channel = BTHCI_CHANNEL_COMMAND; } else { pseudo_header->bthci.channel = BTHCI_CHANNEL_EVENT; } } else { pseudo_header->bthci.channel = BTHCI_CHANNEL_ACL; } } return TRUE; }
static gboolean decode_header_content_with_index (const gchar *buffer, gint length, gint *index, const gchar **name, const gchar **value, GError **error) { gint null_character_point; guint32 normalized_index; gchar *error_message; if (length < sizeof(guint32)) { return FALSE; } memcpy(&normalized_index, buffer, sizeof(guint32)); *index = g_ntohl(normalized_index); buffer += sizeof(guint32); length -= sizeof(guint32); error_message = g_strdup_printf("name isn't terminated by NULL " "on header:"); null_character_point = milter_decoder_decode_null_terminated_value(buffer, length, error, error_message); g_free(error_message); if (null_character_point <= 0) return FALSE; *name = buffer; buffer += (null_character_point + 1); length -= (null_character_point + 1); error_message = g_strdup_printf("value isn't terminated by NULL " "on header: <%s>", *name); null_character_point = milter_decoder_decode_null_terminated_value(buffer, length, error, error_message); g_free(error_message); if (null_character_point < 0) return FALSE; else if (null_character_point == 0) return TRUE; *value = buffer; return TRUE; }
bool load_index(const std::string& ridx_url, index_vect_t &index_vect, gulong filesize, gulong filecount, index_type_t index_type) { std::vector<char> buffer(filesize); if(index_type == itRidx) { FILE *f = fopen(ridx_url.c_str(), "rb"); if(!f) return false; size_t the_size; the_size = fread(&buffer[0], 1, filesize, f); if (the_size != filesize) { g_print("fread error!\n"); } fclose(f); } else if(index_type == itRidxGz) { gzFile f = gzopen(ridx_url.c_str(), "rb"); if (f == NULL) return false; gulong len = gzread(f, &buffer[0], filesize); gzclose(f); if(len != filesize) return false; } else return false; index_vect.resize(filecount); char *p = &buffer[0]; for(gulong i=0; i<filecount; ++i) { index_vect[i].key = p; p += strlen(p) + 1; index_vect[i].off = g_ntohl(get_uint32(p)); p += sizeof(guint32); index_vect[i].size = g_ntohl(get_uint32(p)); p += sizeof(guint32); } g_assert(gulong(p-&buffer[0]) == filesize); return true; }
void SCTPGraphDialog::drawTSNGraph() { GList *listTSN = NULL,*tlist; tsn_t *tsn; guint8 type; guint32 tsnumber=0; if (direction == 1) { listTSN = g_list_last(selected_assoc->tsn1); } else { listTSN = g_list_last(selected_assoc->tsn2); } while (listTSN) { tsn = (tsn_t*) (listTSN->data); tlist = g_list_first(tsn->tsns); while (tlist) { type = ((struct chunk_header *)tlist->data)->type; if (type == SCTP_DATA_CHUNK_ID || type == SCTP_I_DATA_CHUNK_ID || type == SCTP_FORWARD_TSN_CHUNK_ID) { tsnumber = g_ntohl(((struct data_chunk_header *)tlist->data)->tsn); yt.append(tsnumber); xt.append(tsn->secs + tsn->usecs/1000000.0); ft.append(tsn->frame_number); } tlist = g_list_next(tlist); } listTSN = g_list_previous(listTSN); } QCPScatterStyle myScatter; myScatter.setShape(QCPScatterStyle::ssCircle); myScatter.setSize(3); int graphcount = ui->sctpPlot->graphCount(); // create graph and assign data to it: // Add TSN graph if (xt.size() > 0) { QCPGraph *gr = ui->sctpPlot->addGraph(); gr->setName(QString("TSN")); myScatter.setPen(QPen(Qt::black)); myScatter.setBrush(Qt::black); ui->sctpPlot->graph(graphcount)->setScatterStyle(myScatter); ui->sctpPlot->graph(graphcount)->setLineStyle(QCPGraph::lsNone); ui->sctpPlot->graph(graphcount)->setData(xt, yt); typeStrings.insert(graphcount, QString(tr("TSN"))); } }
/* overwrite parity-data with a calculated repair payload */ int pgm_rxw_push_nth_repair ( pgm_rxw_t* r, guint32 sequence_number, guint32 trail, struct pgm_opt_fragment* opt_fragment, /* in network order */ gpointer data, guint16 length, pgm_time_t nak_rb_expiry ) { ASSERT_RXW_BASE_INVARIANT(r); /* advances window */ if ( !ABS_IN_RXW(r, sequence_number) ) { pgm_rxw_window_update (r, trail, r->lead, r->tg_size, r->tg_sqn_shift, nak_rb_expiry); } /* check if window is not empty */ g_assert ( !pgm_rxw_empty (r) ); g_assert ( ABS_IN_RXW(r, sequence_number) ); pgm_rxw_packet_t* rp = RXW_PACKET(r, sequence_number); g_assert ( rp->state == PGM_PKT_HAVE_PARITY_STATE ); /* return parity block */ pgm_rxw_data_free1 (r, rp); r->fragment_count++; if (opt_fragment) { memcpy (&rp->opt_fragment, opt_fragment, sizeof(struct pgm_opt_fragment)); g_assert( g_ntohl (rp->of_apdu_len) > 0 ); } rp->data = data; rp->length = length; rp->state = PGM_PKT_HAVE_DATA_STATE; r->parity_count--; ASSERT_RXW_BASE_INVARIANT(r); return PGM_RXW_OK; }
gint32 thrift_binary_protocol_read_i32 (ThriftProtocol *protocol, gint32 *value, GError **error) { g_return_val_if_fail (THRIFT_IS_BINARY_PROTOCOL (protocol), -1); gint32 ret; gpointer b[4]; if ((ret = thrift_transport_read (protocol->transport, b, 4, error)) < 0) { return -1; } *value = *(gint32 *) b; *value = g_ntohl (*value); return ret; }