6

What I'm trying to do is: Writing client and server for sending a String via TCP with Java, so far no problem using Socket and Input-/Output-Streams.

But now I'm trying to add 3 numbers to the "Options" field in the tcp header enter image description here. I can't find any helpful tutorials or something else on how to customize the header and how to read it.

Any suggestions?

Roman C
  • 49,761
  • 33
  • 66
  • 176
Grt
  • 141
  • 1
  • 2
  • 11
  • 1
    Maybe this will help? http://stackoverflow.com/questions/2653262/how-to-write-custom-data-to-the-tcp-packet-header-options-field-with-java – Daniel Kaplan Jan 10 '13 at 21:53
  • Trying to add what three numbers? Why? The only things in the header that are any of your business have APIs to set them. – user207421 Jul 15 '13 at 23:24

2 Answers2

7

You can't:

  • at application level, you do not have access to the TCP headers;
  • Java does not have raw sockets either.

You can somewhat influence some of the TCP behavior by setting different socket options, though. But not manipulating TCP headers directly.

fge
  • 119,121
  • 33
  • 254
  • 329
1

Not without utilizing external library like jNetPcap. jNetPcap does allow you to format and send your own packet.

jNetPcap Installation Guide (Eclipse)

jNetPcap Installation Guide (NetBeans)

A very rough sample code for formatting and sending packet. Rough it may be, but it shows you the possibilities to customize the packet.

Edit: Forgot to mention that jNetPcap is a Java wrapper for libpcap. They are meant to be utilized to read the packet in the first place.