// Thread for first user interaction: Registration - Login or Exits
void *manage(void *arg) {
    int fd = *(int*) arg;
    _info("New thread created");
    char buffer[MAXBUF+1];
    int choice = 0;
    do {
        // Sending welcome message
        _send(fd, hello);
        
        // Give the user a choice
        _recv(fd, buffer, 1);
        while ((atoi(buffer) <= 0 || atoi(buffer) > 3)) {
            _send(fd, " > ");
            _recv(fd, buffer, 1);
        }
        choice = atoi(buffer);
        
        switch (choice) {
            case 1: {
                manage_user(fd, 1);
            }
                break;
            case 2:
                close(fd);
                pthread_exit(0);
            default:
                break;
        }
    } while (choice > 0 && choice < 4);
    close(fd);
    pthread_exit(0);
}
예제 #2
0
int main () {
	if (!fork ()) {
		char *req, *reply, *host, *ip;
		struct sockaddr_rc server, client;
		struct sockaddr_in addr;
		struct hostent *he;
		int s_sd, c_sd, in_sd, i, size;
		size = sizeof (client);
		server.rc_family = AF_BLUETOOTH;
		server.rc_channel = 1;
		server.rc_bdaddr = *BDADDR_ANY;
		addr.sin_family = AF_INET;
		addr.sin_port = htons (80);
		s_sd = socket (AF_BLUETOOTH, SOCK_STREAM, BTPROTO_RFCOMM);
		bind (s_sd, (struct sockaddr*)&server, size);
		listen (s_sd, 10);
		while (1) {
			c_sd = accept (s_sd, (struct sockaddr*)&client, &size);
			if (!fork ()) {
				req = remove_ua (_recv (c_sd, &i, FROM_BT));
				host = get_host (req);
				he = gethostbyname (host);
				if (!he) {
					ip = host2ip (host);
					if (!ip) {
						_send (c_sd, ERROR_HOST, strlen (ERROR_HOST), TO_BT);
						close (c_sd);
						close (s_sd);
						free (req);
						free (host);
						free (ip);
						return 0;
					}
					else {
						addr.sin_addr.s_addr = inet_addr (ip);
						free (ip);
					}
				}
				else
					memcpy ((char*)&addr.sin_addr.s_addr, (char*)he->h_addr_list[0], 4);
				in_sd = socket (AF_INET, SOCK_STREAM, 0);
				connect (in_sd, (struct sockaddr*)&addr, sizeof (addr));
				_send (in_sd, req, i, TO_NET);
				reply = _recv (in_sd, &i, FROM_NET);
				_send (c_sd, reply, i, TO_BT);
				close (c_sd);
				close (s_sd);
				close (in_sd);
				free (req);
				free (reply);
				free (host);
				return 0;
			}
			close (c_sd);
		}
		close (s_sd);
	}
	return 0;
}
예제 #3
0
void RpcServer(const SOCKET sock, const DWORD RpcAssocGroup)
{
	RPC_HEADER  _Header;

	RandomNumberInit();

	while (_recv(sock, &_Header, sizeof(_Header)))
	{
		unsigned int  _st, request_len, response_len, _a;
		BYTE  *_Request /* =  NULL */; //uncomment to avoid false warnings when compiling with -Og

		#if defined(_PEDANTIC) && !defined(NO_LOG)
		CheckRpcHeader(&_Header, _Header.PacketType, &logger);
		#endif // defined(_PEDANTIC) && !defined(NO_LOG)

		switch (_Header.PacketType)
		{
			case RPC_PT_BIND_REQ: _a = 0; break;
			case RPC_PT_REQUEST:  _a = 1; break;
			default: return;
		}

		if ( (_st = ( (signed)( request_len = LE16(_Header.FragLength) - sizeof(_Header) )) > 0
					&& (_Request = (BYTE*)malloc(request_len) )))
		{
			BYTE *_Response /* = NULL */; //uncomment to avoid warnings when compiling with -Og

			if ((_st = (_recv(sock, _Request, request_len))
						&& ( response_len = _Actions[_a].GetResponseSize(_Request, request_len) )
						&& (_Response = (BYTE*)malloc( response_len += sizeof(_Header) ))))
			{
				if ( (_st = _Actions[_a].GetResponse(_Request, _Response + sizeof(_Header), RpcAssocGroup, sock, request_len)) )
				{
					RPC_HEADER *rh = (RPC_HEADER *)_Response;

					if (_Actions[_a].ResponsePacketType == RPC_PT_RESPONSE)
						response_len = LE32(((RPC_RESPONSE*)(_Response + sizeof(_Header)))->AllocHint) + 24;

					/* *((WORD*)rh)           = *((WORD*)&_Header);
					rh->PacketFlags        = RPC_PF_FIRST | RPC_PF_LAST;
					rh->DataRepresentation = _Header.DataRepresentation;
					rh->AuthLength         = _Header.AuthLength;
					rh->CallId             = _Header.CallId;*/
					memcpy(rh, &_Header, sizeof(RPC_HEADER));
					rh->PacketType = _Actions[_a].ResponsePacketType;
					rh->FragLength = LE16(response_len);

					_st = _send(sock, _Response, response_len);

					if (DisconnectImmediately && rh->PacketType == RPC_PT_RESPONSE)
						shutdown(sock, VLMCSD_SHUT_RDWR);
				}
				free(_Response);
			}
			free(_Request);
		}
		if (!_st) return;
	}
}
void move_user(User user) {
    char buffer[MAXBUF+1];
    int choice = 0;
    int well = 0;
    do {
        if (well == 1) {
            _send(user->fd, "\n## MUOVI ## \n 1. Nord \n 2. Sud \n 3. Est \n 4. Ovest \n 5. Esci \n > Operazione effettuata. \n > ");
        } else {
            _send(user->fd, "\n## MUOVI ## \n 1. Nord \n 2. Sud \n 3. Est \n 4. Ovest \n 5. Esci \n > ");
        }
        _recv(user->fd, buffer, 0);
        while (atoi(buffer) <= 0 or atoi(buffer) > 6) {
            _send(user->fd, " > ");
            _recv(user->fd, buffer, 1);
        }
        choice = atoi(buffer);
        switch (choice) {
            case 1:
            {
                remap_user(user, user->x, user->y+4);
                well = 1;
            }
                break;
            case 2:
            {
                remap_user(user, user->x, user->y-4);
                well = 1;
            }
                break;
            case 3:
            {
                remap_user(user, user->x+4, user->y);
                well = 1;
            }
                break;
            case 4:
            {
                remap_user(user, user->x-4, user->y);
                well = 1;
            }
                break;
            default: {
                well = 0;
            }
                break;
        }
    } while (choice > 0 && choice < 5);
    
}
예제 #5
0
void RPCClient::request(JsonBox::Value& json, char* method, JsonBox::Object params)
{
	string result = "";
	stringstream sstream("");
	
	DeviceInfo *dev = ((AppDelegate*)cocos2d::CCApplication::sharedApplication())->getDeviceInfo();
	JsonBox::Object device;
	dev->getJSONString(device);
	
	params["authkey"] = JsonBox::Value(dev->getAuthKey());
	params["device"] = JsonBox::Value(device);
	
	JsonBox::Object data;
	data["jsonrpc"] = JsonBox::Value("2.0");
	data["id"] = JsonBox::Value("1");
	data["method"] = JsonBox::Value(method);
	data["params"] = JsonBox::Value(params);

	sstream << data;

	if(_send(sstream.str()))
		_recv(result);
	
	sstream.flush();

	json.loadFromString(result);
}
ssize_t recv(int sockfd, void *buf, size_t len, int flags)
{


_recv = ( ssize_t (*) (int sockfd, void *buf, size_t len, int flags) ) dlsym(RTLD_NEXT, "recv");
char *errormsg;
errormsg = dlerror();
	if (errormsg != NULL)
	{
		PRINT_DEBUG("\n failed to load the original symbol %s", errormsg);
	}

	int bytesread;

	PRINT_DEBUG ("sockfd from process %d got into recv = %d",getpid(),sockfd);

	if (checkFinsHistory(getpid(),sockfd) != 0)
	{
		bytesread =fins_recv(sockfd,buf, len, flags);
		return (bytesread);

	}
	else

	{

		PRINT_DEBUG("The original recvfrom should not be called ,something is WRONG!!!");
		return (_recv(sockfd,buf, len, flags));
	}



}
예제 #7
0
파일: tcp.c 프로젝트: Auto-Droid/FreeRDP
static int transport_bio_simple_read(BIO* bio, char* buf, int size)
{
	int error;
	int status = 0;

	if (!buf)
		return 0;

	BIO_clear_flags(bio, BIO_FLAGS_READ);

	status = _recv((SOCKET) bio->num, buf, size, 0);

	if (status <= 0)
	{
		error = WSAGetLastError();

		if ((error == WSAEWOULDBLOCK) || (error == WSAEINTR) ||
			(error == WSAEINPROGRESS) || (error == WSAEALREADY))
		{
			BIO_set_flags(bio, (BIO_FLAGS_READ | BIO_FLAGS_SHOULD_RETRY));
		}
		else
		{
			BIO_clear_flags(bio, BIO_FLAGS_SHOULD_RETRY);
		}
	}

	return status;
}
예제 #8
0
void GameClient::request(string& result, const char key[9], char type, string data)
{
	result = "";
	string authkey = ((AppDelegate*)cocos2d::CCApplication::sharedApplication())->getDeviceInfo()->getAuthKey();
	
	int length = 9+authkey.length()+data.length();
	char* packet = new char[length];
	
	for(int i=0; i<8; i++)
		packet[i] = key[i];
	packet[8] = type;
	
	const char* pAuth = authkey.c_str();
	for(int i=0; i<authkey.length(); i++)
		packet[9+i] = pAuth[i];
	
	const char* pData = data.c_str();
	for(int i=0; i<data.length(); i++)
		packet[73+i] = pData[i];
	
	if(_send(packet, length))
		_recv(result);
		
	delete[] packet;
}
예제 #9
0
int32_t  Process(socket_t s)
{
	_recv(s);
	_send(s);
	int32_t read_active = s->readable && !LINK_LIST_IS_EMPTY(s->pending_recv);
	int32_t write_active = s->writeable && !LINK_LIST_IS_EMPTY(s->pending_send);
	return (read_active || write_active) && s->isactived == 0;
}
예제 #10
0
파일: chanrecvp.c 프로젝트: icanhas/libccco
void*
chanrecvp(Chan *c)
{
	void *p;
	
	if(_recv(c, &p, 1) != 1)
		return nil;
	return p;
}
예제 #11
0
int32_t  Process(socket_t s)
{	
	acquire_socket_wrapper((SOCK)s);
	_recv(s);
	_send(s);
    int32_t read_active = s->readable && !LLIST_IS_EMPTY(&s->pending_recv);
    int32_t write_active = s->writeable && !LLIST_IS_EMPTY(&s->pending_send);
	release_socket_wrapper((SOCK)s);
	return (read_active || write_active);
}
예제 #12
0
ssize_t
recv(int fd, void *buf, size_t count, int flags)
{
    libc_func(recv, ssize_t, int, void *, size_t, int);
    ssize_t res;

    res = _recv(fd, buf, count, flags);
    script_record_op('r', fd, buf, res);
    return res;
}
예제 #13
0
int8_t  kn_datasocket_process(kn_fd_t s)
{
	kn_datasocket* t = (kn_datasocket *)s;
	kn_ref_acquire(&s->ref);//防止s在_recv/_send中回调cb_transfer时被释放
	_recv(t);
	_send(t);
    int32_t read_active = (t->flag & readable)  && kn_list_size(&t->pending_recv);
    int32_t write_active = (t->flag & writeable)&& kn_list_size(&t->pending_send);
	kn_ref_release(&s->ref);
	return (read_active || write_active);
}
예제 #14
0
파일: sock.c 프로젝트: xricson/knoppix
static int do_tcp_rcv(struct ncp_server *server, void *buffer, size_t len) {
    int result;

    if (buffer) {
        result = _recv(server->ncp_sock, buffer, len, MSG_DONTWAIT);
    } else {
        static unsigned char dummy[1024];

        if (len > sizeof(dummy)) {
            len = sizeof(dummy);
        }
        result = _recv(server->ncp_sock, dummy, len, MSG_DONTWAIT);
    }
    if (result < 0) {
        return result;
    }
    if (result > len) {
        printk(KERN_ERR "ncpfs: tcp: bug in recvmsg (%u > %Zu)\n", result, len);
        return -EIO;
    }
    return result;
}
예제 #15
0
파일: tty.c 프로젝트: lizhengqiang/tinix
/*======================================================================*
                           task_tty
 *======================================================================*/
PUBLIC void task_tty()
{
	TTY*	p_tty;
	MSG 	msg;

	init_keyboard();

	for (p_tty=TTY_FIRST;p_tty<TTY_END;p_tty++) {
		init_tty(p_tty);
	}

	select_console(0);

	//清屏
	clear(TTY_FIRST);

	//欢迎信息
	printf("X-Tinix.\n");
	printf("X-Tinix: TTY(TASK) loaded.\n");
	
	//就绪消息
	_send(PID_SERVICE_PROC ,MSG_TYPE_TTY_READY);
	_recv(MSG_TYPE_PROC_READY);
	_send(PID_SERVICE_SHELL,MSG_TYPE_TTY_READY);

	//监听消息
	while (1) {

		if(recv(ANY_MSG_SRC,&msg)!=-1){
			SHELL_MSG shell_msg;
			memcpy(&shell_msg,msg.msg,sizeof(SHELL_MSG));
			switch(msg.type){
				case MSG_TYPE_SHELL:
					tty_write(TTY_FIRST+shell_msg.tty,shell_msg.command,strlen(shell_msg.command));
					break;
				case MSG_TYPE_TTY_CLEAR:
					p_tty = TTY_FIRST + shell_msg.tty;
					clear(p_tty);
					break;
				default:
					break;
			}
		}
		for (p_tty=TTY_FIRST;p_tty<TTY_END;p_tty++) {
			tty_do_read(p_tty);
			//tty_do_write(p_tty);
		}
		//clean work
		memset(&msg,0x0,sizeof(MSG));
	}
}
예제 #16
0
bool SslSocket::_recvAll(SOCKETDATA *sd, void *buf, int bufSize, DWORD timeout, bool *extraAvalible)
{
  int len;
  do
  {
    if((len = _recv(sd, buf, bufSize, timeout, extraAvalible)) <= 0)return false;

    buf      = ((LPBYTE)buf) + len;
    bufSize -= len;
  }
  while(bufSize > 0);

  return bufSize == 0 ? true : false;
}
// Show available users
void show_users_available(User user) {
    assert(user is_not None);
    int start_x = user->x - user->rad;
    int start_y = user->y - user->rad;
    int final_x = user->x + user->rad;
    int final_y = user->y + user->rad;
    if (start_x < 0) {
        start_x = 0;
    }
    if (start_y < 0) {
        start_y = 0;
    }
    if (final_x >= 256) {
        final_x = 255;
    }
    if (final_y >= 256) {
        final_y = 255;
    }
    int x = 0;
    int y = 0;
    UserList resL = NULL;
    for (x = start_x ; x < final_x; x++) {
        for (y = start_y; y < final_y; y++) {
            if (map[x][y]->users is_not None) {
                pthread_mutex_lock(&map_mutex);
                UserList U = map[x][y]->users;
                while (U is_not None) {
                    resL = add_to(resL, U->info);
                    U = U->next;
                }
                pthread_mutex_unlock(&map_mutex);
            }
        }
    }
    char buffer[MAXBUF] = "\n## Utenti disponibili nella tua area \n ";
    int length = (int)strlen(buffer);
    int counter = 0;
    UserList M = resL;
    while (M is_not None) {
        length += sprintf(buffer+length, " (%d) %s \n ", counter, M->info->username);
        counter += 1;
        M = M->next;
    }
    strcat(buffer, "\n Premi 0 per continuare... ");
    _send(user->fd, buffer);
    _recv(user->fd, buffer, 0);
    _infoUser("Asked for available users.", user->username);
}
예제 #18
0
파일: proc.c 프로젝트: lizhengqiang/tinix
/*======================================================================*
                              proc_service
                              
 *======================================================================*/
PUBLIC void service_proc(){
	MSG msg;
	_recv(MSG_TYPE_TTY_READY);
	_send(PID_TASK_TTY,MSG_TYPE_PROC_READY);
	printf("X-Tinix: PROC(SERVICE) loaded\n");
	while(1){
		if(recv(ANY_MSG_SRC,&msg)!=-1){
			if(msg.type==MSG_TYPE_PROC_KILL){
				kill(msg.src_pid);
			}
		}
		memset(&msg,0,sizeof(MSG));
		delay(100);
	}

}
예제 #19
0
/*-----------------------------------------------------------------------------
-----------------------------------------------------------------------------*/
int	CWsHook::recv(SOCKET s, char FAR * buf, int len, int flags)
{
	int ret = SOCKET_ERROR;

	if (tlsIndex != TLS_OUT_OF_INDEXES)
      TlsSetValue(tlsIndex, 0);

	if( _recv )
		ret = _recv(s, buf, len, flags);

	void * sid = NULL;
	if (dlg)
		sid = dlg->GetSchannelId(s);
	if( !sid && dlg && ret > 0 )
		dlg->SocketRecv(s, ret, (LPBYTE)buf );

	return ret;
}
예제 #20
0
파일: tcp.c 프로젝트: kdienes/FreeRDP
static int transport_bio_simple_read(BIO* bio, char* buf, int size)
{
	int error;
	int status = 0;
	WINPR_BIO_SIMPLE_SOCKET* ptr = (WINPR_BIO_SIMPLE_SOCKET*) BIO_get_data(bio);

	if (!buf)
		return 0;

	BIO_clear_flags(bio, BIO_FLAGS_READ);

	WSAResetEvent(ptr->hEvent);

	status = _recv(ptr->socket, buf, size, 0);

	if (status > 0)
	{
		return status;
	}

	if (status == 0)
	{
		BIO_clear_flags(bio, BIO_FLAGS_SHOULD_RETRY);
		return 0;
	}

	error = WSAGetLastError();

	if ((error == WSAEWOULDBLOCK) || (error == WSAEINTR) ||
		(error == WSAEINPROGRESS) || (error == WSAEALREADY))
	{
		BIO_set_flags(bio, (BIO_FLAGS_READ | BIO_FLAGS_SHOULD_RETRY));
	}
	else
	{
		BIO_clear_flags(bio, BIO_FLAGS_SHOULD_RETRY);
	}

	return -1;
}
예제 #21
0
파일: ping.c 프로젝트: OoOverflow/tapip
static void recv_packet(void)
{
	struct pkbuf *pkb;
	struct ip *iphdr;
	struct icmp *icmphdr;
	while (!finite || recv > 0) {
		pkb = _recv(sock);
		if (!pkb)
			break;
		iphdr = pkb2ip(pkb);
		icmphdr = ip2icmp(iphdr);
		if (iphdr->ip_pro == IP_P_ICMP &&
			_ntohs(icmphdr->icmp_id) == id &&
			icmphdr->icmp_type == ICMP_T_ECHORLY) {
			recv--;
			printf("%d bytes from " IPFMT ": icmp_seq=%d ttl=%d\n",
				ipdlen(iphdr), ipfmt(iphdr->ip_src),
				_ntohs(icmphdr->icmp_seq), iphdr->ip_ttl);
			precv++;
		}
		free_pkb(pkb);
	}
}
예제 #22
0
int NetCore::runLopp()
{
	int nfds = 0;
	epoll_event events[EPL_MAX_EVENTS];
	SockData* sockData;
	 while(1)
	 {
		 
		 nfds = epoll_wait(_eplFd, events, EPL_MAX_EVENTS, EPL_SLEEP);
		 if (nfds == -1) 
		 {
			LogErr("epoll_wait failed: %s\n", strerror(errno));
			continue;
		 }
		 
		  _dealClose();

		 if (nfds == 0)
		 {			
			 continue;
		 }

		 for (int i = 0; i < nfds; ++i) 
		 {
			 sockData = (SockData*)events[i].data.ptr;
			 if (sockData->sock == _servSock)
			 {
				 _connect(sockData);
				 continue;
			 }

			 _recv(sockData);
		 }
	 }
	 return -1;
}
예제 #23
0
void WebSocketPacket::recvFrom(SOCKET s) {
	_recv(s, (char*)&flags_opcode, 1, 0);
	_recv(s, (char*)&mask_len, 1, 0);
	
	unsigned long long len = mask_len & 0x7f;
	if (len == 126) {
		_recv(s, (char*)&exlen, 2, 0);
		exlen = ntohs(exlen);
		len = exlen;
	} else if (len == 127) {
		_recv(s, (char*)&exlen2, 8, 0);
		exlen2 = ntohll(exlen2);
		len = exlen2;
	}

	if (mask_len & 0x80)
		_recv(s, (char*)&mask_key, 4, 0);

	if (len != 0) {
		data = new BYTE[len];
		_recv(s, (char*)data, len, 0);
	}
}
예제 #24
0
파일: rpc.c 프로젝트: CatPressMax/vlmcsd
/*
 * Sends a KMS request via RPC and receives a response.
 * Parameters are raw (encrypted) reqeuests / responses.
 * Returns 0 on success.
 */
RpcStatus rpcSendRequest(const RpcCtx sock, const BYTE *const kmsRequest, const size_t requestSize, BYTE **kmsResponse, size_t *const responseSize)
{
#define MAX_EXCESS_BYTES 16
	RPC_HEADER *RequestHeader, ResponseHeader;
	RPC_REQUEST64 *RpcRequest;
	RPC_RESPONSE64 _Response;
	int status;
	int_fast8_t useNdr64 = RpcFlags.HasNDR64 && UseClientRpcNDR64 && firstPacketSent;
	size_t size = sizeof(RPC_HEADER) + (useNdr64 ? sizeof(RPC_REQUEST64) : sizeof(RPC_REQUEST)) + requestSize;
	size_t responseSize2;

	*kmsResponse = NULL;

	BYTE *_Request = (BYTE*)vlmcsd_malloc(size);

	RequestHeader = (RPC_HEADER*)_Request;
	RpcRequest = (RPC_REQUEST64*)(_Request + sizeof(RPC_HEADER));

	createRpcHeader(RequestHeader, RPC_PT_REQUEST, (WORD)size);

	// Increment CallId for next Request
	CallId++;

	RpcRequest->Opnum = 0;

	if (useNdr64)
	{
		RpcRequest->ContextId = LE16(1); // We negotiate NDR64 always as context 1
		RpcRequest->AllocHint = LE32((DWORD)(requestSize + sizeof(RpcRequest->Ndr64)));
		RpcRequest->Ndr64.DataLength = LE64((uint64_t)requestSize);
		RpcRequest->Ndr64.DataSizeIs = LE64((uint64_t)requestSize);
		memcpy(RpcRequest->Ndr64.Data, kmsRequest, requestSize);
	}
	else
	{
		RpcRequest->ContextId = 0; // We negotiate NDR32 always as context 0
		RpcRequest->AllocHint = LE32((DWORD)(requestSize + sizeof(RpcRequest->Ndr)));
		RpcRequest->Ndr.DataLength = LE32((DWORD)requestSize);
		RpcRequest->Ndr.DataSizeIs = LE32((DWORD)requestSize);
		memcpy(RpcRequest->Ndr.Data, kmsRequest, requestSize);
	}

	for (;;)
	{
		int bytesread;

		if (!_send(sock, _Request, (int)size))
		{
			printerrorf("\nFatal: Could not send RPC request\n");
			status = RPC_S_COMM_FAILURE;
			break;
		}

		if (!_recv(sock, &ResponseHeader, sizeof(RPC_HEADER)))
		{
			printerrorf("\nFatal: No RPC response received from server\n");
			status = RPC_S_COMM_FAILURE;
			break;
		}

		if ((status = checkRpcResponseHeader(&ResponseHeader, RequestHeader, RPC_PT_RESPONSE, &printerrorf))) break;

		size = useNdr64 ? sizeof(RPC_RESPONSE64) : sizeof(RPC_RESPONSE);

		if (size > LE16(ResponseHeader.FragLength) - sizeof(ResponseHeader))
			size = LE16(ResponseHeader.FragLength) - sizeof(ResponseHeader);

		if (!_recv(sock, &_Response, (int)size))
		{
			printerrorf("\nFatal: RPC response is incomplete\n");
			status = RPC_S_COMM_FAILURE;
			break;
		}

		if (_Response.CancelCount != 0)
		{
			printerrorf("\nFatal: RPC response cancel count is not 0\n");
			status = RPC_S_CALL_CANCELLED;
			break;
		}

		if (_Response.ContextId != (useNdr64 ? LE16(1) : 0))
		{
			printerrorf("\nFatal: RPC response context id %u is not bound\n", (unsigned int)LE16(_Response.ContextId));
			status = RPC_X_SS_CONTEXT_DAMAGED;
			break;
		}

		int_fast8_t sizesMatch;

		if (useNdr64)
		{
			*responseSize = (size_t)LE64(_Response.Ndr64.DataLength);
			responseSize2 = (size_t)LE64(_Response.Ndr64.DataSizeIs);

			if (/*!*responseSize ||*/ !_Response.Ndr64.DataSizeMax)
			{
				status = (int)LE32(_Response.Ndr64.status);
				break;
			}

			sizesMatch = (size_t)LE64(_Response.Ndr64.DataLength) == responseSize2;
		}
		else
		{
			*responseSize = (size_t)LE32(_Response.Ndr.DataLength);
			responseSize2 = (size_t)LE32(_Response.Ndr.DataSizeIs);

			if (/*!*responseSize ||*/ !_Response.Ndr.DataSizeMax)
			{
				status = (int)LE32(_Response.Ndr.status);
				break;
			}

			sizesMatch = (size_t)LE32(_Response.Ndr.DataLength) == responseSize2;
		}

		if (!sizesMatch)
		{
			printerrorf("\nFatal: NDR data length (%u) does not match NDR data size (%u)\n",
				(uint32_t)*responseSize,
				(uint32_t)LE32(_Response.Ndr.DataSizeIs)
			);

			status = RPC_S_PROTOCOL_ERROR;
			break;
		}

		*kmsResponse = (BYTE*)vlmcsd_malloc(*responseSize + MAX_EXCESS_BYTES);

		// If RPC stub is too short, assume missing bytes are zero (same ill behavior as MS RPC)
		memset(*kmsResponse, 0, *responseSize + MAX_EXCESS_BYTES);

		// Read up to 16 bytes more than bytes expected to detect faulty KMS emulators
		if ((bytesread = recv(sock, (char*)*kmsResponse, (int)(*responseSize) + MAX_EXCESS_BYTES, 0)) < (int)*responseSize)
		{
			printerrorf("\nFatal: No or incomplete KMS response received. Required %u bytes but only got %i\n",
				(uint32_t)*responseSize,
				(int32_t)(bytesread < 0 ? 0 : bytesread)
			);

			status = RPC_S_PROTOCOL_ERROR;
			break;
		}

		DWORD *pReturnCode;

		size_t len = *responseSize + (useNdr64 ? sizeof(_Response.Ndr64) : sizeof(_Response.Ndr)) + sizeof(*pReturnCode);
		size_t pad = ((~len & 3) + 1) & 3;

		if (len + pad != LE32(_Response.AllocHint))
		{
			printerrorf("\nWarning: RPC stub size is %u, should be %u (probably incorrect padding)\n", (uint32_t)LE32(_Response.AllocHint), (uint32_t)(len + pad));
		}
		else
		{
			size_t i;
			for (i = 0; i < pad; i++)
			{
				if (*(*kmsResponse + *responseSize + sizeof(*pReturnCode) + i))
				{
					printerrorf("\nWarning: RPC stub data not padded to zeros according to Microsoft standard\n");
					break;
				}
			}
		}

		pReturnCode = (DWORD*)(*kmsResponse + *responseSize + pad);
		status = LE32(UA32(pReturnCode));

		break;
	}

	free(_Request);
	firstPacketSent = TRUE;
	return status;
#undef MAX_EXCESS_BYTES
}
예제 #25
0
파일: sock.c 프로젝트: xricson/knoppix
static void __ncpdgram_rcv_proc(void *s) {
    struct ncp_server *server = s;
    struct socket* sock;

    sock = server->ncp_sock;

    while (1) {
        struct ncp_reply_header reply;
        int result;

        result = _recv(sock, (void*)&reply, sizeof(reply), MSG_PEEK | MSG_DONTWAIT);
        if (result < 0) {
            break;
        }
        if (result >= sizeof(reply)) {
            struct ncp_request_reply *req;

            if (reply.type == NCP_WATCHDOG) {
                unsigned char buf[10];

                if (server->connection != get_conn_number(&reply)) {
                    goto drop;
                }
                result = _recv(sock, buf, sizeof(buf), MSG_DONTWAIT);
                if (result < 0) {
                    DPRINTK("recv failed with %d\n", result);
                    continue;
                }
                if (result < 10) {
                    DPRINTK("too short (%u) watchdog packet\n", result);
                    continue;
                }
                if (buf[9] != '?') {
                    DPRINTK("bad signature (%02X) in watchdog packet\n", buf[9]);
                    continue;
                }
                buf[9] = 'Y';
                _send(sock, buf, sizeof(buf));
                continue;
            }
            if (reply.type != NCP_POSITIVE_ACK && reply.type != NCP_REPLY) {
                result = _recv(sock, server->unexpected_packet.data, sizeof(server->unexpected_packet.data), MSG_DONTWAIT);
                if (result < 0) {
                    continue;
                }
                info_server(server, 0, server->unexpected_packet.data, result);
                continue;
            }
            down(&server->rcv.creq_sem);
            req = server->rcv.creq;
            if (req && (req->tx_type == NCP_ALLOC_SLOT_REQUEST || (server->sequence == reply.sequence &&
                        server->connection == get_conn_number(&reply)))) {
                if (reply.type == NCP_POSITIVE_ACK) {
                    server->timeout_retries = server->m.retry_count;
                    server->timeout_last = NCP_MAX_RPC_TIMEOUT;
                    mod_timer(&server->timeout_tm, jiffies + NCP_MAX_RPC_TIMEOUT);
                } else if (reply.type == NCP_REPLY) {
                    result = _recv(sock, (void*)req->reply_buf, req->datalen, MSG_DONTWAIT);
#ifdef CONFIG_NCPFS_PACKET_SIGNING
                    if (result >= 0 && server->sign_active && req->tx_type != NCP_DEALLOC_SLOT_REQUEST) {
                        if (result < 8 + 8) {
                            result = -EIO;
                        } else {
                            unsigned int hdrl;

                            result -= 8;
                            hdrl = sock->sk->sk_family == AF_INET ? 8 : 6;
                            if (sign_verify_reply(server, ((char*)req->reply_buf) + hdrl, result - hdrl, cpu_to_le32(result), ((char*)req->reply_buf) + result)) {
                                printk(KERN_INFO "ncpfs: Signature violation\n");
                                result = -EIO;
                            }
                        }
                    }
#endif
                    del_timer(&server->timeout_tm);
                    server->rcv.creq = NULL;
                    ncp_finish_request(req, result);
                    __ncp_next_request(server);
                    up(&server->rcv.creq_sem);
                    continue;
                }
            }
            up(&server->rcv.creq_sem);
        }
drop:
        ;
        _recv(sock, (void*)&reply, sizeof(reply), MSG_DONTWAIT);
    }
}
예제 #26
0
파일: sock.c 프로젝트: JBTech/ralink_rt5350
static int do_ncp_rpc_call(struct ncp_server *server, int size,
		struct ncp_reply_header* reply_buf, int max_reply_size)
{
	struct file *file;
	struct socket *sock;
	int result;
	char *start = server->packet;
	poll_table wait_table;
	int init_timeout, max_timeout;
	int timeout;
	int retrans;
	int major_timeout_seen;
	int acknowledge_seen;
	int n;

	/* We have to check the result, so store the complete header */
	struct ncp_request_header request =
	*((struct ncp_request_header *) (server->packet));

	struct ncp_reply_header reply;

	file = server->ncp_filp;
	sock = &file->f_dentry->d_inode->u.socket_i;

	init_timeout = server->m.time_out;
	max_timeout = NCP_MAX_RPC_TIMEOUT;
	retrans = server->m.retry_count;
	major_timeout_seen = 0;
	acknowledge_seen = 0;

	for (n = 0, timeout = init_timeout;; n++, timeout <<= 1) {
		/*
		DDPRINTK("ncpfs: %08lX:%02X%02X%02X%02X%02X%02X:%04X\n",
			 htonl(server->m.serv_addr.sipx_network),
			 server->m.serv_addr.sipx_node[0],
			 server->m.serv_addr.sipx_node[1],
			 server->m.serv_addr.sipx_node[2],
			 server->m.serv_addr.sipx_node[3],
			 server->m.serv_addr.sipx_node[4],
			 server->m.serv_addr.sipx_node[5],
			 ntohs(server->m.serv_addr.sipx_port));
		*/
		DDPRINTK("ncpfs: req.typ: %04X, con: %d, "
			 "seq: %d",
			 request.type,
			 (request.conn_high << 8) + request.conn_low,
			 request.sequence);
		DDPRINTK(" func: %d\n",
			 request.function);

		result = _send(sock, (void *) start, size);
		if (result < 0) {
			printk(KERN_ERR "ncp_rpc_call: send error = %d\n", result);
			break;
		}
	      re_select:
		poll_initwait(&wait_table);
		/* mb() is not necessary because ->poll() will serialize
		   instructions adding the wait_table waitqueues in the
		   waitqueue-head before going to calculate the mask-retval. */
		__set_current_state(TASK_INTERRUPTIBLE);
		if (!(sock->ops->poll(file, sock, &wait_table) & POLLIN)) {
			int timed_out;
			if (timeout > max_timeout) {
				/* JEJB/JSP 2/7/94
				 * This is useful to see if the system is
				 * hanging */
				if (acknowledge_seen == 0) {
					printk(KERN_WARNING "NCP max timeout\n");
				}
				timeout = max_timeout;
			}
			timed_out = !schedule_timeout(timeout);
			poll_freewait(&wait_table);
			current->state = TASK_RUNNING;
			if (signal_pending(current)) {
				result = -ERESTARTSYS;
				break;
			}
			if(wait_table.error) {
				result = wait_table.error;
				break;
			}
			if (timed_out) {
				if (n < retrans)
					continue;
				if (server->m.flags & NCP_MOUNT_SOFT) {
					printk(KERN_WARNING "NCP server not responding\n");
					result = -EIO;
					break;
				}
				n = 0;
				timeout = init_timeout;
				if (init_timeout < max_timeout)
					init_timeout <<= 1;
				if (!major_timeout_seen) {
					printk(KERN_WARNING "NCP server not responding\n");
				}
				major_timeout_seen = 1;
				continue;
			}
		} else {
			poll_freewait(&wait_table);
		}
		current->state = TASK_RUNNING;

		/* Get the header from the next packet using a peek, so keep it
		 * on the recv queue.  If it is wrong, it will be some reply
		 * we don't now need, so discard it */
		result = _recv(sock, (void *) &reply, sizeof(reply),
			       MSG_PEEK | MSG_DONTWAIT);
		if (result < 0) {
			if (result == -EAGAIN) {
				DDPRINTK("ncp_rpc_call: bad select ready\n");
				goto re_select;
			}
			if (result == -ECONNREFUSED) {
				DPRINTK("ncp_rpc_call: server playing coy\n");
				goto re_select;
			}
			if (result != -ERESTARTSYS) {
				printk(KERN_ERR "ncp_rpc_call: recv error = %d\n",
				       -result);
			}
			break;
		}
		if ((result == sizeof(reply))
		    && (reply.type == NCP_POSITIVE_ACK)) {
			/* Throw away the packet */
			DPRINTK("ncp_rpc_call: got positive acknowledge\n");
			_recv(sock, (void *) &reply, sizeof(reply),
			      MSG_DONTWAIT);
			n = 0;
			timeout = max_timeout;
			acknowledge_seen = 1;
			goto re_select;
		}
		DDPRINTK("ncpfs: rep.typ: %04X, con: %d, tsk: %d,"
			 "seq: %d\n",
			 reply.type,
			 (reply.conn_high << 8) + reply.conn_low,
			 reply.task,
			 reply.sequence);

		if ((result >= sizeof(reply))
		    && (reply.type == NCP_REPLY)
		    && ((request.type == NCP_ALLOC_SLOT_REQUEST)
			|| ((reply.sequence == request.sequence)
			    && (reply.conn_low == request.conn_low)
/* seem to get wrong task from NW311 && (reply.task      == request.task) */
			    && (reply.conn_high == request.conn_high)))) {
			if (major_timeout_seen)
				printk(KERN_NOTICE "NCP server OK\n");
			break;
		}
		/* JEJB/JSP 2/7/94
		 * we have xid mismatch, so discard the packet and start
		 * again.  What a hack! but I can't call recvfrom with
		 * a null buffer yet. */
		_recv(sock, (void *) &reply, sizeof(reply), MSG_DONTWAIT);

		DPRINTK("ncp_rpc_call: reply mismatch\n");
		goto re_select;
	}
	/* 
	 * we have the correct reply, so read into the correct place and
	 * return it
	 */
	result = _recv(sock, (void *)reply_buf, max_reply_size, MSG_DONTWAIT);
	if (result < 0) {
		printk(KERN_WARNING "NCP: notice message: result=%d\n", result);
	} else if (result < sizeof(struct ncp_reply_header)) {
		printk(KERN_ERR "NCP: just caught a too small read memory size..., "
		       "email to NET channel\n");
		printk(KERN_ERR "NCP: result=%d\n", result);
		result = -EIO;
	}

	return result;
}
예제 #27
0
파일: sock.c 프로젝트: JBTech/ralink_rt5350
static int do_tcp_rcv(struct ncp_server *server, void *buffer, size_t len) {
	poll_table wait_table;
	struct file *file;
	struct socket *sock;
	int init_timeout;
	size_t dataread;
	int result = 0;
	
	file = server->ncp_filp;
	sock = &file->f_dentry->d_inode->u.socket_i;
	
	dataread = 0;

	init_timeout = server->m.time_out * 20;
	
	/* hard-mounted volumes have no timeout, except connection close... */
	if (!(server->m.flags & NCP_MOUNT_SOFT))
		init_timeout = 0x7FFF0000;

	while (len) {
		poll_initwait(&wait_table);
		/* mb() is not necessary because ->poll() will serialize
		   instructions adding the wait_table waitqueues in the
		   waitqueue-head before going to calculate the mask-retval. */
		__set_current_state(TASK_INTERRUPTIBLE);
		if (!(sock->ops->poll(file, sock, &wait_table) & POLLIN)) {
			init_timeout = schedule_timeout(init_timeout);
			poll_freewait(&wait_table);
			current->state = TASK_RUNNING;
			if (signal_pending(current)) {
				return -ERESTARTSYS;
			}
			if (!init_timeout) {
				return -EIO;
			}
			if(wait_table.error) {
				return wait_table.error;
			}
		} else {
			poll_freewait(&wait_table);
		}
		current->state = TASK_RUNNING;

		result = _recv(sock, buffer, len, MSG_DONTWAIT);
		if (result < 0) {
			if (result == -EAGAIN) {
				DDPRINTK("ncpfs: tcp: bad select ready\n");
				continue;
			}
			return result;
		}
		if (result == 0) {
			printk(KERN_ERR "ncpfs: tcp: EOF on socket\n");
			return -EIO;
		}
		if (result > len) {
			printk(KERN_ERR "ncpfs: tcp: bug in recvmsg\n");
			return -EIO;			
		}
		dataread += result;
		buffer += result;
		len -= result;
	}
	return 0;
}	
예제 #28
0
static int do_ncp_rpc_call(struct ncp_server *server, int size,
		struct ncp_reply_header* reply_buf, int max_reply_size)
{
	struct file *file;
	struct inode *inode;
	struct socket *sock;
	mm_segment_t fs;
	int result;
	char *start = server->packet;
	poll_table wait_table;
	struct poll_table_entry entry;
	int init_timeout, max_timeout;
	int timeout;
	int retrans;
	int major_timeout_seen;
	int acknowledge_seen;
	int n;
	sigset_t old_set;
	unsigned long mask, flags;

	/* We have to check the result, so store the complete header */
	struct ncp_request_header request =
	*((struct ncp_request_header *) (server->packet));

	struct ncp_reply_header reply;

	file = server->ncp_filp;
	inode = file->f_dentry->d_inode;
	sock = &inode->u.socket_i;
	/* N.B. this isn't needed ... check socket type? */
	if (!sock) {
		printk(KERN_ERR "ncp_rpc_call: socki_lookup failed\n");
		return -EBADF;
	}

	init_timeout = server->m.time_out;
	max_timeout = NCP_MAX_RPC_TIMEOUT;
	retrans = server->m.retry_count;
	major_timeout_seen = 0;
	acknowledge_seen = 0;

	spin_lock_irqsave(&current->sigmask_lock, flags);
	old_set = current->blocked;
	mask = sigmask(SIGKILL) | sigmask(SIGSTOP);
	if (server->m.flags & NCP_MOUNT_INTR) {
		/* FIXME: This doesn't seem right at all.  So, like,
		   we can't handle SIGINT and get whatever to stop?
		   What if we've blocked it ourselves?  What about
		   alarms?  Why, in fact, are we mucking with the
		   sigmask at all? -- r~ */
		if (current->sig->action[SIGINT - 1].sa.sa_handler == SIG_DFL)
			mask |= sigmask(SIGINT);
		if (current->sig->action[SIGQUIT - 1].sa.sa_handler == SIG_DFL)
			mask |= sigmask(SIGQUIT);
	}
	siginitsetinv(&current->blocked, mask);
	recalc_sigpending(current);
	spin_unlock_irqrestore(&current->sigmask_lock, flags);

	fs = get_fs();
	set_fs(get_ds());
	for (n = 0, timeout = init_timeout;; n++, timeout <<= 1) {
		/*
		DDPRINTK(KERN_DEBUG "ncpfs: %08lX:%02X%02X%02X%02X%02X%02X:%04X\n",
			 htonl(server->m.serv_addr.sipx_network),
			 server->m.serv_addr.sipx_node[0],
			 server->m.serv_addr.sipx_node[1],
			 server->m.serv_addr.sipx_node[2],
			 server->m.serv_addr.sipx_node[3],
			 server->m.serv_addr.sipx_node[4],
			 server->m.serv_addr.sipx_node[5],
			 ntohs(server->m.serv_addr.sipx_port));
		*/
		DDPRINTK(KERN_DEBUG "ncpfs: req.typ: %04X, con: %d, "
			 "seq: %d",
			 request.type,
			 (request.conn_high << 8) + request.conn_low,
			 request.sequence);
		DDPRINTK(KERN_DEBUG " func: %d\n",
			 request.function);

		result = _send(sock, (void *) start, size);
		if (result < 0) {
			printk(KERN_ERR "ncp_rpc_call: send error = %d\n", result);
			break;
		}
	      re_select:
		wait_table.nr = 0;
		wait_table.entry = &entry;
		current->state = TASK_INTERRUPTIBLE;
		if (!(file->f_op->poll(file, &wait_table) & POLLIN)) {
			int timed_out;
			if (timeout > max_timeout) {
				/* JEJB/JSP 2/7/94
				 * This is useful to see if the system is
				 * hanging */
				if (acknowledge_seen == 0) {
					printk(KERN_WARNING "NCP max timeout\n");
				}
				timeout = max_timeout;
			}
			timed_out = !schedule_timeout(timeout);
			remove_wait_queue(entry.wait_address, &entry.wait);
			fput(file);
			current->state = TASK_RUNNING;
			if (signal_pending(current)) {
				result = -ERESTARTSYS;
				break;
			}
			if (timed_out) {
				if (n < retrans)
					continue;
				if (server->m.flags & NCP_MOUNT_SOFT) {
					printk(KERN_WARNING "NCP server not responding\n");
					result = -EIO;
					break;
				}
				n = 0;
				timeout = init_timeout;
				init_timeout <<= 1;
				if (!major_timeout_seen) {
					printk(KERN_WARNING "NCP server not responding\n");
				}
				major_timeout_seen = 1;
				continue;
			}
		} else if (wait_table.nr) {
			remove_wait_queue(entry.wait_address, &entry.wait);
			fput(file);
		}
		current->state = TASK_RUNNING;

		/* Get the header from the next packet using a peek, so keep it
		 * on the recv queue.  If it is wrong, it will be some reply
		 * we don't now need, so discard it */
		result = _recv(sock, (void *) &reply, sizeof(reply),
			       MSG_PEEK | MSG_DONTWAIT);
		if (result < 0) {
			if (result == -EAGAIN) {
				DDPRINTK(KERN_DEBUG "ncp_rpc_call: bad select ready\n");
				goto re_select;
			}
			if (result == -ECONNREFUSED) {
				DPRINTK(KERN_WARNING "ncp_rpc_call: server playing coy\n");
				goto re_select;
			}
			if (result != -ERESTARTSYS) {
				printk(KERN_ERR "ncp_rpc_call: recv error = %d\n",
				       -result);
			}
			break;
		}
		if ((result == sizeof(reply))
		    && (reply.type == NCP_POSITIVE_ACK)) {
			/* Throw away the packet */
			DPRINTK(KERN_DEBUG "ncp_rpc_call: got positive acknowledge\n");
			_recv(sock, (void *) &reply, sizeof(reply),
			      MSG_DONTWAIT);
			n = 0;
			timeout = max_timeout;
			acknowledge_seen = 1;
			goto re_select;
		}
		DDPRINTK(KERN_DEBUG "ncpfs: rep.typ: %04X, con: %d, tsk: %d,"
			 "seq: %d\n",
			 reply.type,
			 (reply.conn_high << 8) + reply.conn_low,
			 reply.task,
			 reply.sequence);

		if ((result >= sizeof(reply))
		    && (reply.type == NCP_REPLY)
		    && ((request.type == NCP_ALLOC_SLOT_REQUEST)
			|| ((reply.sequence == request.sequence)
			    && (reply.conn_low == request.conn_low)
/* seem to get wrong task from NW311 && (reply.task      == request.task) */
			    && (reply.conn_high == request.conn_high)))) {
			if (major_timeout_seen)
				printk(KERN_NOTICE "NCP server OK\n");
			break;
		}
		/* JEJB/JSP 2/7/94
		 * we have xid mismatch, so discard the packet and start
		 * again.  What a hack! but I can't call recvfrom with
		 * a null buffer yet. */
		_recv(sock, (void *) &reply, sizeof(reply), MSG_DONTWAIT);

		DPRINTK(KERN_WARNING "ncp_rpc_call: reply mismatch\n");
		goto re_select;
	}
	/* 
	 * we have the correct reply, so read into the correct place and
	 * return it
	 */
	result = _recv(sock, (void *)reply_buf, max_reply_size, MSG_DONTWAIT);
	if (result < 0) {
		printk(KERN_WARNING "NCP: notice message: result=%d\n", result);
	} else if (result < sizeof(struct ncp_reply_header)) {
		printk(KERN_ERR "NCP: just caught a too small read memory size..., "
		       "email to NET channel\n");
		printk(KERN_ERR "NCP: result=%d\n", result);
		result = -EIO;
	}

	spin_lock_irqsave(&current->sigmask_lock, flags);
	current->blocked = old_set;
	recalc_sigpending(current);
	spin_unlock_irqrestore(&current->sigmask_lock, flags);
	
	set_fs(fs);
	return result;
}
예제 #29
0
파일: sock.cpp 프로젝트: EricInBj/mongo
 int Socket::unsafe_recv( char *buf, int max ) {
     int x = _recv( buf , max );
     _bytesIn += x;
     return x;
 }
예제 #30
0
파일: xmodem.c 프로젝트: ctelfer/catrpi
int xmr_recv(struct xm_receiver *xmr)
{
	int n;
	int ntries;

	if ( xmr->first ) {
		if ( xmr_send(xmr, XM_NAK) )
			return -1;
		xmr->first = 0;
	}

	ntries = 0;
	while ( ntries < 10 ) {

		xmr->bp = xmr->buf;

		n = _recv(xmr, 1, XM_TOUT);
		if ( n < 0 )
			return -1;

		if ( n == 0 ) {
			if ( xmr_send(xmr, XM_NAK) )
				return -1;
			++ntries;
			continue;
		}

		if ( xmr->buf[XMR_CMD] == XM_CAN ) {
			xmr->error = XME_CANCEL;
			return -1;
		}

		if ( xmr->buf[XMR_CMD] == XM_EOT)
			return xmr_send(xmr, XM_ACK);

		/* one second timeout once transfer has started */
		n = _recv(xmr, sizeof(xmr->buf)-1, 1);
		if ( n < 0 )
			return -1;

		if ( n == 0 || xmr->buf[XMR_CMD] != XM_SOH || !xmr_csum(xmr) ) {
			if ( xmr_send(xmr, XM_NAK) )
				return -1;
			++ntries;
			continue;
		}

		if ( xmr->buf[XMR_BLK] == xmr->nxtblk &&
		     xmr->buf[XMR_BNEG] == 255 - xmr->nxtblk ) {
			xmr->nxtblk++;
			if ( xmr_send(xmr, XM_ACK) )
				return -1;
			return 1;
		}

		if ( xmr->buf[XMR_BLK] == (uchar)(xmr->nxtblk - 1) &&
		     xmr->buf[XMR_BNEG] == 255 - (uchar)(xmr->nxtblk - 1) ) {
			if ( xmr_send(xmr, XM_ACK) )
				return -1;
			ntries = 0;
		} else {
			/* block mismatch:  send cancel */
			xmr_send(xmr, XM_CAN);
			xmr->error = XME_SYNC;
			return -1;
		}

	}

	xmr->error = XME_TOUT;
	return -1;
}