function connect ipv6

Tesi TLC (G. MazzinI) tesi_tlc@ing240.unife.it
Wed, 17 Mar 1999 18:54:12 +0100 (MET)


  This message is in MIME format.  The first part should be readable text,
  while the remaining parts are likely unreadable without MIME-aware tools.
  Send mail to mime@docserver.cac.washington.edu for more info.

---559023410-851401618-921693252=:20297
Content-Type: TEXT/PLAIN; charset=US-ASCII


Hi !
We are 2 italian students !

We are tried to make a IPv6 application, but when we try to open a connect
in IPv6 addreswe have : 
invalid argument  
Where is the problem ?
The function connect doesn't work good,but the function gethostbyname2
works good 
This is my client v6 in c code :

/* client v6 */
#include <stdio.h>
#include <fcntl.h>
#include <sys/types.h>
#include </usr/inet6/include/sys/types.h>
#include <sys/socket.h>
#include </usr/inet6/include/sys/socket.h>
#include <netinet/in.h>
#include </usr/inet6/include/netinet/in6.h>
#include <netdb.h>
#define DIM_BUFF 256

main (int argc, char *argv[])
{
  int sd, fd, nread, i ;
  char buff[DIM_BUFF] ;
  int fromlen, copiati ;
  struct hostent *host ;    /* ptr a info per host remoto */
  struct sockaddr_in6 rem_indirizzo ; /* per indirizzo socket remota */
if (argc != 3)  {
       printf ("Usage Error: %s nomenodo nomefile\n", argv[0]) ;
       exit (1) ;
}

memset ((char *)&rem_indirizzo, 0, sizeof(struct sockaddr_in6)) ;

/* Preparazione indirizzo remoto a cui connettersi */
rem_indirizzo.sin6_family = AF_INET6 ;
host = gethostbyname2(argv[1],AF_INET6) ;
if (host == NULL)  {
                 printf("%s not found in /etc/hosts\n",argv[1]);
                 exit (2) ;
}
for (i=0; i < 16 ; i++)  {

rem_indirizzo.sin6_addr.s6_addr[i]=((struct in6_addr *)
                                  (host->h_addr))->s6_addr[i] ;
}
rem_indirizzo.sin6_port = 12345 ; /* possibile uso htons() */

sd=socket (AF_INET6, SOCK_STREAM, 0);

printf("ho apero la socket con valore %i\n",sd);

if(connect(sd,(struct sockaddr *) &rem_indirizzo,
                             sizeof(struct sockaddr))<0)  {
           perror("Errore in connect");
           exit (1) ;
}
if (write(sd, argv[2], strlen(argv[2])+1)<0)  {
    perror("write") ;
    exit (1);
}
if ((nread=read(sd,buff,DIM_BUFF))<0) {
    perror("read"); exit(1) ; }
if (buff[0] == 'S' )  {
     if ((fd=open(argv[2], O_RDONLY))<0)  {perror("open") ; exit(1);}

     while ((nread=read(fd, buff, DIM_BUFF))>0)
           write (sd, buff, nread) ;
     close (sd) ;  /* ho spedito il file */
     printf("File spedito\n") ;

}   else
       printf ("Il file %s esiste, termino\n",argv[1]) ;
close (sd) ;
exit(0) ;
}


We attach also serverv6.c !

Questions : where is C code to function 'connect' ? the function 'connect'
has some problems if rem_indirizzo has IPv6 addres ?
We have very small documentation about new structure IPv6.

Could anyone help us ??

UNIVERSITA' DEGLI STUDI DI FERRARA   -ITALY- 
DIPARTIMENTO DI INGEGNERIA

Rovatti Luca         personal email   lucarov@ing58.unife.it      
Villani Giancarlo    personal email   gianca@ing58.unife.it

G&L email   tesi_tlc@ing240.unife.it
     

---559023410-851401618-921693252=:20297
Content-Type: TEXT/PLAIN; charset=US-ASCII; name="serverv6.c"
Content-Transfer-Encoding: BASE64
Content-ID: <Pine.GSO.3.96.990317185412.20297C@ing240.unife.it>
Content-Description: 

I2luY2x1ZGU8c3RkaW8uaD4NCiNpbmNsdWRlPGZjbnRsLmg+DQojaW5jbHVk
ZTxzeXMvdHlwZXMuaD4NCiNpbmNsdWRlPC91c3IvaW5ldDYvaW5jbHVkZS9z
eXMvdHlwZXMuaD4NCiNpbmNsdWRlPHN5cy9zb2NrZXQuaD4NCiNpbmNsdWRl
PC91c3IvaW5ldDYvaW5jbHVkZS9zeXMvc29ja2V0Lmg+DQojaW5jbHVkZTxu
ZXRpbmV0L2luLmg+DQojaW5jbHVkZTwvdXNyL2luZXQ2L2luY2x1ZGUvbmV0
aW5ldC9pbjYuaD4NCiNpbmNsdWRlPG5ldGRiLmg+DQojZGVmaW5lIERJTV9C
VUZGIDI1Ng0KDQptYWluKGludCBhcmdjLCBjaGFyICphcmd2W10pDQp7DQ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PX0NSRUFUfE9f
RVhDTCkpPDApDQogICAgICB7DQogICAgICAgcHJpbnRmKCJGaWxlIGVzaXN0
ZSwgbm9uIGxvIHNvdnJhc2NyaXZvXG4iKTsNCiAgICAgICB3cml0ZShucywi
TiIsMSk7DQogICAgICB9DQogICAgZWxzZQ0KICAgICAgew0KICAgICAgIHBy
aW50ZigiRmlsZSBub24gZXNpc3RlbnRlLCBsbyBjb3BpbyBkYWwgY2xpZW50
XG4iKTsNCiAgICAgICB3cml0ZShucywiUyIsMSk7DQogICAgICAgd2hpbGUo
KG5yZWFkPXJlYWQobnMsIGJ1ZmYsIERJTV9CVUZGKSk+MCkNCiAgICAgICAg
IHsNCiAgICAgICAgICAgd3JpdGUoZmQsYnVmZixucmVhZCk7DQogICAgICAg
ICAgIGNvbnQrPW5yZWFkOw0KICAgICAgICAgfQ0KICAgICAgIHByaW50Zigi
Q29waWEgZXNlZ3VpdGEgZGkgJWQgYnl0ZVxuIiwgY29udCk7DQogICB9DQog
IGNsb3NlKG5zKTsNCn0NCn0NCg==
---559023410-851401618-921693252=:20297--