Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

Negative port numbers when binding to port 0.

Name: Anonymous 2006-04-11 20:18

In this code fragment from a server program (edited for length):

sendPort = (short) desiredSendPort;
  
sendSock = socket(AF_INET, SOCK_STREAM, 0);

sendAddr.sin_family = AF_INET;
sendAddr.sin_addr.s_addr = INADDR_ANY;
sendAddr.sin_port = sendPort;

bind(sendSock, (struct sockaddr *) &sendAddr, sizeof(sendAddr)));
   
if (sendPort == 0) {
    length = sizeof(sendSock);
    getsockname(sendSock, (struct sockaddr *)&sendAddr, (unsigned int *) &length) < 0)
    sendPort = ntohs(sendAddr.sin_port);
}

When the port number is 0 the system assigns a negative number on the schools server, but a regular >1024 port number on my local Debian system. If you specify a port number it assigns properly on my Debian system but the school server denies permssion. Even if you specify something like 55739 the school server won't give up the port.

When using the program if you specify the negative number returned by the school server all the client programs work fine.

I'm using kernel 2.4.27 and the server is using 2.6.11.

Can anyone tell me possibly why it does this?

Name: Anonymous 2006-05-04 4:11

I had a professor who used this brace style:
function(type arg)
    {
    if(something)
        {
        doStuff();
        }
    else
        {
        dontDoStuff();
        }
    }
Every time he gave out code I had to reformat it before I could even look at it without barfing.

Then again I know a Perl programmer whose boss indents backwards to save space. I won't even try to give an example here, I'll leave it as a thought experiment.

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List