Book Image

iOS and OS X Network Programming Cookbook

By : Jon Hoffman
Book Image

iOS and OS X Network Programming Cookbook

By: Jon Hoffman

Overview of this book

Table of Contents (15 chapters)
iOS and OS X Network Programming Cookbook
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Decoding TCP headers


In the Decoding IP headers recipe of this chapter, we created a decodeIp() function that decoded the IP headers of a packet. In that function, if the protocol type was TCP, we called a decodeTcp() function. We will create the decodeTcp() function in this recipe.

The TCP header is a part of the third layer (Protocol layer) of our header stack.

The TCP header looks like this:

Let's take a look at the fields of the TCP header:

  • Source Port: This identifies the port that the packet is being sent from on the sending device.

  • Destination Port: This identifies the port that the packet is going to on the receiving device.

  • Sequence Number: This is the initial sequence number for this session if the SYN flag is set. If the SYN flag is not set, this is the sequence number of the first data byte of this segment for this session.

  • Acknowledgement Number: This value is the next sequence number that the receiver is expecting if the ACK flag is set. The first ACK packet that is sent by each end...