rem: if (getsockname(fd, (struct sockaddr *)in, &addrlen) == -1) {
add: if (ACE_OS::getsockname(fd, (struct sockaddr *)in, &addrlen) == -1) {
context: int ComGetConnPair(int *ctr_fd, int *data_fd, int *max_pkt_size){  int i;  int fd, fdType = -1;  int addrlen;  struct sockaddr_in peeraddr_in;  struct fd_set read_mask;  struct timeval tval;  int nfds;    fd = 0;  addrlen = get_sec();  for (i = 0; i < size; i ++) {    if (fdTable[i].fd == -1) {      fd ++;    }    else if (fdTable[i].type == STATE_PENDING &&                     get_duration(fdTable[i].stime, addrlen) > 10) {      fprintf(stderr,              "ComGetConnPair: pid %ld closed fd %d (PENDING >= 10 sec)\n",             ACE_OS::getpid (), fdTable[i].fd);      ComCloseConn(fdTable[i].fd);      fdTable[i].fd = -1;      fd ++;    }  }  if (fd < 2) {    fprintf(stderr,            "Error ComGetConnPair: pid %ld no faTable entry for the pair",           ACE_OS::getpid ());    return -1;  }    FD_ZERO(&read_mask);  if (fd_inet >= 0) FD_SET(fd_inet, &read_mask);  if (fd_unix >= 0) FD_SET(fd_unix, &read_mask);  if (fd_atm  >= 0) FD_SET(fd_atm,  &read_mask);  tval.tv_sec = 1;   /* wait at most 1 second */  tval.tv_usec = 0;  nfds = fd_inet;  if (fd_unix > nfds) nfds = fd_unix;  if (fd_atm > nfds) nfds = fd_atm;  // nfds now holds the highest numbered open file descriptor  nfds ++; // increment so that select can use o to nfds -1 no. of           // file descriptors.  errno = 0;  // fd is here used as the result of the select call#ifdef _HPUX_SOURCE  if ((fd = select(nfds, (int *)&read_mask, NULL, NULL, &tval)) == -1)#else  if ((fd = select(nfds, &read_mask, NULL, NULL, &tval)) == -1)#endif  {        if (errno == EINTR) return -1;        fprintf(stderr,            "Error ComGetConnPair: pid %ld failed on select():",           ACE_OS::getpid ());   ACE_OS::perror ("");    return -1;  }  if (fd == 0) return -1; /* time expire */  fd = -1;  // fd will be reused inside this code as the accepted socket.  if (fd == -1 && fd_unix >= 0 && FD_ISSET(fd_unix, &read_mask)) {    struct sockaddr_un peeraddr_un;        fprintf(stderr, "Server to accept a UNIX connection.\n");        addrlen = sizeof(struct sockaddr_un);    fd = accept(fd_unix, (struct sockaddr *)&peeraddr_un, &addrlen);    if (fd == -1) {      fprintf(stderr,              "Error ComGetConnPair: pid %ld failed to accpet on fd_unix:",             ACE_OS::getpid ());     ACE_OS::perror ("");    }    else fdType = CONN_UNIX;    *max_pkt_size = 0;  }  // fd here is the result of the  accept for unix if fd_unix is valid  // Hence if fd_unix is present then this won't be called if the  // accept for the fd_unix succeeds.  if (fd == -1 && fd_inet >= 0 && FD_ISSET(fd_inet, &read_mask)) {        fprintf(stderr, "Server to accept a INET connection.\n");        addrlen = sizeof(struct sockaddr_in);    fd = accept(fd_inet, (struct sockaddr *)&peeraddr_in, &addrlen);    if (fd == -1) {      fprintf(stderr,              "Error ComGetConnPair: pid %ld failed to accpet on fd_inet:",             ACE_OS::getpid ());     ACE_OS::perror ("");    }    else fdType = CONN_INET;    *max_pkt_size = 0;  }  if (fd == -1 && fd_atm >= 0 && FD_ISSET(fd_atm, &read_mask)) {#ifdef NATIVE_ATM    fd = ATMaccept(fd_atm, max_pkt_size);    fdType = CONN_ATM;#else    fprintf(stderr,            "Error ComGetConnPair: pid %ld CONN_ATM not supported.\n",           ACE_OS::getpid ());#endif  }  // fd = -1 implies accept failed in any of the active connections  // which came out of the select call.  if (fd == -1) return -1;  for (i = 0; i < size; i ++) {    if (fdTable[i].fd == -1) break;  }  // Enter the accepted fd in the file descriptor Table  if (i < size) {    fdTable[i].fd = fd;    fdTable[i].type = fdType;    fdTable[i].stime = get_sec();  }  else {    fprintf(stderr, "Weird\n");  }  // read the port number for the UDP socket of the client  if (time_read_int(fd, &nfds) == -1) {    fprintf(stderr,            "Error ComGetConnPair: pid %ld failed to read int from %s fd:",           ACE_OS::getpid (),            fdType == CONN_ATM ? "ATM" :            fdType == CONN_INET ? "INET" : "UNIX");   ACE_OS::perror ("");    ComCloseConn(fd);    return -1;  }  fprintf (stderr,           " Received int nfds = %d \n",           nfds);  // nfds holds the int read in time_read_int  // if nfds is -1 then read int error.  fprintf(stderr, "ComGetConnPair got %s fd = %d with value %d\n",          fdType == CONN_ATM ? "ATM" :          fdType == CONN_INET ? "INET" : "UNIX",          fd, nfds);  if (nfds >= 0) { /* can be paired and return */    // This is the success case where you got a control fd and a data fd.    fdTable[i].state = STATE_DATA;    for (i = 0; i < size; i ++) {      if (fdTable[i].fd == nfds) break;    }    if (i < size && fdTable[i].state == STATE_PENDING) {      fdTable[i].state = STATE_CONTROL;    }    else {      if (i >= 0) fprintf(stderr, "<Weird> i %d\n", i);      ComCloseConn(fd);      return -1;    }    // ????    *ctr_fd = fdTable[i].fd;    *data_fd = fd;    return 0;  }  else if (nfds == -1) { /* wait to be paired */    fdTable[i].state = STATE_PENDING;    // fd is the inet or unix accepted socket.    // why is anyone writing the fd to the peer?    // looks like he is indicating an error to the client!!    // is this a hack ;-(    if (time_write_int(fd, fd) == -1) {      fprintf(stderr,              "Error ComGetConnPair: pid %ld failed to write (fd) to %s fd:",             ACE_OS::getpid (),              fdType == CONN_ATM ? "ATM" :              fdType == CONN_INET ? "INET" : "UNIX");     ACE_OS::perror ("");      ComCloseConn(fd);      return -1;    }    if (fdType == CONN_INET && change_option(fd) == -1) {      ComCloseConn(fd);    }    return -1;  }  else if (nfds == -2) {  /* inet case only, UDP data sock is requested */    int dfd;    struct sockaddr_in * in = &(peeraddr_in);        fdTable[i].state = STATE_CONTROL;    if (fdType == CONN_INET && change_option(fd) == -1) {      fprintf(stderr,              "Error ComGetConnPair: pid %ld failed to change options of TCP cfd:",             ACE_OS::getpid ());      ComCloseConn(fd);      return -1;    }        dfd = socket(AF_INET, SOCK_DGRAM, 0);    if (dfd == -1) {      fprintf(stderr,          "Error ComGetConnPair: pid %ld failed to open dfd:",         ACE_OS::getpid ());     ACE_OS::perror ("");      ComCloseConn(fd);      return -1;    }    memset((char *)in, 0, sizeof(* in));        addrlen = sizeof(*in);    if (getsockname(fd, (struct sockaddr *)in, &addrlen) == -1) {      fprintf(stderr,          "Error ComGetConnPair: pid %ld failed to getsockname of fd:",         ACE_OS::getpid ());     ACE_OS::perror ("");      ComCloseConn(fd);      ACE_OS::close (dfd);      return -1;    }        in->sin_family = AF_INET;    in->sin_port = 0;    /*    in->sin_addr.s_addr = htonl(INADDR_ANY);    */    if (bind(dfd, (struct sockaddr *)in, sizeof(* in)) == -1) {      fprintf(stderr,          "Error ComGetConnPair: pid %ld failed to bind dfd:",         ACE_OS::getpid ());     ACE_OS::perror ("");      ComCloseConn(fd);      ACE_OS::close (dfd);      return -1;    }    addrlen = sizeof(*in);    if (getsockname(dfd, (struct sockaddr *)in, &addrlen) == -1) {      fprintf(stderr,          "Error ComGetConnPair: pid %ld failed to getsockname of dfd:",         ACE_OS::getpid ());     ACE_OS::perror ("");      ComCloseConn(fd);      ACE_OS::close (dfd);      return -1;    }    if (time_write_bytes(fd, (char *)&in->sin_port, sizeof(short)) == -1) {      fprintf(stderr,          "Error ComGetConnPair: pid %ld failed to write (dfd.port) to fd:",         ACE_OS::getpid ());     ACE_OS::perror ("");      ComCloseConn(fd);      ACE_OS::close (dfd);      return -1;    }    /*    addrlen = sizeof(*in);    if (getsockname(fd, (struct sockaddr *)in, &addrlen) == -1) {      fprintf(stderr,          "Error ComGetConnPair: pid %ld failed to getsockname of fd:",         ACE_OS::getpid ());     ACE_OS::perror ("");      ComCloseConn(fd);      ACE_OS::close (dfd);      return -1;    }    */    if (time_write_bytes(fd, (char *)&in->sin_addr.s_addr, sizeof(int)) == -1) {      fprintf(stderr,          "Error ComGetConnPair: pid %ld failed to write (dfd.IPaddr) to fd:",         ACE_OS::getpid ());     ACE_OS::perror ("");      ComCloseConn(fd);      ACE_OS::close (dfd);      return -1;    }    fprintf(stderr, "ComGetConnPair local UDP socket: addr - %s, port - %u.\n",            inet_ntoa(in->sin_addr), ntohs(in->sin_port));    if (time_read_bytes(fd, (char *)&in->sin_port, sizeof(short)) == -1 ||        time_read_bytes(fd, (char *)&in->sin_addr.s_addr, sizeof(int)) == -1) {      fprintf(stderr,          "Error ComGetConnPair: pid %ld failed to read (port, IPaddr) from fd:",         ACE_OS::getpid ());     ACE_OS::perror ("");      ComCloseConn(fd);      ACE_OS::close (dfd);      return -1;    }    usleep(10000);    if (connect(dfd, (struct sockaddr *)in, sizeof(*in)) == -1) {      fprintf(stderr,              "Error ComGetConnPair: pid %ld failed conn UDP dfd to peer:",             ACE_OS::getpid ());     ACE_OS::perror ("");      ComCloseConn(fd);      ACE_OS::close (dfd);      return -1;    }#if 0    {      int len;      len = 65536; /* INET_SOCKET_BUFFER_SIZE + 100; */      /*      if (setsockopt(dfd, SOL_SOCKET, SO_SNDBUF, (char *)&len, sizeof(len)) == -1) {        fprintf(stderr,                "Error ComGetConnPair: pid %ld failed to set UDP dfd-snd to size %d:",                ACE_OS::getpid (), len);        perror("");        ComCloseConn(fd);        close(dfd);        return -1;      }      */      len = 65536;      while (setsockopt(dfd, SOL_SOCKET, SO_RCVBUF, (char *)&len, sizeof(len)) == -1) {        len -= 1024;        if (len < 8192) break;        /*        fprintf(stderr,                "Warning ComGetConnPair: pid %ld failed to set UDP dfd-rcv to size %d:",                ACE_OS::getpid (), len);        perror("");        ComCloseConn(fd);        close(dfd);        return -1;        */      }      if (getuid() == DEVELOPER_UID)      fprintf(stderr,"Set UDP dfd-rcv to %dB\n", len);    }#endif    // Most common return case where the server creates a UDP socket ,    // writes the port and ip addr and also gets the client's UDP    // endpoint .    *max_pkt_size = - INET_SOCKET_BUFFER_SIZE;  /* UDP sockets on HP and SUN                                                are known to be discard mode */    fprintf(stderr, "ComGetConnPair UDP dfd connects to host-%s (port %u)\n",            inet_ntoa(in->sin_addr), ntohs(in->sin_port));    for (i = 0; i < size; i ++) {      if (fdTable[i].fd == -1) break;    }    if (i < size) {      fdTable[i].fd = dfd;      fdTable[i].type = CONN_INET;      fdTable[i].stime = get_sec();      fdTable[i].state = STATE_DATA;      *ctr_fd = fd;      *data_fd = dfd;      return 0;    }    else {      fprintf(stderr, "ComGetConnPair <Weird>: no space left\n");      return -1;    }  }  else {    fprintf(stderr,            "Error ComGetConnPair: pid %ld get invalid value %d from fd\n",           ACE_OS::getpid (), nfds);    ComCloseConn(fd);  }  return -1;}