Giter Site home page Giter Site logo

tcp-packet's Introduction

tcp-packet

Encode/decode raw tcp packets. Currently very incomplete.

$ npm install tcp-packet

Usage

const tcp = require('tcp-packet')

const packet = tcp.decode(Buffer.from('c3560050ee7d2560b5e66669801801c90a5900000101080a000276e95dd3f7a668656c6c6f0a', 'hex'))
console.log(packet)
/*
  {
    sourcePort: 50006,
    destinationPort: 80,
    sequenceNumber: 4001178976,
    acknowledgmentNumber: 3051775593,
    dataOffset: 8,
    flags: 24,
    reserved: 0,
    ns: 0,
    cwr: 0,
    ece: 0,
    urg: 0,
    ack: 1,
    psh: 1,
    rst: 0,
    syn: 0,
    fin: 0,
    windowSize: 457,
    checksum: 2649,
    urgentPointer: 0,
    data: <Buffer 68 65 6c 6c 6f 0a>
  }
*/
console.log(packet.data.toString())
// hello\n

API

ip.encode({ data, sourcePort, destinationPort, sequenceNumber, acknowledgmentNumber })

Encodes a packet. Returns a buffer. The packet should look like this:

{
  data: <Buffer>,
  sourcePort: 12345,
  destinationPort: 80,
  sequenceNumbe: 1234567,
  acknowledgmentNumber: 7654321
}

ip.decode(buffer)

Decodes a packet from a buffer. A buffer could look like Buffer.from('c3560050ee7d2560b5e66669801801c90a5900000101080a000276e95dd3f7a668656c6c6f0a', 'hex')) and return something like this:

{
  sourcePort: 50006,
  destinationPort: 80,
  sequenceNumber: 4001178976,
  acknowledgmentNumber: 3051775593,
  dataOffset: 8,
  flags: 24,
  reserved: 0,
  ns: 0,
  cwr: 0,
  ece: 0,
  urg: 0,
  ack: 1,
  psh: 1,
  rst: 0,
  syn: 0,
  fin: 0,
  windowSize: 457,
  checksum: 2649,
  urgentPointer: 0,
  data: <Buffer 68 65 6c 6c 6f 0a>
}

tcp-packet's People

Contributors

freeall avatar

Stargazers

Aly Abdelrahman avatar  avatar Wahid Niam avatar  avatar

Watchers

 avatar James Cloos avatar Jeff Fowler avatar Henrik Aagaard avatar Håkon Westh-Hansen avatar Farhad H. P. Shirvan avatar Dave J. Franco avatar CCS avatar Dalsmo avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.