Hi! I am learning how to use IPv6 and I am working on a simple Ipv6 client/server application. My problem is that after I do a connect on the client side I am getting a Bad File Descriptor error. 
 
Here's how the application works: 1) the server decides on the port. 2) The client takes the name of the server and the port number assigned by the server as arguments (argv[s]) and should stablish a connection.
 
Here is my code for the client, I'd appreciate your help on telling me what could be going wrong.
 
Thank you very much for your time, I greatly appreciate it.
 
Jose Melara (student)
 
/* --------------------------------------------------------------
*
* tcp6_send_setup() function
*
* --------------------------------------------------------------*/
int32_t tcp6_send_setup(char * host_name, char * port)
{
  int32_t server_socket= -1;
  int32_t i_connect = -1; /* for testing purposes */ 
  char *int_port;
  struct sockaddr_in6 server6; /* socket address for the server */
  struct hostent *hostinfo; /* address of server */
  char *addr_pptr;
 
/* create the socket */
server_socket = socket(PF_INET6, SOCK_STREAM,0);
cout << "server_socket: " << server_socket << endl;
 
/* designate the addressing family */
server6.sin6_family = AF_INET6;
server6.sin6_addr = in6addr_any; //wildcard
server6.sin6_flowinfo = 0;
 
// ALLOCATE MEMORY -- I took this out to save you time...
 
/* Get server info */
hostinfo = gethostbyname2(host_name, AF_INET6);
 
/* copy to server6 structure */
 
memcpy((char *)server6.sin6_addr.s6_addr,(char *)hostinfo->h_addr_list[0], INET6_ADDRLEN);
 
/* get the port used on the remote side and store */
 
server6.sin6_port = atoi(port);
 
if (i_connect = connect(server_socket, (struct sockaddr *)&server6, sizeof(INET6_ADDRLEN)) < 0)
{
  close (server_socket);
  cout << "ERROR connecting stream socket ERROR#" << i_connect << endl; 
  perror("");
  exit(1);
}
  return (server_socket);
 
}//end function

Reply via email to