Giter Club home page Giter Club logo

Comments (6)

gafferongames avatar gafferongames commented on September 27, 2024

What does the ipv6 address data look like as an array of bytes in the connect token that you generate?

from netcode.

gafferongames avatar gafferongames commented on September 27, 2024

I would expect the array of bytes should look like:

0x00000000000000000000000000000100

Which when read into a uint16_t should look like:

0x0001 in the uint16 value?

from netcode.

gafferongames avatar gafferongames commented on September 27, 2024

(because little endian switches byte order from a uint16 when its read in from memory, while big endian does not... but for both little endian and big endian, the format of a uint16_t in register is the same).

from netcode.

wirepair avatar wirepair commented on September 27, 2024

So net.IP (which stores the ip address as a series of bytes) shows:
net.IP{0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x1}
the code i use to write/serialize it to the connect token buffer:

for i := 0; i < len(parsed); i += 2 {
    var n uint16
    n = binary.BigEndian.Uint16([]byte(parsed[i : i+2]))
        buffer.WriteUint16(n)
}

shows: []byte{0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x1, 0x0}
if i change the binary.BigEndian.Uint16 to binary.LittleEndian.Uint16(...) i get:
[]byte{0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x1}
(Note that buffer.WriteUint16(n) does the following):

b.Buf[b.Pos] = byte(n)
b.Pos++
b.Buf[b.Pos] = byte(n >> 8)
b.Pos++

from netcode.

wirepair avatar wirepair commented on September 27, 2024

So giving this some more thought, I think the reason is completely on my side, since net.IP already stores it in big endian, converting those bytes again to big endian again actually flips it back to being little endian. We can probably close this.

from netcode.

gafferongames avatar gafferongames commented on September 27, 2024

Makes sense. There are similar endian issues in the C API for parsing IP addresses too, it's tricky.

from netcode.

Related Issues (20)

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.