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 6:09

>>23
GNU style puts the brace halfway between the block header and the block body, eg:
int main(int argc, char** argv)
  {
    puts("Hello, RMS!");
    return 0;
  }

Which is slightly different from the above. The rational for this is to keep everything that's not a function definition away from the first column, to make it easier for automated tools to find them. To which I say: NO GNU!

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