Hello,
I'm simulating a bunch of routers communicating with each other. I have multiple process running, and each is a child of another process. The great-parent of all the processes is the master process. The master process communicates with the other process with a pair of sockets created from socketpair(2). The other processes themselves are commununicating with each other through sockets created from socketpair(2) as well, but the master process does not know about that. How can the master process create a new pair of sockets through socketpair(2), send it to two processes, and then have those two processes communicate with each other with the two new sockets created? Here's what I have, but it doesn't work:

definition for Link struct:
Code:
typedef struct Link
{
  int link[2];
  int comm_end;
} Link;
some master process code:
Code:
    Link link;
...
    socketpair2(link.link);
    task = 3;
    router = 6;
    write(master_conns[0][MASTER_TO_ROUTER], &task, 4);
    write(master_conns[0][MASTER_TO_ROUTER], &router, 4);
    link.comm_end = 0;
    write(master_conns[0][MASTER_TO_ROUTER], &link, sizeof(link));

    router = 0;
    write(master_conns[6][MASTER_TO_ROUTER], &task, 4);
    write(master_conns[6][MASTER_TO_ROUTER], &router, 4);
    link.comm_end = 1;
    write(master_conns[6][MASTER_TO_ROUTER], &link, sizeof(link));
    distance_vector_routing(master_conns, 7);
    print_routing_table(master_conns, "After adding link between "
                                      "router 0 and 6", 7);
And the code for the sub processes:
Code:
          read(master_conn[ROUTER_TO_MASTER], &task, 4);
...
          switch(task)
          {
            case 3:
              read(master_conn[ROUTER_TO_MASTER], &router, 4);
              read(master_conn[ROUTER_TO_MASTER], &link, sizeof(link));

              for(i = 0; i < 7; i++)
                // shorten distance to router being connected to
                if(my_table[i].destination == router)
                {
                  my_table[i].next_hop = router;
                  my_table[i].hop_count = 1;
                  break;
                }

              links.conns[router] = 1;
              links.links[ links.num_links ].comm_end = link.comm_end;
              memcpy(links.links[ links.num_links ].link, link.link, 8);
              
              FD_SET(link.link[link.comm_end], &master);
              set_max_fd(max_fd, link.link[link.comm_end]);
Thanks,
Yasir