bcmtcp.h 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. /*
  2. * Copyright 2007, Broadcom Corporation
  3. * All Rights Reserved.
  4. *
  5. * THIS SOFTWARE IS OFFERED "AS IS", AND BROADCOM GRANTS NO WARRANTIES OF ANY
  6. * KIND, EXPRESS OR IMPLIED, BY STATUTE, COMMUNICATION OR OTHERWISE. BROADCOM
  7. * SPECIFICALLY DISCLAIMS ANY IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS
  8. * FOR A SPECIFIC PURPOSE OR NONINFRINGEMENT CONCERNING THIS SOFTWARE.
  9. *
  10. * Fundamental constants relating to TCP Protocol
  11. *
  12. */
  13. #ifndef _bcmtcp_h_
  14. #define _bcmtcp_h_
  15. /* enable structure packing */
  16. #if defined(__GNUC__)
  17. #define PACKED __attribute__((packed))
  18. #else
  19. #pragma pack(1)
  20. #define PACKED
  21. #endif
  22. #define TCP_SRC_PORT_OFFSET 0 /* TCP source port offset */
  23. #define TCP_DEST_PORT_OFFSET 2 /* TCP dest port offset */
  24. #define TCP_CHKSUM_OFFSET 16 /* TCP body checksum offset */
  25. /* These fields are stored in network order */
  26. struct bcmtcp_hdr
  27. {
  28. uint16 src_port; /* Source Port Address */
  29. uint16 dst_port; /* Destination Port Address */
  30. uint32 seq_num; /* TCP Sequence Number */
  31. uint32 ack_num; /* TCP Sequence Number */
  32. uint16 hdrlen_rsvd_flags; /* Header length, reserved bits and flags */
  33. uint16 tcpwin; /* TCP window */
  34. uint16 chksum; /* Segment checksum with pseudoheader */
  35. uint16 urg_ptr; /* Points to seq-num of byte following urg data */
  36. } PACKED;
  37. #undef PACKED
  38. #if !defined(__GNUC__)
  39. #pragma pack()
  40. #endif
  41. /* Byte offset of flags in TCP header */
  42. #define TCP_FLAGS_OFFSET 13
  43. #define TCP_FLAGS_FIN 0x01
  44. #define TCP_FLAGS_SYN 0x02
  45. #define TCP_FLAGS_RST 0x03
  46. #define TCP_FLAGS_PSH 0x04
  47. #define TCP_FLAGS_ACK 0x10
  48. #define TCP_FLAGS_URG 0x20
  49. #define TCP_FLAGS_ECN 0x40
  50. #define TCP_FLAGS_CWR 0x80
  51. #define TCP_FLAGS(tcp_hdr) (((uint8 *)(tcp_hdr))[TCP_FLAGS_OFFSET])
  52. #define TCP_IS_ACK(tcp_hdr) (TCP_FLAGS(tcp_hdr) & TCP_FLAGS_ACK)
  53. #define TCP_SRC_PORT(tcp_hdr) (ntoh16(((struct bcmtcp_hdr*)(tcp_hdr))->src_port))
  54. #define TCP_DST_PORT(tcp_hdr) (ntoh16(((struct bcmtcp_hdr*)(tcp_hdr))->dst_port))
  55. #define TCP_SEQ_NUM(tcp_hdr) (ntoh32(((struct bcmtcp_hdr*)(tcp_hdr))->seq_num))
  56. #define TCP_ACK_NUM(tcp_hdr) (ntoh32(((struct bcmtcp_hdr*)(tcp_hdr))->ack_num))
  57. #endif /* #ifndef _bcmtcp_h_ */