// File: /workspace/github_cpp_makefile_star2_O2/ccf19881030[P]UDP_Chat/client.cpp
// Function: parse_cmd(char*, int, sockaddr_in*)
void parse_cmd(char *cmdline,int sock,struct sockaddr_in *servaddr)
{
	char cmd[10] = {0};//����
	char *p = NULL;
	//�����ո�
	p = strchr(cmdline,' ');
	if(p != NULL)
		*p = '\0';
 
	strcpy(cmd,cmdline);
 
	if(strcmp(cmd,"exit") == 0)
	{
		MESSAGE msg;
		memset(&msg,0,sizeof(msg));
		msg.cmd = htonl(C2S_LOGOUT);
		strcpy(msg.body,username);
 
		if( (sendto(sock, &msg, sizeof(msg), 0, (struct sockaddr *)servaddr, sizeof(*servaddr))) < 0 )
			ERR_EXIT("sendto");
 
		printf("user %s has logout server\n",username);
		exit(EXIT_SUCCESS);
	}
	else if(strcmp(cmd,"list") == 0)
	{
		MESSAGE msg;
		memset(&msg,0,sizeof(msg));
		msg.cmd = htonl(C2S_ONLINE_USER);
 
		if( (sendto(sock, &msg, sizeof(msg), 0, (struct sockaddr *)servaddr, sizeof(*servaddr))) < 0 )
                        ERR_EXIT("sendto");
		return;
 
	}
	else if(strcmp(cmd,"send") == 0)
	{
		char peername[16] = {0};//�û���
		char msg[MSG_LEN] = {0};//Ҫ���͵���Ϣ
		if(p == NULL)		//�û���Ϊ�գ���������
		{
			 printf("bad command\n");
                         printf("**********************************COMMANDS:*******************************\n");
                         printf("                        send username msg\n");
                         printf("                        list\n");
                         printf("                        exit\n");
 
			 return;
 
		}
		/*send user msg*/
		/*     p    p2 */
		//��������
		while(*p++ == ' ');
 
		char *p2;
		p2 = strchr(p,' ');
		if(p2 == NULL)//��ϢΪ�գ���������
		{
			 printf("bad command\n");
               		 printf("**********************************COMMANDS:*******************************\n");
               		 printf("                        send username msg\n");
                	 printf("                        list\n");
                	 printf("			 exit\n"); 
			 return;
		}
		*p2 = '\0';
		strcpy(peername,p);
 
		while( *p2++ == ' ');
		if(p2 == NULL)//��ϢΪ�գ���������
                {
                         printf("bad command\n");
                         printf("**********************************COMMANDS:*******************************\n");
                         printf("                        send username msg\n");
                         printf("                        list\n");
                         printf("                        exit\n");
                         return;
                }
 
		strcpy(msg,p2);
 
		sendmsgto(sock,peername,msg);
		
	}
	else 
	{	printf("bad command\n");
		printf("**********************************COMMANDS:*******************************\n");
        	printf("                        send username msg\n");
        	printf("                        list\n");
        	printf("                        exit\n");
 
	}
}

// Assembly:
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x230, %rsp            # imm = 0x230
movq %rdx, %r14
movl %esi, %ebx
andw $0x0, 0x8(%rsp)
movq %rdi, %r12
andq $0x0, (%rsp)
pushq $0x20
popq %rsi
callq 0x1080
movq %rax, %r15
testq %rax, %rax
je 0x18d9
movb $0x0, (%r15)
movq %rsp, %r13
movq %r13, %rdi
movq %r12, %rsi
callq 0x1110
leaq 0x8cf(%rip), %rsi       # 0x21bd
pushq $0x5
popq %rdx
movq %r13, %rdi
callq 0x1160
testl %eax, %eax
je 0x1a78
leaq 0x8ad(%rip), %rsi       # 0x21b5
movq %rsp, %rdi
pushq $0x5
popq %rdx
callq 0x1160
testl %eax, %eax
je 0x196f
leaq 0x809(%rip), %rsi       # 0x2127
movq %rsp, %rdi
pushq $0x5
popq %rdx
callq 0x1160
testl %eax, %eax
je 0x19bf
leaq 0x8b5(%rip), %rdi       # 0x21ed
callq 0x11b0
leaq 0x8b5(%rip), %rdi       # 0x21f9
callq 0x11b0
leaq 0x8f4(%rip), %rdi       # 0x2244
callq 0x11b0
leaq 0x912(%rip), %rdi       # 0x226e
callq 0x11b0
leaq 0x923(%rip), %rdi       # 0x228b
callq 0x11b0
jmp 0x19ae
leaq 0x24(%rsp), %r15
movl $0x200, %edx            # imm = 0x200
movq %r15, %rdi
xorl %esi, %esi
callq 0x10b0
movl $0x3000000, -0x4(%r15)  # imm = 0x3000000
leaq 0x20(%rsp), %rsi
pushq $0x10
popq %r9
movl $0x204, %edx            # imm = 0x204
movl %ebx, %edi
xorl %ecx, %ecx
movq %r14, %r8
callq 0x1040
testq %rax, %rax
js 0x1ac2
addq $0x230, %rsp            # imm = 0x230
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
retq
xorps %xmm0, %xmm0
movaps %xmm0, 0x10(%rsp)
leaq 0x20(%rsp), %rdi
movl $0x200, %edx            # imm = 0x200
xorl %esi, %esi
callq 0x10b0
testq %r15, %r15
je 0x1931
cmpb $0x20, (%r15)
leaq 0x1(%r15), %r15
je 0x19e1
pushq $0x20
popq %rsi
movq %r15, %rdi
callq 0x1080
testq %rax, %rax
je 0x1a3c
movq %rax, %r14
movb $0x0, (%rax)
leaq 0x10(%rsp), %rdi
movq %r15, %rsi
callq 0x1110
cmpb $0x20, (%r14)
leaq 0x1(%r14), %r14
je 0x1a0e
leaq 0x20(%rsp), %r15
movq %r15, %rdi
movq %r14, %rsi
callq 0x1110
leaq 0x10(%rsp), %rsi
movl %ebx, %edi
movq %r15, %rdx
callq 0x1af2
jmp 0x19ae
leaq 0x7aa(%rip), %rdi       # 0x21ed
callq 0x11b0
leaq 0x7aa(%rip), %rdi       # 0x21f9
callq 0x11b0
leaq 0x7e9(%rip), %rdi       # 0x2244
callq 0x11b0
leaq 0x807(%rip), %rdi       # 0x226e
callq 0x11b0
leaq 0x771(%rip), %rdi       # 0x21e4
jmp 0x1968
leaq 0x24(%rsp), %r15
movl $0x200, %edx            # imm = 0x200
movq %r15, %rdi
xorl %esi, %esi
callq 0x10b0
movl $0x2000000, -0x4(%r15)  # imm = 0x2000000
leaq 0x2675(%rip), %rsi      # 0x4110
movq %r15, %rdi
callq 0x1110
leaq 0x20(%rsp), %rsi
pushq $0x10
popq %r9
movl $0x204, %edx            # imm = 0x204
movl %ebx, %edi
xorl %ecx, %ecx
movq %r14, %r8
callq 0x1040
testq %rax, %rax
jns 0x1ad6
leaq 0x657(%rip), %rdi       # 0x2120
callq 0x10f0
pushq $0x1
popq %rdi
callq 0x1190
leaq 0x628(%rip), %rdi       # 0x2105
leaq 0x262c(%rip), %rsi      # 0x4110
xorl %eax, %eax
callq 0x1030
xorl %edi, %edi
callq 0x1190