Skip to content

Commit

Permalink
Merge pull request #12079 from nmeum/pr/gnrc_tcp_gnrc_pktbuf_add
Browse files Browse the repository at this point in the history
gnrc_tcp: Fix invocation of gnrc_pktbuf_add
  • Loading branch information
miri64 committed Sep 16, 2019
2 parents e8b08d3 + 7f3415e commit 56e6887
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions sys/net/gnrc/transport_layer/tcp/gnrc_tcp_pkt.c
Original file line number Diff line number Diff line change
Expand Up @@ -175,15 +175,22 @@ int _pkt_build(gnrc_tcp_tcb_t *tcb, gnrc_pktsnip_t **out_pkt, uint16_t *seq_con,
/* Set offset and control bit accordingly */
tcp_hdr.off_ctl = byteorder_htons(_option_build_offset_control(offset, ctl));

/* Allocate TCP header: size = offset * 4 bytes */
tcp_snp = gnrc_pktbuf_add(pay_snp, &tcp_hdr, offset * 4, GNRC_NETTYPE_TCP);
tcp_snp = gnrc_pktbuf_add(pay_snp, &tcp_hdr, sizeof(tcp_hdr), GNRC_NETTYPE_TCP);
if (tcp_snp == NULL) {
DEBUG("gnrc_tcp_pkt.c : _pkt_build() : Can't allocate buffer for TCP Header\n.");
gnrc_pktbuf_release(pay_snp);
*(out_pkt) = NULL;
return -ENOMEM;
}
else {
/* Resize TCP header: size = offset * 4 bytes */
if (gnrc_pktbuf_realloc_data(tcp_snp, offset * 4)) {
DEBUG("gnrc_tcp_pkt.c : _pkt_build() : Couldn't set size of TCP header\n");
gnrc_pktbuf_release(tcp_snp);
*(out_pkt) = NULL;
return -ENOMEM;
}

/* Add options if existing */
if (TCP_HDR_OFFSET_MIN < offset) {
uint8_t *opt_ptr = (uint8_t *) tcp_snp->data + sizeof(tcp_hdr);
Expand Down

0 comments on commit 56e6887

Please sign in to comment.