I think to have understood about what you refer, the RFC 793 should have anything you need to know.
A good help about the format of the TCP packets can come also from Wireshark or any other sniffer which shows you all the fields.
The following code should give you an "idea" of the format and the usage:
Code:
typedef struct {
uint16_t source;
uint16_t dest;
uint32_t seq;
uint32_t ack_seq;
uint8_t doff;
uint8_t flags;
uint16_t window;
uint16_t check;
uint16_t urg_ptr;
} tcph;
tcp.source = htons(src_port);
tcp.dest = htons(dst_port);
tcp.seq = htonl(*seq1);
tcp.ack_seq = htonl(*ack1);
tcp.doff = sizeof(tcph) << 2;
tcp.flags = TH_SYN;
tcp.window = htons(65535);
tcp.check = htons(0);
tcp.urg_ptr = htons(0);
// now calculate the checksum
If you have doubts about specific fields post here.