Subject: Bad file descriptor error during CONNECT...what to do?

From: "Jose Melara" <[email-masked]>
Date: Mon, 23 Jul 2001 17:26:24 -0700

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

---

From: "Jose Melara" <[email-masked]>
Date: Tue, 24 Jul 2001 21:29:22 -0700

Thank you for your prompt response and also for helping me on my coding.

I am using: RedHat 7.1 with a kernel version 2.4.3

I have tar'ed the whole directory so that you can just run the program. If
you're using Windows let me know so that I can zip it.
You'll find that there's a lot of debug output because I'm still working
with it.

Thank you ... seriously... your help is greatly appreciated.

Jose Melara

----- Original Message -----
From: "Francis Dupont" <[email-masked]>
To: "Jose Melara" <[email-masked]>
Sent: Tuesday, July 24, 2001 1:41 AM
Subject: Re: Bad file descriptor error during CONNECT...what to do?

> Give the OS/etc and *please* put the close after perror!
>
> [email-masked]
>
> PS: I am afraid that the server6 structure is *not* fully initialized
> (use bzero/memset).