当前位置: 首页>>代码示例>>C++>>正文


C++ recv_line函数代码示例

本文整理汇总了C++中recv_line函数的典型用法代码示例。如果您正苦于以下问题:C++ recv_line函数的具体用法?C++ recv_line怎么用?C++ recv_line使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了recv_line函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: authenticate

int RASocket::authenticate()
{
    if (send(std::string("Username: ")) == -1)
        return -1;

    std::string user;
    if (recv_line(user) == -1)
        return -1;

    if (send(std::string("Password: ")) == -1)
        return -1;

    std::string pass;
    if (recv_line(pass) == -1)
        return -1;

    sLog->outRemote("Login attempt for user: %s", user.c_str());

    if (check_access_level(user) == -1)
        return -1;

    if (check_password(user, pass) == -1)
        return -1;

    sLog->outRemote("User login: %s", user.c_str());

    return 0;
}
开发者ID:Sar777,项目名称:SkyFireEMU,代码行数:28,代码来源:RASocket.cpp

示例2: send

int RASocket::svc(void)
{
    if (send("Authentication required\r\n") == -1)
        return -1;

    if (authenticate() == -1)
    {
        (void) send("Authentication failed\r\n");
        return -1;
    }

    // send motd
    if (send(std::string(sWorld->GetMotd()) + "\r\n") == -1)
        return -1;

    for(;;)
    {
        // show prompt
        const char* tc_prompt = "TC> ";
        if (size_t(peer().send(tc_prompt, strlen(tc_prompt))) != strlen(tc_prompt))
            return -1;

        std::string line;

        if (recv_line(line) == -1)
            return -1;

        if (process_command(line) == -1)
            return -1;
    }

    return 0;
}
开发者ID:wuhongyi1977,项目名称:StrawberryCore,代码行数:33,代码来源:RASocket.cpp

示例3: subnegotiate

int RASocket::svc(void)
{
    //! Subnegotiation may differ per client - do not react on it
    subnegotiate();

    if (send("Authentication required\r\n") == -1)
        return -1;

    if (authenticate() == -1)
    {
        (void) send("Authentication failed\r\n");
        return -1;
    }

    // send motd
    if (send(std::string(sWorld->GetMotd()) + "\r\n") == -1)
        return -1;

    for (;;)
    {
        // show prompt
        if (send("TC> ") == -1)
            return -1;

        std::string line;

        if (recv_line(line) == -1)
            return -1;

        if (process_command(line) == -1)
            return -1;
    }

    return 0;
}
开发者ID:Caydan,项目名称:DeathCore,代码行数:35,代码来源:RASocket.cpp

示例4: db

int RASocket::recv_line(std::string& out_line)
{
    char buf[4096];

    ACE_Data_Block db(sizeof (buf),
            ACE_Message_Block::MB_DATA,
            buf,
            0,
            0,
            ACE_Message_Block::DONT_DELETE,
            0);

    ACE_Message_Block message_block(&db,
            ACE_Message_Block::DONT_DELETE,
            0);

    if (recv_line(message_block) == -1)
    {
        sLog->outRemote("Recv error %s", ACE_OS::strerror(errno));
        return -1;
    }

    out_line = message_block.rd_ptr();

    return 0;
}
开发者ID:Sar777,项目名称:SkyFireEMU,代码行数:26,代码来源:RASocket.cpp

示例5: take_connection

void take_connection(int sockfd) {

	int status;
	char *buff;

	/* chek for client ip */
	if (strcmp(client_ip, "127.0.0.1")) {
		close(sockfd);

		return;
	}

	send_line(sockfd, message(MSG_WELCOME), strlen(message(MSG_WELCOME)));

	if (helo_cmd(sockfd)) {
		close(sockfd);
		return;
	}

	buff = calloc(MAX_MSG_SIZE, sizeof(char));

	while (1) {
		memset(buff, '\0', MAX_MSG_SIZE);

		if (recv_line(sockfd, buff, MAX_MSG_SIZE - 1) <= 0) {
			free(buff);
			break;
		} else {
			status = lr_cmd(sockfd, buff);

			/* if something went wrong break */
			if (status <= -1) {
				break;
			/* if it went ok continue */
			} else if (status == 0) {
				continue;
			/* else: nothing happened, this command wasn't requested */
			} else {
				status = bye_cmd(sockfd, buff);

				if (status <= 0 ||
					send_line(
						sockfd,
						message(MSG_BAD_SYNTAX),
						strlen(message(MSG_BAD_SYNTAX))
					) < 0) {
					break;
				}
			}
		}
	}

	sleep(1);
	close(sockfd);
}
开发者ID:BenBE,项目名称:ispCP,代码行数:55,代码来源:take_connection.c

示例6: handle_connection

/* This function handles the connection on the passed socket from the 
 * passed client address and logs to the passed FD. The connection is 
 * processed as a web request and this function replies over the connected
 * socket.  Finally, the passed socket is closed at the end of the function. 
 */ 
void handle_connection(int sockfd, struct sockaddr_in *client_addr_ptr, int logfd) { 
   unsigned char *ptr, request[500], resource[500], log_buffer[500]; 
   int fd, length; 

   length = recv_line(sockfd, request); 
   
   sprintf(log_buffer, "From %s:%d \"%s\"\t", inet_ntoa(client_addr_ptr->sin_addr), ntohs(client_addr_ptr->sin_port), request); 

   ptr = strstr(request, " HTTP/"); // search for valid looking request 
   if(ptr == NULL) { // then this isn't valid HTTP 
      strcat(log_buffer, " NOT HTTP!\n"); 
   } else { 
      *ptr = 0; // terminate the buffer at the end of the URL 
      ptr = NULL; // set ptr to NULL (used to flag for an invalid request) 
      if(strncmp(request, "GET ", 4) == 0)  // get request 
         ptr = request+4; // ptr is the URL 
      if(strncmp(request, "HEAD ", 5) == 0) // head request 
         ptr = request+5; // ptr is the URL 
      if(ptr == NULL) { // then this is not a recognized request 
         strcat(log_buffer, " UNKNOWN REQUEST!\n"); 
      } else { // valid request, with ptr pointing to the resource name 
         if (ptr[strlen(ptr) - 1] == '/')  // for resources ending with '/' 
            strcat(ptr, "index.html");     // add 'index.html' to the end 
         strcpy(resource, WEBROOT);     // begin resource with web root path 
         strcat(resource, ptr);         //  and join it with resource path 
         fd = open(resource, O_RDONLY, 0); // try to open the file 
         if(fd == -1) { // if file is not found 
            strcat(log_buffer, " 404 Not Found\n"); 
            send_string(sockfd, "HTTP/1.0 404 NOT FOUND\r\n"); 
            send_string(sockfd, "Server: Tiny webserver\r\n\r\n"); 
            send_string(sockfd, "<html><head><title>404 Not Found</title></head>"); 
            send_string(sockfd, "<body><h1>URL not found</h1></body></html>\r\n"); 
         } else {      // otherwise, serve up the file 
            strcat(log_buffer, " 200 OK\n"); 
            send_string(sockfd, "HTTP/1.0 200 OK\r\n"); 
            send_string(sockfd, "Server: Tiny webserver\r\n\r\n"); 
            if(ptr == request + 4) { // then this is a GET request 
               if( (length = get_file_size(fd)) == -1) 
                  fatal("getting resource file size"); 
               if( (ptr = (unsigned char *) malloc(length)) == NULL) 
                  fatal("allocating memory for reading resource"); 
               read(fd, ptr, length); // read the file into memory 
               send(sockfd, ptr, length, 0);  // send it to socket 
               free(ptr); // free file memory 
            } 
            close(fd); // close the file 
         } // end if block for file found/not found 
      } // end if block for valid request 
   } // end if block for valid HTTP 
   timestamp(logfd); 
   length = strlen(log_buffer); 
   write(logfd, log_buffer, length); // write to the log 

   shutdown(sockfd, SHUT_RDWR); // close the socket gracefully
} 
开发者ID:17twenty,项目名称:hackingSkel,代码行数:60,代码来源:tinywebd.c

示例7: send_recv

int
send_recv(struct user *u, int child_no, struct user *users)
{
	//struct user *up = &u;
	char *buf;
	ssize_t len;

	(void) fprintf(stderr, "-----------------------------------\n");
	len = recv_line(u->socket, &buf);
	if (len == -1){ // 受信失敗。無視する
		(void) fprintf(stderr, "error");
		return(0);
	}
	if(len == 0){
		(void) fprintf(stderr, "recv:EOF\n");
		return(-1);
	}
	char *cmd, *body;
	client_cmd_parse(buf, &cmd, &body);

	if(strncmp(cmd, "JOIN", sizeof("JOIN")) == 0){
		fprintf(stderr, "JOIN CMD..\n");
		if(!set_name(u, body)){
			disconnect(u);
		}
		(void) fprintf(stderr, "name= '%s'\n", u->name);
	}else if(strncmp(cmd, "SAY", sizeof("SAY")) == 0){
		fprintf(stderr, "SAY CMD..\n");

		push_to_everybody(users, generate_sayed_cmd(u, body));
		/*
		int send_len = strlen(body);
		fprintf(stderr, "body...'%s', len=%d\n", body, send_len);
		generate_sayed_cmd(u, body);
		int i;
		for (i = 0; i < MAX_CHILD; i++) {
			if(users[i].socket != -1){
				fprintf(stderr, "sending....to [user:%d]\n", users[i].no);
				len = send(users[i].socket, body, (size_t) send_len, 0);
				if (len == -1) {
					perror("send");
					return(-1);
				}
			}
		}
		*/
	}else if(strncmp(cmd, "LEAVE", sizeof("LEAVE")) == 0){
		fprintf(stderr, "LEAVE CMD..\n");
	}
	//free(body);
	free(cmd);
	free(buf);
	return(0);
}
开发者ID:curi1119,项目名称:socketServerPractice,代码行数:54,代码来源:server.c

示例8: nrecv

char* nrecv(int clientfd)
{
    int read = 0, nread = 0;
    char head_line[100];
    char content_len[] = "Content-Length: ";
    char *p = NULL;
    char *buf = NULL;
    int body_len = 0;
    /*printf("step into nrecv!\n");*/
    do {
        if (recv_line(clientfd,head_line) <= 0)
            return NULL;
    } while(strstr(head_line, content_len) == NULL);

    p = head_line + 16;
    while(*p != '\0') {
        body_len = body_len * 10 + *p - '0';
        p++;
    }
    /*printf("nrecv 85\n");*/
    do {
        if(recv_line(clientfd, head_line) < 0)
            return NULL;
        if(strlen(head_line) == 0)
            break;
    } while(1);
    /*printf("nrecv 92\n");*/
    if((buf = (char *) malloc((body_len+1) * sizeof(char))) == NULL)
        return NULL;
    do {
        read = recv(clientfd, buf + nread, body_len-nread, 0);
        if(read < 0) {
            return NULL;
        }
        nread += read;
    } while(read > 0);
    /*printf("nrecv 102\n");*/
    *(buf+body_len) = '\0';
    /*	printf("will out the nrecv\n");*/
    return buf;
}
开发者ID:yhshen,项目名称:siteanalyzer,代码行数:41,代码来源:network.c

示例9: http_response_status

int http_response_status(http_client_ptr_t http_client)/* 远程WEB服务器的http响应代码,如404*/
{
	//char *temp[5];
	int flag;
	char recvbuf[RECVSIZE+1];
	bzero(recvbuf,RECVSIZE+1);
	flag = recv_line(recvbuf, &(http_client->network));
	if(flag == -1) {
		fprintf(stderr, "Error in http_response_status(). recv error.\n");
		return flag;
	}
	else if (flag < 2) {
		fprintf(stderr, "Error in http_response_status(). recv error.\n");
		fprintf(stderr, "Now flag is %d, recvbuf is %s.\n",flag ,recvbuf);
		return -1;
	}
	//mysplit(temp, recvbuf, " ");
	http_client->status = get_status(recvbuf);
	bzero(recvbuf,RECVSIZE);
	flag = recv_line(recvbuf, &(http_client->network));
	if(flag <= -1){
		fprintf(stderr, "Error in http_response_status(). recv error.\n");
		return -1;
	}
	while(strcmp(recvbuf,"\r\n")!=0) {
//		mysplit(temp, recvbuf, ":");
//		if(strcasecmp(temp[0], "Content-Length")==0) {
//			http_client->content_length = atol(temp[1]);
//		}
//		bzero(recvbuf,RECVSIZE);
		flag = recv_line(recvbuf, &(http_client->network));
		if(flag <= -1){
			fprintf(stderr, "Error in http_response_status(). recv error.\n");
			return -1;
		}
	}
	//fprintf(stderr,"http get status success!\n");
	return http_client->status;
}
开发者ID:xuexiaojian,项目名称:siteanalyzer,代码行数:39,代码来源:http_client.c

示例10: dump_residual

static void
dump_residual (socket_descriptor_t sd,
	       int timeout,
	       volatile int *signal_received)
{
  char buf[256];
  while (true)
    {
      if (!recv_line (sd, buf, sizeof (buf), timeout, true, NULL, signal_received))
	return;
      chomp (buf);
      msg (D_PROXY, "PROXY HEADER: '%s'", buf);
    }
}
开发者ID:ThomasHabets,项目名称:openvpn,代码行数:14,代码来源:proxy.c

示例11: hosts_read_client

/**
 * Returns -1 if no socket, error or client asked to stop tests, 0 otherwise.
 */
static int
hosts_read_client (struct arglist *globals)
{
  struct timeval tv;
  int e;
  fd_set rd;
  int rsoc;

  if (g_soc == -1)
    return 0;


  rsoc = openvas_get_socket_from_connection (g_soc);
  if (rsoc == -1)
    return -1;

  FD_ZERO (&rd);
  FD_SET (rsoc, &rd);

  for (;;)
    {
      tv.tv_sec = 0;
      tv.tv_usec = 1000;
      e = select (rsoc + 1, &rd, NULL, NULL, &tv);
      if (e < 0 && errno == EINTR)
        continue;
      else
        break;
    }

  if (e > 0 && FD_ISSET (rsoc, &rd) != 0)
    {
      int f, n;
      char buf[4096];
      n = recv_line (g_soc, buf, sizeof (buf) - 1);
      if (n <= 0)
        return -1;

      f = ntp_parse_input (globals, buf);
      if (f == NTP_STOP_WHOLE_TEST)
        return -1;
      else if (f == NTP_PAUSE_WHOLE_TEST)
        hosts_pause_all ();
      else if (f == NTP_RESUME_WHOLE_TEST)
        hosts_resume_all ();
    }

  return 0;
}
开发者ID:manfredgithub,项目名称:Openvas-Source,代码行数:52,代码来源:hosts.c

示例12: read_version

static int read_version(conn_t *conn)
{
	char buf[1024];
	unsigned i;
	if(!recv_line(conn, buf, sizeof(buf)))
	    return -1;
	if (!strcmp(buf, "UNKNOWN COMMAND\n"))
	    return -2;

	conn->version = strdup(buf);
	OOM_CHECK(conn->version);
	for (i=0;i<strlen(conn->version);i++)
		    if (conn->version[i] == '\n')
			conn->version[i] = ' ';
	return 0;
}
开发者ID:Jyang772,项目名称:clamav-devel,代码行数:16,代码来源:clamdtop.c

示例13: get_proxy_authenticate

/*
 * Extract the Proxy-Authenticate header from the stream.
 * Consumes all headers.
 */
static int
get_proxy_authenticate (socket_descriptor_t sd,
		        int timeout,
			char **data,
			struct gc_arena *gc,
		        volatile int *signal_received)
{
  char buf[256];
  int ret = HTTP_AUTH_NONE;
  while (true)
    {
      if (!recv_line (sd, buf, sizeof (buf), timeout, true, NULL, signal_received))
	{
	  *data = NULL;
	  return HTTP_AUTH_NONE;
	}
      chomp (buf);
      if (!strlen(buf))
	return ret;
      if (ret == HTTP_AUTH_NONE && !strncmp(buf, "Proxy-Authenticate: ", 20))
	{
	  if (!strncmp(buf+20, "Basic ", 6))
	    {
	      msg (D_PROXY, "PROXY AUTH BASIC: '%s'", buf);
	      *data = string_alloc(buf+26, gc);
	      ret = HTTP_AUTH_BASIC;
	    }
#if PROXY_DIGEST_AUTH
	  else if (!strncmp(buf+20, "Digest ", 7))
	    {
	      msg (D_PROXY, "PROXY AUTH DIGEST: '%s'", buf);
	      *data = string_alloc(buf+27, gc);
	      ret = HTTP_AUTH_DIGEST;
	    }
#endif
#if NTLM
	  else if (!strncmp(buf+20, "NTLM", 4))
	    {
	      msg (D_PROXY, "PROXY AUTH HTLM: '%s'", buf);
	      *data = NULL;
	      ret = HTTP_AUTH_NTLM;
	    }
#endif
	}
    }
}
开发者ID:ThomasHabets,项目名称:openvpn,代码行数:50,代码来源:proxy.c

示例14: main

int main(int argc, char *argv[]){

	int sockfd;
	struct hostent *host_info;
	struct sockaddr_in target_addr;
	unsigned char buffer[4096];
	
	if (argc < 2){
		printf("Usage: %s <hostname>\n",argv[1]);
	}

	/* tries to resolve the hostname. if it failes, a null pointer is returned */
	if((host_info=gethostbyname(argv[1]))==NULL){
		printf("Could not resolve hostname %s",argv[1]);
	}

	/* creates a usual tcp socket for internet protocol family */
	if((sockfd=socket(PF_INET, SOCK_STREAM,0))==0){
		printf("Error creating socket\n");
	}
	
	target_addr.sin_family=AF_INET;		/* sets the host byte order */
	target_addr.sin_port=htons(80);		/* changes the integer port number from host byte order into network byte order */
	target_addr.sin_addr = *((struct in_addr *) host_info->h_addr);		/* sets the address we are trying to connect. the information is received from hostent struct */
	memset(&(target_addr.sin_zero),'\0',8);		/* padding to zero */

	/* connect function call on socket tries to connect 
	see http://linux.die.net/man/2/connect */
	if(connect(sockfd, (struct sockaddr *)&target_addr, sizeof(struct sockaddr)) == -1){
		printf("Error when connecting to the remote server\n");
	}

	send_string(sockfd, "HEAD / HTTP/1.0\r\n\r\n");

	while(recv_line(sockfd, buffer)){
		/* strncasecmü is a string comparsion functon from string.h that compares the first n bytes of the two strings, ignoring capit. 
		   it retunrs 0 on success. If it found that string, it will remove that and print out everything after that */
		if(strncasecmp(buffer, "Server:",7)==0){
			printf("The webserver for the hostname %s is %s\n", argv[1], buffer+8);
			exit(0);
		}
	}
	printf("Server line not found\n");
	exit(1);

}
开发者ID:mp88,项目名称:tmp,代码行数:46,代码来源:webserver_id.c

示例15: parse_queue

static void parse_queue(conn_t *conn, char* buf, size_t len, unsigned idx)
{
	do {
		double tim;
		const char *t = strchr(buf, ' ');
		if(!t)
			continue;
		if(sscanf(t,"%lf", &tim) != 1)
			continue;
		++global.n;
		global.tasks = realloc(global.tasks, sizeof(*global.tasks)*global.n);
		OOM_CHECK(global.tasks);
		global.tasks[global.n-1].line = strdup(buf);
		OOM_CHECK(global.tasks[global.n-1].line);
		global.tasks[global.n-1].tim  = tim;
		global.tasks[global.n-1].clamd_no = idx + 1;
	} while (recv_line(conn, buf, len) && buf[0] == '\t' && strcmp("END\n", buf) != 0);
}
开发者ID:Jyang772,项目名称:clamav-devel,代码行数:18,代码来源:clamdtop.c


注:本文中的recv_line函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。