예제 #1
0
int make_listen_bind(uint32 ip, uint16 port)
{
	struct sockaddr_in server_address;
	int fd;
	int result;

	fd = sSocket(AF_INET, SOCK_STREAM, 0);

	if( fd == -1 )
	{
		ShowError("make_listen_bind: criacao de socket falhou (codigo %d)!\n", sErrno);
		exit(EXIT_FAILURE);
	}
	if( fd == 0 )
	{// reserved
		ShowError("make_listen_bind: Socket #0 e reservado - Favor reportar isso!!!\n");
		sClose(fd);
		return -1;
	}
	if( fd >= FD_SETSIZE )
	{// socket number too big
		ShowError("make_listen_bind: Novo socket #%d e maior do que suportamos! aumente o valor de FD_SETSIZE (atualmente %d) para seu SO consertar isso!\n", fd, FD_SETSIZE);
		sClose(fd);
		return -1;
	}

	setsocketopts(fd);
	set_nonblocking(fd, 1);

	server_address.sin_family      = AF_INET;
	server_address.sin_addr.s_addr = htonl(ip);
	server_address.sin_port        = htons(port);

	result = sBind(fd, (struct sockaddr*)&server_address, sizeof(server_address));
	if( result == SOCKET_ERROR ) {
		ShowError("make_listen_bind: vinculacao falhou (socket #%d, codigo %d)!\n", fd, sErrno);
		exit(EXIT_FAILURE);
	}
	result = sListen(fd,5);
	if( result == SOCKET_ERROR ) {
		ShowError("make_listen_bind: listen falhou (socket #%d, codigo %d)!\n", fd, sErrno);
		exit(EXIT_FAILURE);
	}

	if(fd_max <= fd) fd_max = fd + 1;
	sFD_SET(fd, &readfds);

	create_session(fd, connect_client, null_send, null_parse);
	session[fd]->client_addr = 0; // just listens
	session[fd]->rdata_tick = 0; // disable timeouts on this socket

	return fd;
}
예제 #2
0
파일: socket.c 프로젝트: anacondaqq/ra_cpp
int make_listen_bind(uint32 ip, uint16 port)
{
    struct sockaddr_in server_address;
    int fd;
    int result;

    fd = sSocket(AF_INET, SOCK_STREAM, 0);

    if( fd == -1 )
    {
        ShowError("make_listen_bind: socket creation failed (%s)!\n", error_msg());
        exit(EXIT_FAILURE);
    }
    if( fd == 0 )
    {   // reserved
        ShowError("make_listen_bind: Socket #0 is reserved - Please report this!!!\n");
        sClose(fd);
        return -1;
    }
    if( fd >= FD_SETSIZE )
    {   // socket number too big
        ShowError("make_listen_bind: New socket #%d is greater than can we handle! Increase the value of FD_SETSIZE (currently %d) for your OS to fix this!\n", fd, FD_SETSIZE);
        sClose(fd);
        return -1;
    }

    setsocketopts(fd,0);
    set_nonblocking(fd, 1);

    server_address.sin_family      = AF_INET;
    server_address.sin_addr.s_addr = htonl(ip);
    server_address.sin_port        = htons(port);

    result = sBind(fd, (struct sockaddr*)&server_address, sizeof(server_address));
    if( result == SOCKET_ERROR ) {
        ShowError("make_listen_bind: bind failed (socket #%d, %s)!\n", fd, error_msg());
        exit(EXIT_FAILURE);
    }
    result = sListen(fd,5);
    if( result == SOCKET_ERROR ) {
        ShowError("make_listen_bind: listen failed (socket #%d, %s)!\n", fd, error_msg());
        exit(EXIT_FAILURE);
    }

    if(fd_max <= fd) fd_max = fd + 1;
    sFD_SET(fd, &readfds);

    create_session(fd, connect_client, null_send, null_parse);
    session[fd]->client_addr = 0; // just listens
    session[fd]->rdata_tick = 0; // disable timeouts on this socket

    return fd;
}
예제 #3
0
파일: socket.c 프로젝트: Chocolate31/eamod
int make_listen_bind(uint32 ip, uint16 port)
{
	struct sockaddr_in server_address;
	int fd;
	int result;

	fd = sSocket(AF_INET, SOCK_STREAM, 0);

	if(fd == -1) {
		ShowError(read_message("Source.common.make_listen_bind"), error_msg());
		exit(EXIT_FAILURE);
	}
	if(fd == 0) {
		// reserved
		ShowError(read_message("Source.common.make_listen_bind2"));
		sClose(fd);
		return -1;
	}
	if(fd >= FD_SETSIZE) {
		// socket number too big
		ShowError(read_message("Source.common.make_listen_bind3"), fd, FD_SETSIZE);
		sClose(fd);
		return -1;
	}

	setsocketopts(fd);
	set_nonblocking(fd, 1);

	server_address.sin_family      = AF_INET;
	server_address.sin_addr.s_addr = htonl(ip);
	server_address.sin_port        = htons(port);

	result = sBind(fd, (struct sockaddr *)&server_address, sizeof(server_address));
	if(result == SOCKET_ERROR) {
		ShowError(read_message("Source.common.make_listen_bind4"), fd, error_msg());
		exit(EXIT_FAILURE);
	}
	result = sListen(fd,5);
	if(result == SOCKET_ERROR) {
		ShowError(read_message("Source.common.make_listen_bind5"), fd, error_msg());
		exit(EXIT_FAILURE);
	}

	if(fd_max <= fd) fd_max = fd + 1;
	sFD_SET(fd, &readfds);

	create_session(fd, connect_client, null_send, null_parse);
	session[fd]->client_addr = 0; // just listens
	session[fd]->rdata_tick = 0; // disable timeouts on this socket

	return fd;
}
예제 #4
0
파일: socket.c 프로젝트: Gubio/brAthena
int make_listen_bind(uint32 ip, uint16 port)
{
	struct sockaddr_in server_address = { 0 };
	int fd;
	int result;

	fd = sSocket(AF_INET, SOCK_STREAM, 0);

	if( fd == -1 ) {
		ShowError("make_listen_bind: Criacao de socket falhou (%s)!\n", error_msg());
		exit(EXIT_FAILURE);
	}
	if( fd == 0 ) { // reserved
		ShowError("make_listen_bind: Socket #0 esta reservado - Por favor reporte isso!!!\n");
		sClose(fd);
		return -1;
	}
	if( fd >= FD_SETSIZE ) { // socket number too big
		ShowError("make_listen_bind: Novo socket #%d e maior do que o limite suportado! Aumentando o valor para FD_SETSIZE (atualmente %d) seu SO deve corrigir isso!\n", fd, FD_SETSIZE);
		sClose(fd);
		return -1;
	}

	setsocketopts(fd,NULL);
	set_nonblocking(fd, 1);

	server_address.sin_family      = AF_INET;
	server_address.sin_addr.s_addr = htonl(ip);
	server_address.sin_port        = htons(port);

	result = sBind(fd, (struct sockaddr*)&server_address, sizeof(server_address));
	if( result == SOCKET_ERROR ) {
		ShowError("make_listen_bind: socket-bind falhou (socket #%d, %s)!\n", fd, error_msg());
		exit(EXIT_FAILURE);
	}
	result = sListen(fd,5);
	if( result == SOCKET_ERROR ) {
		ShowError("make_listen_bind: socket-listen falhou (socket #%d, %s)!\n", fd, error_msg());
		exit(EXIT_FAILURE);
	}

	if(sockt->fd_max <= fd) sockt->fd_max = fd + 1;
	sFD_SET(fd, &readfds);

	create_session(fd, connect_client, null_send, null_parse);
	session[fd]->client_addr = 0; // just listens
	session[fd]->rdata_tick = 0; // disable timeouts on this socket

	return fd;
}