How to use the ip.toBuffer function in ip

To help you get started, we’ve selected a few ip examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github noobaa / noobaa-core / src / rpc / stun.js View on Github external
function encode_attr_mapped_addr(addr, buffer, offset, end) {
    buffer.writeUInt16BE(addr.family === 'IPv6' ? 0x02 : 0x01, offset);

    // xor the port against the magic key
    buffer.writeUInt16BE(addr.port, offset + 2);

    ip_module.toBuffer(addr.address, buffer, offset + 4);
}
github graalvm / graaljs / deps / npm / node_modules / socks / build / client / socksclient.js View on Github external
sendSocks5CommandRequest() {
        const buff = new smart_buffer_1.SmartBuffer();
        buff.writeUInt8(0x05);
        buff.writeUInt8(constants_1.SocksCommand[this._options.command]);
        buff.writeUInt8(0x00);
        // ipv4, ipv6, domain?
        if (net.isIPv4(this._options.destination.host)) {
            buff.writeUInt8(constants_1.Socks5HostType.IPv4);
            buff.writeBuffer(ip.toBuffer(this._options.destination.host));
        }
        else if (net.isIPv6(this._options.destination.host)) {
            buff.writeUInt8(constants_1.Socks5HostType.IPv6);
            buff.writeBuffer(ip.toBuffer(this._options.destination.host));
        }
        else {
            buff.writeUInt8(constants_1.Socks5HostType.Hostname);
            buff.writeUInt8(this._options.destination.host.length);
            buff.writeString(this._options.destination.host);
        }
        buff.writeUInt16BE(this._options.destination.port);
        this._nextRequiredPacketBufferSize =
            constants_1.SOCKS_INCOMING_PACKET_SIZES.Socks5ResponseHeader;
        this._socket.write(buff.toBuffer());
        this.state = constants_1.SocksClientState.SentFinalHandshake;
    }
    /**
github noobaa / noobaa-core / src / rpc / stun.js View on Github external
function encode_attr_xor_mapped_addr(addr, buffer, offset, end) {
    buffer.writeUInt16BE(addr.family === 'IPv6' ? 0x02 : 0x01, offset);

    // xor the port against the magic key
    buffer.writeUInt16BE(addr.port ^ buffer.readUInt16BE(stun.XOR_KEY_OFFSET), offset + 2);

    ip_module.toBuffer(addr.address, buffer, offset + 4);
    var k = stun.XOR_KEY_OFFSET;
    for (var i = offset + 4; i < end; ++i) {
        buffer[i] ^= buffer[k];
        k += 1;
    }
}
github graalvm / graaljs / deps / npm / node_modules / socks / build / client / socksclient.js View on Github external
sendSocks4InitialHandshake() {
        const userId = this._options.proxy.userId || '';
        const buff = new smart_buffer_1.SmartBuffer();
        buff.writeUInt8(0x04);
        buff.writeUInt8(constants_1.SocksCommand[this._options.command]);
        buff.writeUInt16BE(this._options.destination.port);
        // Socks 4 (IPv4)
        if (net.isIPv4(this._options.destination.host)) {
            buff.writeBuffer(ip.toBuffer(this._options.destination.host));
            buff.writeStringNT(userId);
            // Socks 4a (hostname)
        }
        else {
            buff.writeUInt8(0x00);
            buff.writeUInt8(0x00);
            buff.writeUInt8(0x00);
            buff.writeUInt8(0x01);
            buff.writeStringNT(userId);
            buff.writeStringNT(this._options.destination.host);
        }
        this._nextRequiredPacketBufferSize =
            constants_1.SOCKS_INCOMING_PACKET_SIZES.Socks4Response;
        this._socket.write(buff.toBuffer());
    }
    /**
github blinksocks / blinksocks / src / presets / v2ray-vmess.js View on Github external
onInitTargetAddress({ host, port }) {
    const type = getAddrType(host);
    this._atyp = type;
    this._port = ntb(port);
    this._host = (type === ATYP_DOMAIN) ? Buffer.from(host) : ip.toBuffer(host);
  }
github latysheff / node-sctp / lib / association.js View on Github external
this._heartbeatInterval = setInterval(() => {
      /*
       To probe an address for verification, an endpoint will send
       HEARTBEATs including a 64-bit random nonce and a path indicator (to
       identify the address that the HEARTBEAT is sent to) within the
       HEARTBEAT parameter.
       */
      for (const address in this.destinations) {
        const destination = this.destinations[address]
        const heartbeatInfo = crypto.randomBytes(12)
        const nonce = heartbeatInfo.readUInt32BE(0)
        this.nonces[nonce] = true
        ip.toBuffer(address, heartbeatInfo, 8)
        this.debugger.trace(
          '> heartbeat to %s, %d bytes',
          address,
          heartbeatInfo.length,
          heartbeatInfo,
          destination
        )
        this._sendChunk('heartbeat', { heartbeat_info: heartbeatInfo }, address)
        /*
         The endpoint should increment the respective error counter of the
         destination transport address each time a HEARTBEAT is sent to that
         address and not acknowledged within one RTO.

         When the value of this counter reaches the protocol parameter
         'Path.Max.Retrans', the endpoint should mark the corresponding
         destination address as inactive if it is not so marked, and may also
github latysheff / node-sctp / lib / transport.js View on Github external
function createHeader (packet) {
  const buffer = Buffer.from(IP_HEADER_TEMPLATE)
  writeLength(buffer, buffer.length + packet.payload.length)
  if (packet.ttl > 0 && packet.ttl < 0xFF) {
    buffer.writeUInt8(packet.ttl, 8)
  }
  ip.toBuffer(packet.src, buffer, 12)
  ip.toBuffer(packet.dst, buffer, 16)
  return buffer
}
github mozilla / fxa / packages / fxa-auth-db-mysql / lib / db / mysql.js View on Github external
function ipHmac(key, uid, addr) {
    if (ip.isV4Format(addr)) {
      addr = '::' + addr
    }
    addr = ip.toBuffer(addr)

    var hmac = crypto.createHmac('sha256', key)
    hmac.update(uid)
    hmac.update(addr)

    return hmac.digest()
  }
github mappum / bitcoin-protocol / src / types.js View on Github external
function encode (value, buffer, offset) {
    if (!buffer) buffer = Buffer.alloc(16)
    if (!offset) offset = 0
    if (offset + 16 > buffer.length) throw new RangeError('destination buffer is too small')

    if (ip.isV4Format(value)) {
      IPV4_PREFIX.copy(buffer, offset)
      ip.toBuffer(value, buffer, offset + 12)
    } else if (ip.isV6Format(value)) {
      ip.toBuffer(value, buffer, offset)
    } else {
      throw Error('Invalid IP address value')
    }

    return buffer
  }
github android-js / androidjs-builder / example / helloworld / node_modules / dns-packet / index.js View on Github external
ra.encode = function (host, buf, offset) {
  if (!buf) buf = Buffer.allocUnsafe(ra.encodingLength(host))
  if (!offset) offset = 0

  buf.writeUInt16BE(4, offset)
  offset += 2
  ip.toBuffer(host, buf, offset)
  ra.encode.bytes = 6
  return buf
}