Ver Mensaje Individual
  #1 (permalink)  
Antiguo 26/04/2014, 23:31
Avatar de Drewermerc
Drewermerc
 
Fecha de Ingreso: febrero-2014
Mensajes: 185
Antigüedad: 10 años, 2 meses
Puntos: 5
error al compilar sockets en c

hola a todo.
buen espeor que me puedan ayudar bueno es que anterior mente ya habia compilado sockets en c en codeblock y en devc++ pero ahora ya no me quiere compilar en codeblocks me sale esto:


Código C:
Ver original
  1. C:\Program Files (x86)\Windows Kits\8.0\Include\shared\basetsd.h||In function 'Ptr32ToPtr':|
  2. C:\Program Files (x86)\Windows Kits\8.0\Include\shared\basetsd.h|299|warning: cast from pointer to integer of different size [-Wpointer-to-int-cast]|
  3. C:\Program Files (x86)\Windows Kits\8.0\Include\shared\basetsd.h||In function 'Handle32ToHandle':|
  4. C:\Program Files (x86)\Windows Kits\8.0\Include\shared\basetsd.h|308|warning: cast from pointer to integer of different size [-Wpointer-to-int-cast]|
  5. C:\Program Files (x86)\Windows Kits\8.0\Include\shared\basetsd.h||In function 'PtrToPtr32':|
  6. C:\Program Files (x86)\Windows Kits\8.0\Include\shared\basetsd.h|317|warning: cast to pointer from integer of different size [-Wint-to-pointer-cast]|
  7. C:\Program Files (x86)\Windows Kits\8.0\Include\um\winnt.h|307|warning: "_cdecl" redefined [enabled by default]|
  8. C:\progc\pruebas\sock.c|1|note: this is the location of the previous definition|
  9. C:\Program Files (x86)\Windows Kits\8.0\Include\um\winnt.h|308|warning: "__cdecl" redefined [enabled by default]|
  10. C:\progc\pruebas\sock.c|1|note: this is the location of the previous definition|
  11. C:\Program Files (x86)\Windows Kits\8.0\Include\um\winuser.h|1086|warning: declaration does not declare anything [enabled by default]|
  12. C:\Program Files (x86)\Windows Kits\8.0\Include\um\winuser.h|12838|warning: declaration does not declare anything [enabled by default]|
  13. C:\Program Files (x86)\Windows Kits\8.0\Include\um\winuser.h|12843|warning: declaration does not declare anything [enabled by default]|
  14. C:\Program Files (x86)\Windows Kits\8.0\Include\um\objidl.h|11066|warning: declaration does not declare anything [enabled by default]|
  15. C:\Program Files (x86)\Windows Kits\8.0\Include\shared\wtypes.h|752|error: pasting "/" and "/" does not give a valid preprocessing token|
  16. C:\Program Files (x86)\Windows Kits\8.0\Include\um\oaidl.h|473|note: in expansion of macro '_VARIANT_BOOL'|
  17. C:\Program Files (x86)\Windows Kits\8.0\Include\shared\wtypes.h|752|error: expected specifier-qualifier-list before '/' token|
  18. C:\Program Files (x86)\Windows Kits\8.0\Include\um\oaidl.h|473|note: in expansion of macro '_VARIANT_BOOL'|
  19. C:\Program Files (x86)\Windows Kits\8.0\Include\shared\wtypes.h|752|error: pasting "/" and "/" does not give a valid preprocessing token|
  20. C:\Program Files (x86)\Windows Kits\8.0\Include\um\oaidl.h|488|note: in expansion of macro '_VARIANT_BOOL'|
  21. C:\Program Files (x86)\Windows Kits\8.0\Include\um\propidl.h|647|error: array type has incomplete element type|
  22. C:\Program Files (x86)\Windows Kits\8.0\Include\um\propidl.h|653|error: array type has incomplete element type|
  23. ||=== Build failed: 5 error(s), 9 warning(s) (0 minute(s), 1 second(s)) ===|

en dev c++ me sale lo siguiente:

Código C:
Ver original
  1. 239 0   C:\mingw completo\mingw\include\windef.h    In file included from C:\mingw completo\mingw\include/windef.h
  2. 60      C:\mingw completo\mingw\include\windows.h                    from C:\mingw completo\mingw\include/windows.h
  3. 22      C:\mingw completo\mingw-mingw-w32api\include\winsock2.h                  from C:\mingw completo\mingw-mingw-w32api\include\winsock2.h
  4. 83      C:\progc\ifdef.c                     from C:\progc\ifdef.c
  5. 2398    2   C:\mingw completo\mingw\include\winnt.h [Error] #error "undefined processor type"
  6. 2401    1   C:\mingw completo\mingw\include\winnt.h [Error] unknown type name 'CONTEXT'
  7. 62  0   C:\mingw completo\mingw\include\windows.h   In file included from C:\mingw completo\mingw\include/windows.h
  8. 22      C:\mingw completo\mingw-mingw-w32api\include\winsock2.h                  from C:\mingw completo\mingw-mingw-w32api\include\winsock2.h
  9. 83      C:\progc\ifdef.c                     from C:\progc\ifdef.c
  10. 1733    1   C:\mingw completo\mingw\include\winbase.h   [Error] unknown type name 'CONTEXT'

mi codigo es este:
Código C:
Ver original
  1. #include <stdio.h>
  2.     #include <stdlib.h>
  3.     #include <winsock2.h>
  4.     #include <windows.h>
  5.  
  6.     #define PORT 3550
  7.     #define BACKLOG 2
  8.  
  9.     main()
  10.     {
  11.     WSADATA wsaData;
  12.       if (WSAStartup(MAKEWORD(2,0), &wsaData) != 0 )
  13.       {
  14.           printf("No se pudo inicar la libreria de sockets");
  15.           return 0;
  16.       }
  17.  
  18.        int fd, fd2;
  19.  
  20.        struct sockaddr_in server;
  21.        struct sockaddr_in client;
  22.        int sin_size;
  23.  
  24.        if ((fd=socket(AF_INET, SOCK_STREAM, 0)) == -1 ) {
  25.           printf("error en socket()\n");
  26.           exit(1);
  27.        }
  28.  
  29.        server.sin_family = AF_INET;
  30.  
  31.        server.sin_port = htons(PORT);
  32.        server.sin_addr.s_addr = INADDR_ANY;
  33.        if(bind(fd,(struct sockaddr*)&server,
  34.                sizeof(struct sockaddr))==-1) {
  35.           printf("error en bind() \n");
  36.           exit(-1);
  37.        }
  38.  
  39.        if(listen(fd,BACKLOG) == -1) {
  40.           printf("error en listen()\n");
  41.           exit(-1);
  42.        }
  43.  
  44.        while(1) {
  45.           sin_size=sizeof(struct sockaddr_in);
  46.  
  47.           if ((fd2 = accept(fd,(struct sockaddr *)&client,
  48.                             &sin_size))==-1) {
  49.              printf("error en accept()\n");
  50.              exit(-1);
  51.           }
  52.  
  53.           printf("Se obtuvo una conexión desde %s\n",
  54.                  inet_ntoa(client.sin_addr) );
  55.  
  56.  
  57.           send(fd2,"Bienvenido a mi servidor.\n",22,0);
  58.  
  59.  
  60.           close(fd2);
  61.        }
  62.     WSACleanup();
  63.     }