void rtconfig_init(endpoint_t *_endpoint) { num_rtcs = 0; endpoint = _endpoint; // init the packet structs packet_init(&buspack, OPT_BUFFER_LENGTH, (uint8_t*)buf); packet_init(&outpack, OUT_BUFFER_LENGTH, (uint8_t*)outbuf); // initialize the server communication with PETSCII current_charset = CHARSET_PETSCII; }
// client handlers void vc_handler_createchannel(ascnhalf_socket *s, packet *p) { uint8 type; uint32 request_id; packet reply; voice_channel * chn; uint8 error; uint16 reply_id; type = packet_readu8(p); request_id = packet_readu32(p); // attempt to create the channel chn = voice_channel_create((int)type, (void*)s); if( chn == NULL ) { // channel creation failed error = 1; packet_init(VOICECHAT_SMSG_CHANNEL_CREATED, 5, &reply); packet_writeu32(&reply, request_id); packet_writeu8(&reply, error); // send reply socket_send(s, &reply); // free buffer packet_free(&reply); } else { // channel creation successful error = 0; reply_id = chn->channel_id; packet_init(VOICECHAT_SMSG_CHANNEL_CREATED, 7, &reply); packet_writeu32(&reply, request_id); packet_writeu8(&reply, error); packet_writeu16(&reply, reply_id); // send reply socket_send(s, &reply); // free buffer packet_free(&reply); // increment this ++s->channelcount; ++g_channelCount; } }
void parse_packet(uint8_t *notused, const struct pcap_pkthdr *phdr, const uint8_t *packet) { size_t pk_len=0; int pk_layer=0; extern pcap_dumper_t *pdump; if (packet == NULL || phdr == NULL) { ERR("%s is null", packet == NULL ? "packet" : "pcap header"); return; } /* when you forget to put this here, it makes for really dull pcap log files */ if (s->pcap_dumpfile) { pcap_dump((uint8_t *)pdump, phdr, packet); } pk_len=phdr->caplen; if (pk_len <= s->ss->header_len) { ERR("this packet is too short " STFMT ", header length is %u", pk_len, s->ss->header_len); return; } if (ISDBG(M_PKT) || GET_SNIFF()) { INF("got packet with length %u (cap %u) with header length at %u", phdr->len, phdr->caplen, s->ss->header_len); } pk_len -= s->ss->header_len; packet += s->ss->header_len; pk_layer++; switch (s->ss->mode) { case MODE_ARPSCAN: report_init(REPORT_TYPE_ARP, &phdr->ts); packet_init(packet, pk_len); decode_arp(packet, pk_len, pk_layer); /* the pcap filter should be arp only */ break; case MODE_TCPSCAN: case MODE_UDPSCAN: case MODE_ICMPSCAN: case MODE_IPSCAN: report_init(REPORT_TYPE_IP, &phdr->ts); packet_init(packet, pk_len); decode_ip(packet, pk_len, pk_layer); /* the pcap filter should be ip only */ break; } return; }
payload_size_t data_hub_assign_page(void (* packet_maker)(packet_t *)){ payload_t *next_free_page = free_page + PAGE_SIZE; if(next_free_page >= (payload_buf + sizeof(payload_buf))){ next_free_page -= sizeof(payload_buf); } if(next_free_page == locked_page){return 0;} packet_init(&packet, free_page, PAGE_SIZE); packet_maker(&packet); if(packet.current == packet.buf_begin){ return 0; } free_page = next_free_page; do{ #define whether_send_telemetry(page, frequency) \ if(*packet.buf_begin == page){ \ static __xdata unsigned char count = 0; \ if(++count < frequency){break;} \ count = 0; \ } whether_send_telemetry('A', 20) // 'A' page : approximately 5 Hz else whether_send_telemetry('P', 2) // 'P' page : approximately 1 Hz else whether_send_telemetry('M', 2) // 'M' page : approximately 1 Hz else break; data_hub_send_telemetry(packet.buf_begin); }while(0); return PAGE_SIZE; }
int main(int argc, char * argv[]) { int i = 0; int j = 0; char *state_table[] = { #include "packet_names.h" }; struct gps_packet_t lexer; packet_init(&lexer); for (i = 0; i < 7; i++) { printf("Sentence no %d\n", i); for(j = 0; j < strlen(nmea[i]); j++) { lexer.inbuffer[lexer.inbuflen] = nmea[i][j]; lexer.inbuflen++; if(lexer.inbuflen % 10 == 0) packet_parse(&lexer); } lexer.inbuffer[lexer.inbuflen] = '\r'; lexer.inbuflen++; lexer.inbuffer[lexer.inbuflen] = '\n'; lexer.inbuflen++; } packet_parse(&lexer); return 0; }
void mac_tdma_init (uint16_t addr) { if (tdma_mutex == NULL) { tdma_mutex = xSemaphoreCreateMutex(); } /* Init libs. */ soft_timer_init(); packet_init(); /* Init tdma modules. */ tdma_frame_init(); tdma_slot_init(); /* eventually generate address */ if (addr == 0x0000 || addr == 0xffff) { addr = uid->uid16[0] ^ uid->uid16[1] ^ uid->uid16[2] ^ uid->uid16[3] ^ uid->uid16[4] ^ uid->uid16[5]; if (addr == 0x0000 || addr == 0xffff) { addr ^= 0x00ff; } log_info("Generating address from id -> %04x", addr); } /* Init structure */ tdma_data.addr = addr; tdma_data.state = TDMA_IDLE; tdma_data.slot_cb = NULL; }
void draw_init_env() { framebuffer_t frame; zbuffer_t z; packet_t *packet = packet_init(16,PACKET_NORMAL); qword_t *q = packet->data; frame.width = 640; frame.height = 448; frame.psm = GS_PSM_32; frame.mask = 0; frame.address = graph_vram_allocate(frame.width,frame.height,frame.psm,GRAPH_ALIGN_PAGE); z.enable = 0; z.method = ZTEST_METHOD_GREATER; z.address = 0; z.mask = 1; z.zsm = 0; graph_initialize(frame.address,640,448,GS_PSM_32,0,0); q = draw_setup_environment(q,0,&frame,&z); q = draw_finish(q); dma_channel_send_normal(DMA_CHANNEL_GIF,packet->data, q - packet->data, 0,0); dma_wait_fast(); packet_free(packet); }
void ping_master(const char *master_addr, int port, const char *servername, int clients, int players, int creatures) { struct sockaddr_in master; socklen_t addrlen = sizeof(struct sockaddr_in); size_t namelen = strlen(servername); if (namelen > 32) namelen = 32; memset(&master, 0, sizeof(struct sockaddr_in)); master.sin_family = AF_INET; master.sin_addr.s_addr = inet_addr(master_addr); master.sin_port = htons(port); int sock = socket(AF_INET, SOCK_DGRAM, 0); if (sock < 0) return; packet_t packet; packet_init(&packet, PACKET_MASTER_PING); packet_write08(&packet, clients); packet_write08(&packet, players); packet_write08(&packet, creatures); packet_writeXX(&packet, servername, namelen); packet.len = packet.offset; sendto(sock, &packet, PACKET_HEADER_SIZE + packet.len, 0, (struct sockaddr *)&master, addrlen); close(sock); }
static void xsync_put(uint8_t command, uint8_t * data, size_t size) { struct packet_t packet; packet_init(&packet, command, data, size); packet_put(&packet); }
void packet_send_open_window(struct client *client, uint8_t type, const char *title, uint8_t slots) { bedrock_packet packet; uint8_t use_title = 1; if (!title) { title = ""; use_title = 0; } while (++window_id == 0); #if 0 packet_init(&packet, SERVER_OPEN_WINDOW); packet_pack_byte(&packet, window_id); packet_pack_byte(&packet, type); packet_pack_string(&packet, title); packet_pack_byte(&packet, slots); packet_pack_byte(&packet, use_title); client_send_packet(client, &packet); client->window_data.id = window_id; client->window_data.type = type; #endif }
static void wbsrv_accept(struct stream_connection *conn) { struct wbsrv_listen_socket *listen_socket = talloc_get_type(conn->private_data, struct wbsrv_listen_socket); struct wbsrv_connection *wbconn; wbconn = talloc_zero(conn, struct wbsrv_connection); if (!wbconn) { stream_terminate_connection(conn, "wbsrv_accept: out of memory"); return; } wbconn->conn = conn; wbconn->listen_socket = listen_socket; wbconn->lp_ctx = listen_socket->service->task->lp_ctx; conn->private_data = wbconn; wbconn->packet = packet_init(wbconn); if (wbconn->packet == NULL) { wbsrv_terminate_connection(wbconn, "wbsrv_accept: out of memory"); return; } packet_set_private(wbconn->packet, wbconn); packet_set_socket(wbconn->packet, conn->socket); packet_set_callback(wbconn->packet, wbsrv_samba3_process); packet_set_full_request(wbconn->packet, wbsrv_samba3_packet_full_request); packet_set_error_handler(wbconn->packet, wbsrv_recv_error); packet_set_event_context(wbconn->packet, conn->event.ctx); packet_set_fde(wbconn->packet, conn->event.fde); packet_set_serialise(wbconn->packet); }
void usb_cdc_ecm_rx(uint8_t ep, uint8_t stat) { int len; int ip_length; int i; uint16_t eth_hdr_type; //printf("cdc ecm rx ep-state=%x state=%d transferred=%d",stat,rndisRxState,rndisRxTransferCount); switch (rndisRxState) { case RNDIS_RX_IDLE: rndisRxTransferCount = 0; rndisRxPacketSize = 0; /* it may increase later */ /* hopefully, it follows the header immediately... */ if (receive_packet == 0) { if (RING_IS_FULL(receive_ring_head, receive_ring_tail, RECEIVE_RING_SIZE)) { rndisRxState = RNDIS_RX_DROP; DBG("usb_eth_rx: receive ring is full, head=%d, tail=%d",receive_ring_head, receive_ring_tail); len = usbRead(ep, NULL, 64); } else { rndisRxState = RNDIS_RX_RECV; receive_packet = &receive_ring[receive_ring_tail]; packet_init(receive_packet); len = usbRead(ep, receive_packet->data , 64); rndisRxTransferCount += len; } } break; case RNDIS_RX_DROP: len = usbRead(ep, NULL, 64); //ETH_DEV_DBG_INFO("rndis rx read %d bytes more in drop state",len); if (len >= 0) rndisRxTransferCount += len; break; case RNDIS_RX_RECV: len = usbRead(ep, (receive_packet->data) + rndisRxTransferCount, 64 /* maybe we need to limit this */); if (len >= 0) rndisRxTransferCount += len; break; } if (len < 64) { /* a short packet terminates the Ethernet frame */ rndisRxPackets++; DBG("cdc ecm rx done with a packet (%d bytes)",rndisRxTransferCount); //for (i=0; i<rndisRxPacketSize; i++) DBG("%d %02x",i,(receive_packet->data)[i]); //if (rndisRxPacketSize==54) while(1); if (rndisRxState == RNDIS_RX_RECV) { receive_packet->size = rndisRxTransferCount; receive_packet = 0; RING_INC(receive_ring_tail, RECEIVE_RING_SIZE); } rndisRxState = RNDIS_RX_IDLE; } }
void hdmirx_hw_reset(void) { hdmirx_print("%s %d\n", __func__, rx.port); //WRITE_CBUS_REG(RESET0_REGISTER, 0x8); //reset HDMIRX module //mdelay(10); //clk_init(); hdmirx_wr_top(HDMIRX_TOP_INTR_MASKN, 0); //disable top interrupt gate hdmirx_wr_top( HDMIRX_TOP_SW_RESET, 0x3f); mdelay(1); control_reset(0); hdmirx_wr_top( HDMIRX_TOP_PORT_SEL, (1<<rx.port)); //EDID port select hdmirx_interrupts_cfg(false); //disable dwc interrupt if(hdcp_enable){ hdmi_rx_ctrl_hdcp_config(&rx.hdcp); } else { hdmirx_wr_bits_dwc( RA_HDCP_CTRL, HDCP_ENABLE, 0); } /*phy config*/ //hdmirx_phy_restart(); //hdmi_rx_phy_fast_switching(1); phy_init(rx.port, 0); //port, dcm /**/ /* control config */ control_init(rx.port); audio_init(); packet_init(); hdmirx_audio_fifo_rst(); hdmirx_packet_fifo_rst(); /**/ control_reset(1); /*enable irq */ hdmirx_wr_top(HDMIRX_TOP_INTR_STAT_CLR, ~0); hdmirx_wr_top(HDMIRX_TOP_INTR_MASKN, 0x00001fff); hdmirx_interrupts_hpd(true); /**/ #ifndef USE_GPIO_FOR_HPD hdmi_rx_ctrl_hpd(true); hdmirx_wr_top( HDMIRX_TOP_HPD_PWR5V, (1<<5)|(1<<4)); //invert HDP output #endif /* wait at least 4 video frames (at 24Hz) : 167ms for the mode detection recover the video mode */ mdelay(200); /* Check If HDCP engine is in Idle state, if not wait for authentication time. 200ms is enough if no Ri errors */ if (hdmirx_rd_dwc(0xe0) != 0) { mdelay(200); } }
/* main: * Entry point. See usage(). */ int main(int argc, char **argv) { pthread_t thread; struct sigaction sa = {}; setlocale(LC_ALL, ""); /* TODO: tidy this up */ /* read command line options and config file */ config_init(); options_set_defaults(); options_read_args(argc, argv); /* If a config was explicitly specified, whinge if it can't be found */ read_config(options.config_file, options.config_file_specified); options_make(); sa.sa_handler = finish; sigaction(SIGINT, &sa, NULL); pthread_mutex_init(&tick_mutex, NULL); packet_init(); init_history(); if (options.no_curses) { tui_init(); } else { ui_init(); } pthread_create(&thread, NULL, (void*)&packet_loop, NULL); /* Keep the starting time (used for timed termination) */ first_timestamp = time(NULL); if (options.no_curses) { if (options.timed_output) { while(!foad) { sleep(1); } } else { tui_loop(); } } else { ui_loop(); } pthread_cancel(thread); ui_finish(); return 0; }
void comm_usb_init(void) { comm_usb_serial_init(); packet_init(send_packet, process_packet, PACKET_HANDLER); chMtxObjectInit(&send_mutex); // Threads chThdCreateStatic(serial_read_thread_wa, sizeof(serial_read_thread_wa), NORMALPRIO, serial_read_thread, NULL); chThdCreateStatic(serial_process_thread_wa, sizeof(serial_process_thread_wa), NORMALPRIO, serial_process_thread, NULL); }
void comm_init(void) { myUSBinit(); packet_init(send_packet, process_packet); chMtxInit(&send_mutex); // Threads chThdCreateStatic(serial_read_thread_wa, sizeof(serial_read_thread_wa), NORMALPRIO, serial_read_thread, NULL); chThdCreateStatic(serial_process_thread_wa, sizeof(serial_process_thread_wa), NORMALPRIO, serial_process_thread, NULL); chThdCreateStatic(timer_thread_wa, sizeof(timer_thread_wa), NORMALPRIO, timer_thread, NULL); }
int cmd_capture(int argc, char **argv) { parse_opts(argc, argv, capture_options, capture_usage); argv += optind; if (help_opt || !*argv || argv[1]) parse_usage_and_die(capture_usage, capture_options); char *dev = argv[0]; int fd = socket(PF_PACKET, SOCK_RAW, htons(ETH_P_ALL)); if (fd < 0) die_errno("Unable to obtain monitoring socket"); if (dev_bind_ifname(fd, dev) < 0) perror("Unable to bind device on the socket"); FILE *fp = NULL; if (ofilename) { fp = fopen(ofilename, "wb"); if (!fp) die_errno("fopen"); } struct pkt_hdr pkt; packet_init(&pkt); int captured = 0; for (;;) { if (packet_get(fd, &pkt, NULL, NULL) == -1) die_errno("fail to get packet"); if (!pkt.pkt_len) continue; printf("."); fflush(stdout); if (fp) fwrite(&pkt, sizeof(pkt), 1, fp); if (++captured == cap_nr_pkt) break; } printf("\n"); packet_destroy(&pkt); close(fd); if (fp) fclose(fp); return 0; }
/* send conn's ip and port which used to connect to user server * to mesage server */ void send_conn_info_to_message(struct conn_server *server) { struct list_packet *lp = allocator_malloc(&server->packet_allocator); packet_init(lp); set_length(lp, 18); set_command(lp, CMD_CONN_INFO); set_field_uint32_t(get_parameters(lp), 0, server->conn_user_ip); set_field_uint16_t(get_parameters(lp), 4, server->conn_user_port); list_add_tail(&lp->list, &(server->message_conn.send_packet_list)); wait_for_write(server->efd, server->message_conn.sfd); }
/* create a transport structure based on an established socket */ struct smbcli_transport *smbcli_transport_init(struct smbcli_socket *sock, TALLOC_CTX *parent_ctx, bool primary, struct smbcli_options *options) { struct smbcli_transport *transport; transport = talloc_zero(parent_ctx, struct smbcli_transport); if (!transport) return NULL; if (primary) { transport->socket = talloc_steal(transport, sock); } else { transport->socket = talloc_reference(transport, sock); } transport->negotiate.protocol = PROTOCOL_NT1; transport->options = *options; transport->negotiate.max_xmit = transport->options.max_xmit; /* setup the stream -> packet parser */ transport->packet = packet_init(transport); if (transport->packet == NULL) { talloc_free(transport); return NULL; } packet_set_private(transport->packet, transport); packet_set_socket(transport->packet, transport->socket->sock); packet_set_callback(transport->packet, smbcli_transport_finish_recv); packet_set_full_request(transport->packet, packet_full_request_nbt); packet_set_error_handler(transport->packet, smbcli_transport_error); packet_set_event_context(transport->packet, transport->socket->event.ctx); packet_set_nofree(transport->packet); packet_set_initial_read(transport->packet, 4); smbcli_init_signing(transport); ZERO_STRUCT(transport->called); /* take over event handling from the socket layer - it only handles events up until we are connected */ talloc_free(transport->socket->event.fde); transport->socket->event.fde = event_add_fd(transport->socket->event.ctx, transport->socket->sock, socket_get_fd(transport->socket->sock), EVENT_FD_READ, smbcli_transport_event_handler, transport); packet_set_fde(transport->packet, transport->socket->event.fde); packet_set_serialise(transport->packet); talloc_set_destructor(transport, transport_destructor); return transport; }
void packet_send_destroy_entity_dropped_item(struct client *client, struct dropped_item *di) { bedrock_packet packet; uint8_t count = 1; packet_init(&packet, SERVER_DESTROY_ENTITY); packet_pack_int(&packet, &count, sizeof(count)); packet_pack_int(&packet, &di->eid, sizeof(di->eid)); client_send_packet(client, &packet); }
void packet_send_destroy_entity_player(struct client *client, struct client *c) { bedrock_packet packet; uint8_t count = 1; packet_init(&packet, SERVER_DESTROY_ENTITY); packet_pack_int(&packet, &count, sizeof(count)); packet_pack_int(&packet, &c->id, sizeof(c->id)); client_send_packet(client, &packet); }
void packet_send_update_window_property(struct client *client, int8_t window_id, int16_t property, int16_t value) { bedrock_packet packet; packet_init(&packet, SERVER_UPDATE_WINDOW_PROPERTY); packet_pack_int(&packet, &window_id, sizeof(window_id)); packet_pack_int(&packet, &property, sizeof(property)); packet_pack_int(&packet, &value, sizeof(value)); client_send_packet(client, &packet); }
/* send offline message to status server */ void send_offline_to_status(struct conn_server *server, uint32_t uin) { struct list_packet *lp = allocator_malloc(&server->packet_allocator); packet_init(lp); set_length(lp, 24); set_command(lp, CMD_STATUS_CHANGE); set_uin(lp, uin); set_field_uint32_t(get_parameters(lp), 0, uin); set_field_uint16_t(get_parameters(lp), 10, STATUS_CHANGE_OFFLINE); list_add_tail(&lp->list, &(server->status_conn.send_packet_list)); wait_for_write(server->efd, server->status_conn.sfd); }
void vc_handler_ping(ascnhalf_socket *s, packet *p) { packet bp; uint32 pi; printf("ping!\n"); pi = packet_readu32(p); packet_init(VOICECHAT_SMSG_PONG, 4, &bp); packet_writeu32(&bp, pi); socket_send(s, &bp); packet_free(&bp); }
void ndp_spoof(const u_char *bytes, size_t len) { struct ether *ether = NULL; struct ip6 *ip = NULL; struct icmp6 *icmp = NULL; struct icmp6_nd_ns *ns = NULL; char s1[INET6_ADDRSTRLEN], s2[INET6_ADDRSTRLEN]; struct packet *p = NULL; u_char *mac = NULL; ether = (struct ether *)bytes; ip = (struct ip6 *)(bytes + sizeof(struct ether)); if (ip->nxt == IP6_NXT_ICMP6) { icmp = (struct icmp6 *)(bytes + sizeof(struct ether) + sizeof(struct ip6)); } else { /* TODO */ fatal("no ICMPv6 packet!!! Skipping..."); return; } if (icmp->type == ICMP6_T_ND_NS) { mac = get_mac(iface); if (mac == NULL) return; if (memcmp(mac, ether->src, ETH_ADDR_LEN) == 0) { free(mac); return; } ns = (struct icmp6_nd_ns *)(bytes + sizeof(struct ether) + sizeof(struct ip6) + sizeof(struct icmp6)); bzero(s1, INET6_ADDRSTRLEN); inet_ntop(AF_INET6, ns->target, s1, INET6_ADDRSTRLEN); bzero(s2, INET6_ADDRSTRLEN); inet_ntop(AF_INET6, ip->src, s2, INET6_ADDRSTRLEN); printf("Spoofing %s with target %s\n", s2, s1); p = packet_init(); packet_add_ether(p, mac, ether->src, ETH_TYPE_IP6); packet_add_ip6(p, sizeof(struct icmp6) + sizeof(struct icmp6_nd_na), IP6_NXT_ICMP6, IP6_HLIM, ns->target, ip->src); packet_add_icmp6_nd_na(p, ICMP6_ND_NA_F_SOLICIT | ICMP6_ND_NA_F_OVERRIDE, ns->target); packet_send(iface, p); packet_free(p); free(mac); } }
static void initial_update(client_t *client) { // Protokoll Version senden packet_t packet; packet_init(&packet, PACKET_HANDSHAKE); packet_write08(&packet, PROTOCOL_VERSION); server_send_packet(&packet, client); server_start_compression(client); game_send_initial_update(client); world_send_initial_update(client); player_send_initial_update(client); creature_send_initial_update(client); }
void packet_send_player_list_item(struct client *client, struct client *c, uint8_t online) { bedrock_packet packet; #if 0 packet_init(&packet, SERVER_PLAYER_LIST); packet_pack_string(&packet, c->name); packet_pack_byte(&packet, online); packet_pack_short(&packet, c->ping); client_send_packet(client, &packet); #endif }
void app_uartcomm_start(void) { packet_init(send_packet, process_packet, PACKET_HANDLER); uartStart(&HW_UART_DEV, &uart_cfg); palSetPadMode(HW_UART_TX_PORT, HW_UART_TX_PIN, PAL_MODE_ALTERNATE(HW_UART_GPIO_AF) | PAL_STM32_OSPEED_HIGHEST | PAL_STM32_PUDR_PULLUP); palSetPadMode(HW_UART_RX_PORT, HW_UART_RX_PIN, PAL_MODE_ALTERNATE(HW_UART_GPIO_AF) | PAL_STM32_OSPEED_HIGHEST | PAL_STM32_PUDR_PULLUP); is_running = 1; chThdCreateStatic(packet_process_thread_wa, sizeof(packet_process_thread_wa), NORMALPRIO, packet_process_thread, NULL); }
odp_buffer_t buffer_alloc(odp_pool_t pool_hdl, size_t size) { uint32_t pool_id = pool_handle_to_index(pool_hdl); pool_entry_t *pool = get_pool_entry(pool_id); uintmax_t totsize = pool->s.headroom + size + pool->s.tailroom; odp_anybuf_t *buf; /* Reject oversized allocation requests */ if ((pool->s.flags.unsegmented && totsize > pool->s.seg_size) || (!pool->s.flags.unsegmented && totsize > pool->s.seg_size * ODP_BUFFER_MAX_SEG)) return ODP_BUFFER_INVALID; /* Try to satisfy request from the local cache */ buf = (odp_anybuf_t *)(void *)get_local_buf(&local_cache[pool_id], &pool->s, totsize); /* If cache is empty, satisfy request from the pool */ if (odp_unlikely(buf == NULL)) { buf = (odp_anybuf_t *)(void *)get_buf(&pool->s); if (odp_unlikely(buf == NULL)) return ODP_BUFFER_INVALID; /* Get blocks for this buffer, if pool uses application data */ if (buf->buf.size < totsize) { intmax_t needed = totsize - buf->buf.size; do { uint8_t *blk = get_blk(&pool->s); if (blk == NULL) { ret_buf(&pool->s, &buf->buf); return ODP_BUFFER_INVALID; } buf->buf.addr[buf->buf.segcount++] = blk; needed -= pool->s.seg_size; } while (needed > 0); buf->buf.size = buf->buf.segcount * pool->s.seg_size; } } /* By default, buffers inherit their pool's zeroization setting */ buf->buf.flags.zeroized = pool->s.flags.zeroized; if (buf->buf.type == ODP_EVENT_PACKET) packet_init(pool, &buf->pkt, size); return odp_hdr_to_buf(&buf->buf); }
void packet_send_set_slot(struct client *client, uint8_t window_id, uint16_t slot, struct item *item, uint8_t count, int16_t damage) { bedrock_packet packet; struct item_stack slot_data; slot_data.id = item != NULL ? item->id : -1; slot_data.count = count; slot_data.metadata = damage; packet_init(&packet, SERVER_SET_SLOT); packet_pack_int(&packet, &window_id, sizeof(window_id)); packet_pack_int(&packet, &slot, sizeof(slot)); packet_pack_slot(&packet, &slot_data); client_send_packet(client, &packet); }