xiluoc un pc pour les unirs .... | ,
On dois faire un petit clien ftp pour jouer avec les sockets en C.
j arrive a me connecter avec le programme suivant. mais LOGIN ne me renvoie aucune reponse j en deduit que rien nas etait envoye.
via telnet
Code :
- pompeii:a1:64 % telnet 127.0.0.1 1034
- Trying 127.0.0.1...
- Connected to 127.0.0.1.
- Escape character is '^]'.
- ACK comp341 server ready
- LOGIN test
- ACK Log in ID OK
- LOGOUT
- ACK SFTP server exit
- Connection to 127.0.0.1 closed by foreign host.
|
mon prog, les message envoye au server doivent se terminet par char(255).
Code :
- # define HOST "pompeii.ics.mq.edu.au"
- # include <sys/types.h>
- # include <sys/socket.h>
- # include <netinet/in.h>
- # include <arpa/inet.h>
- # include <netdb.h>
- # include <stdio.h>
- #include <string.h>
- int main (int argc, char* argv[])
- {
- char c;
- register struct hostent *hp = 0;
- struct sockaddr_in remoteaddr;
- struct servent *sp;
- FILE *send, *receive;
- int sock, port;
- hp = gethostbyname (argv[1]); /* Take it from command line */
- /* Extract the remote address and put it into the structure for socket */
- remoteaddr.sin_family = hp->h_addrtype;
- bcopy (hp->h_addr_list[0], (caddr_t) &remoteaddr.sin_addr, hp->h_length);
- sock = socket (remoteaddr.sin_family, SOCK_STREAM, 0);
- if (sock < 0)
- {
- printf("error connecting to socket of type %s \n", remoteaddr.sin_family);
- exit (1);
- }
- sp = getservbyname ( "comp341","tcp" );
- if (sp == 0)
- {
- exit (1);
- }
- else
- port = sp->s_port;
- remoteaddr.sin_port = port;
- if (comp341_connect (sock, &remoteaddr, sizeof (remoteaddr)) < 0)
- {
- printf("error while calling connect() \n" );
- exit (1);
- }
-
- receive = fdopen (sock, "r" );
- send = fdopen (sock, "w" );
- while ((c = fgetc(receive)) != EOF) {
- putchar(c); }
- printf("\n" );
- int length;
- char *logi="LOGIN s4046342";
- length = strlen(logi);
- logi[length]=(char)0xFF;
- fprintf(send, "%s", logi);
- while ((c = fgetc(receive)) != EOF) {
- putchar(c); }
- printf("\n" );
- }
|
Ou est le problem il y a til de grosses erreurs ? merci pour votre aide Message édité par xiluoc le 08-03-2005 à 11:08:26
|