[bittorrent] compact ip problem
bengotow at gmail.com
Wed Aug 22 15:47:09 EDT 2007
You might want to check the endianness of your data. I'm not sure how
java works, so you may have to specifically put your data structure
into big endian mode before setting values.
Also, I can't really tell from your code but it looks like
inetAddress.getAddress() may return a string? You don't actually want
to send the address as a string. You want to save each section of the
IP address as a unsigned 8 bit integer. So if I have the IP address
188.8.131.52, then I would say:
compactIP = (byte)(129)
compactIP = (byte)(59)
compactIP = (byte)(70)
compactIP = (byte)(23)
haha please excuse my syntax. I really don't know Java. But here's
some code I wrote a while ago that decodes a compact response. It may
//create a memoryblock object and fill it with the "peers" section
//of the bencoded data.
mb = NewMemoryBlock(d.value("peers").StringValue.Len+2)
mb.LittleEndian = false
mb.cstring(0) = d.value("peers").StringValue
//step through each set of 6 bytes. IP is first four, port is
for x=0 to mb.size-3 step 6
port = mb.uInt16Value(x+4)
a = peerNewWithProperties(ip,"",port)
Hope that helps,
- Ben Gotow
On Aug 22, 2007, at 3:07 PM, Dazen D wrote:
> Hi. I'm having some problems sending announce responses
> with compact ips on it. Apparently the clients don't
> recognize the compact ip that i'm generating (using java
> code). If i send regular ips and ports, it works fine.
> To generate the four first bytes (IP) i use the code:
> String ip = (...)
> InetAddress inetAddress = InetAddress.getByName(ip);
> byte rawAddress = inetAddress.getAddress();
> For the other two bytes (port):
> compactIP = (byte)(port >> 8);
> compactIP = (byte)(port & 0xff);
> (which is apparently how azureus do that)
> The response that is arriving to the client is:
> where "XXXX" are the IP bytes and "YY" the port bytes.
> I even tried another format for the response, which some trackers use:
> but it was the same.
> Any idea about what could be wrong?
> Thanks a lot.
> BitTorrent mailing list
> BitTorrent at lists.ibiblio.org
More information about the BitTorrent