[Csci551-talk] allotting dynamic port to node children
johnh at ISI.EDU
Wed Mar 16 15:44:01 PST 2005
On Sun, 13 Mar 2005 22:06:19 PST, "S. Lugani" wrote:
>My problem is that when I fork multiple clients to a function and try to give them each of them dynamic ports. It does create a port number and assigns them that BUT it assigns the same port number to all the fork children created. Shouldn't it assign a differnt port to each child when i use the socket() function??
>This is the pseudo code:-
>void childnode(int nodeid,int tracker_port)
> node_socket = socket(AF_INET,SOCK_DGRAM,0);
> getsockname(node_socket,(struct sockaddr *)&nodeadd,sizeof(nodeadd));
> printf("myport %d",node_port);
> pid_t pid;
> if(pid == 0)
You have a bug. Think about what is kept the same and what is changed
when you fork().
Hint: print the address you're sending to the kernel just before you
call call the syscall that give is it that address and make sure it's
what you think it should be.
More information about the Csci551-talk