Net2: question

Halo,

I am investigating SDL_Net and I am using the
excellent Net2 library by Bob Pendleton. Note that
Net2 is a thin layer around SDL_net and does not perform
any swaping.

But I think it should do.

The problem:------------
I am calling
NET2_UDPAcceptOn(int port) which calls
SDLNet_UDP_Open(int port)
which accepts native byte order integer. So far so good.

Now when I am receiving UDP packets on this port, the
source port number is swapped. OK. let’s just accept
that. This is the network.

Now when I am trying to send using

NET2_UDPSend(IPaddress *ip, char *buf, int len) which calls
SDLNet_UDP_Send(requires UDPpacket)
the ip->port member must be jammed again – unlike the other uses
of IPaddresses

I believe since NET2_UDPSend requires an IPaddress it should
be noted with very big letters in the documentation.
Or
better hide the swap inside NET2_UDPSend and during the receipt
of the UDPpacket.

.bill

Hi!

2006/9/8, Vassilis Virvilis :

Halo,

I am investigating SDL_Net and I am using the
excellent Net2 library by Bob Pendleton. Note that
Net2 is a thin layer around SDL_net and does not perform
any swaping.

But I think it should do.

The problem:

I am calling
NET2_UDPAcceptOn(int port) which calls
SDLNet_UDP_Open(int port)
which accepts native byte order integer. So far so good.

Now when I am receiving UDP packets on this port, the
source port number is swapped. OK. let’s just accept
that. This is the network.

Now when I am trying to send using

NET2_UDPSend(IPaddress *ip, char *buf, int len) which calls
SDLNet_UDP_Send(requires UDPpacket)
the ip->port member must be jammed again – unlike the other uses
of IPaddresses

I believe since NET2_UDPSend requires an IPaddress it should
be noted with very big letters in the documentation.
Or
better hide the swap inside NET2_UDPSend and during the receipt
of the UDPpacket.

BTW, will SDL_net be improved in SDL 1.3?–
Roman Kyrylych (??? ???)

Halo,

I am investigating SDL_Net and I am using the
excellent Net2 library by Bob Pendleton. Note that
Net2 is a thin layer around SDL_net and does not perform
any swaping.

But I think it should do.

The problem:

I am calling
NET2_UDPAcceptOn(int port) which calls
SDLNet_UDP_Open(int port)
which accepts native byte order integer. So far so good.

Now when I am receiving UDP packets on this port, the
source port number is swapped. OK. let’s just accept
that. This is the network.

Now when I am trying to send using

NET2_UDPSend(IPaddress *ip, char *buf, int len) which calls
SDLNet_UDP_Send(requires UDPpacket)
the ip->port member must be jammed again – unlike the other uses
of IPaddresses

I believe since NET2_UDPSend requires an IPaddress it should
be noted with very big letters in the documentation.
Or
better hide the swap inside NET2_UDPSend and during the receipt
of the UDPpacket.

.bill

Hi, what kind of machine are you working on that you are having trouble
with the byte order of ip address and port numbers? These are values
that are passed through to the OS and received back from the OS, not
values that go over the wire. That means there is no worry about network
ordering of that data. If there were a problem, you would never be able
to connect or send data.

BTW, it is best to send these kinds of questions directly to the
developer. I sometimes go weeks without looking at the SDL list, but I
rarely go more than a few days without looking at my personal email. And
even when I do read the SDL mailing list I can’t guarantee to see every
message sent to me.

	Bob PendletonOn Fri, 2006-09-08 at 11:19 +0300, Vassilis Virvilis wrote:

SDL mailing list
SDL at libsdl.org
http://www.libsdl.org/mailman/listinfo/sdl


±-------------------------------------+

Bob Pendleton wrote:

Hi, what kind of machine are you working on that you are having trouble
with the byte order of ip address and port numbers? These are values
that are passed through to the OS and received back from the OS, not
values that go over the wire. That means there is no worry about network
ordering of that data. If there were a problem, you would never be able
to connect or send data.

Standard PC (athlon).

I don’t have a problem of connecting. I am connecting to the wrong port.
If I want to transmit UDP data to some host at port 8899 it will send
the data to port 49954.

What’s my use case;

IPaddress ip = {some_precomputed_host, port};
NET2_UDPSend(&ip, data, data_size);

This code works for the TCP case. Oups! just checked. In my TCP
case I either use the NET2_ResolveHost that calls SDLNet_ResolveHost
that byteswaps the port, or I am using accept directly which takes
native order port by documentation.

Ok I was wrong. But Eitherway it’s a bit confusing. Accept takes native
order integers but NET2_UDPSend requires a network order integer, but
I suppose this is a problem of SDLNet and not of Net2.

Sorry for the noise.

BTW, it is best to send these kinds of questions directly to the
developer. I sometimes go weeks without looking at the SDL list, but I
rarely go more than a few days without looking at my personal email. And
even when I do read the SDL mailing list I can’t guarantee to see every
message sent to me.

Ok next time I will bother you personally :slight_smile:

.bill

Whenever the API accepts an IPaddress, it assumes that you’ve already
converted it to network (big endian) byte order. This normally isn’t
a problem since that’s what the hostname resolution functions return,
but if you fill in your own address, you need to make sure the port
is in big endian byte order.

See ya,
-Sam Lantinga, Senior Software Engineer, Blizzard Entertainment