06-09-2008, 00:23
Che, estamos teniendo el siguiente problema con el codigo:
Y despues sigue.... alguien sabe porque razon en el bind, SIEMPRE me tira error??? (Y supuestamente tira error 88 "socket operation on non socket")
#include <stdio.h>
#include <string.h>
/*
#include <sys/socket.h>
#include <resolv.h>
*/
#include <sys/types.h>
#include <sys/socket.h>
#include <arpa/inet.h>
#include <netinet/in.h>
#include <stdlib.h>
#include <unistd.h>
#include <errno.h>
#define MI_PUERTO 8080 //esto va en el archivo configuracion
#define BACKLOG 10 //esto va en el archivo configuracion
void mensaje_error(int e){
printf("error!!!, %d\n",e);
return;
}
int main(){
int sockfd; //declaro el descriptor del socket
int addrlen = sizeof(struct sockaddr); //SINO FUNCIONA PROBAR CON sizeof(struct sockaddr_in)
struct sockaddr_in my_addr; // creo la estructura sockaddr_in
//inicializo la estructura sockaddr_in
bzero(&my_addr, sizeof(my_addr));
my_addr.sin_family = AF_INET;
my_addr.sin_port = htons(MI_PUERTO); // Designa numero de puerto por donde escuchara el servidor
my_addr.sin_addr.s_addr = htonl (INADDR_ANY); // IP de la interface por donde escuchara el servidor, en este caso permite IP de cualquier host
struct sockaddr_in client_addr; //DNI del cliente
//si no hay error, creo el socket
if((sockfd = socket(AF_INET, SOCK_STREAM, 0) == -1))
{mensaje_error(0); return 1;}
//si no hay error, pido el puerto
//extern int errno; /*"SI NO FUNCIONA PROBA DESCOMENTAR ESTA LINEA Y BORRAR ESTO"*/
if(bind(sockfd, (struct sockaddr*) &my_addr, sizeof(my_addr))==-1) //otro tutorial me dice q si no es error retorna 0 ¿?
{mensaje_error(1); printf("errno = %d \n",errno); return 1;}
Y despues sigue.... alguien sabe porque razon en el bind, SIEMPRE me tira error??? (Y supuestamente tira error 88 "socket operation on non socket")