[C] pb de code sous windows

pb de code sous windows [C] - C++ - Programmation

Marsh Posté le 16-05-2002 à 09:35:17    

bon j essaie de faire marcher un client irc sous windows que j ai code sous bsd, mais bon ca marche pas des masses :
 
#include <stdlib.h>
#include "client.h"
#include <unistd.h>
#include <string.h>
#include <stdio.h>
#include <signal.h>
#include <winsock.h>
 
int   main(int ac, char **av)
{
  struct sockaddr_in sock;
 
  int   fd_sock;
  int  size;
  struct hostent *host;
  fd_set                fd_read;
  char   buf[1024];
 
  if ((fd_sock = socket(AF_INET, SOCK_STREAM, 0)) < 0)
    error("socket" );
  if (!(host = gethostbyname(av[1])))
    error("gethostbyname" );
  sock.sin_family = AF_INET;
  sock.sin_port = htons(atoi(av[2]));
  //bcopy(host->h_addr, &(sock.sin_addr.s_addr), host->h_length);
  size = sizeof (struct sockaddr_in);
  if (-1 == connect(fd_sock, (void *)&sock, size))
    error("connect" );
  MY_WRITE(1, PROMPT);
...
return (0)
}
 
les pb :  
- j ai tjs ca quand je le lance :"socket : no error", et ca termine
 
- y a t il un equivalent a bcopy???
 
voila, merci

Reply

Marsh Posté le 16-05-2002 à 09:35:17   

Reply

Marsh Posté le 16-05-2002 à 09:49:02    

bon j ai deja trouve un debut de reponse : ma fonction error utilise perror, et il fo utiliser WSAGetLastError() (ca marche bien mieux!!)
 
mais le pb now, c est que lorsque j ai le prompt irc, je peux po ecrire, si j ecris et fait Ctrl-C, alors ce que j ai tappe apparait sur le prompt de windows!!
 
que faire, c est un pb de select ca???
 
voila la fin du code :
int main (int ac, char **av)
...
MY_WRITE(1, PROMPT);
  while (1)
    {
      FD_ZERO(&fd_read);
      FD_SET(0, &fd_read);
      FD_SET(fd_sock, &fd_read);
      if (-1 == select(fd_sock + 1, &fd_read, 0, 0, 0))
  WSAGetLastError();
  //error("select" );
      else
 check(&fd_read, fd_sock, buf);
    }
  return (0);
}
 
int loop(int fd_sock)
{
  char buf[1024];
  int lu;
 
  lu = read(0, buf, 1024);
  if (lu > 1)
    write(fd_sock, buf, lu);
  else
    MY_WRITE(1, PROMPT);
  return (0);
}
 
void check(fd_set *fd_read, int fd_sock, char *buf)
{
  if (FD_ISSET(0, fd_read))
    loop(fd_sock);
  if (FD_ISSET(fd_sock, fd_read))
    {
      memset(buf, 0, 1024);
      if (0 > read(fd_sock, buf, 1024))
 {
   printf("%s\n", ENDCON);
   exit(0);
 }
      MY_WRITE(1, buf);
    }
}

Reply

Marsh Posté le 16-05-2002 à 09:53:59    

Mettre du code en brute dans le forum, c pas top.
avec de poster, réfléchis à ton problème, essaye d'identifier ce qui peut poser problème, cherche ds des questions précises à poser. Desfois d'ailleur, rien qu'en faisant ça, on, trouve la réponse !
 :hello:

Reply

Marsh Posté le 16-05-2002 à 09:56:05    

oui, j ai trouve la reponse avec WSAtruc
 
mais la j ai une question precise : pour savoir d ou vienne les infos, je fais un select sur l entree standard et la socket
mais quand j ecris, le prompt est blocke, et Ctrl-C fait apparaitre ce que j ai ecris sur le prompt de windows
 
voila, je vois pas pk, car le code compile tres bien

Reply

Marsh Posté le 16-05-2002 à 09:57:20    

Essaie d'inclure winsock2.h. Je ne sais pas si ca va changer grand chose mais en tout cas c'est ce qui est marque dans la msdn.
Sinon pour bcopy je ne sais pas.

Reply

Marsh Posté le 16-05-2002 à 09:59:27    

nan, que j inclue winsock ou winsock2 c est pareil
 
:cry:

Reply

Marsh Posté le 16-05-2002 à 10:30:31    

bon je viens de faire des tests, et bah la socket est jamais cree, ca me renvoie tjs -1, et la fonction WSAGetLasteError me revoie 10093 comme code d erreur!
 
bon c bien tout ca mais sur msdn, y a pas les codes d erreurs en chiffres!!!!donc je sais pas a quoi correspond cette erreur!!!
 
heeeeeeeeelp:cry:
 
 
quelle merde le codage sous windows quand meme, pfffff

Reply

Marsh Posté le 16-05-2002 à 10:54:25    

up!!!

Reply

Marsh Posté le 16-05-2002 à 14:07:56    

up pleze........

Reply

Sujets relatifs:

Leave a Replay

Make sure you enter the(*)required information where indicate.HTML code is not allowed