c - How to check for a <CRLF> for my FTP server -
i have created little ftp server , have few commands available.
here's how check input user see if matches 1 of commands in linked list:
int check_cmd(char *buff, char *cmd) { int end; if (strstr(buff, cmd) != buff) return (-1); end = strlen(cmd); if (buff[end] != '\0' && buff[end] != ' ' && buff[end] != '\n') return (-1); return (0); } void read_command(t_client *client, t_cmd *lexer) { t_cmd *current; bzero(client->buff, max_read + 1); server_read(client); current = lexer; while (current != null) // go through linked list, checking if matches { if (check_cmd(client->buff, current->cmd) == 0) // matches command ! { current->ptr(client); // calls appropriate function return ; } current = current->next; } server_write(client, "invalid command.\n"); }
but using -c
option netcat
send \r\n
default @ every command, , yet, not check it.
how may check if <crlf>
passed through command line?
first thing see end should be:
end = strlen(cmd) - 1;
because arrays in c accessed index starting 0 not 1.
to check @ end of string determine if end - 1 '\r' , end '\n':
if(buff[end-1] == '\r' && buff[end] == '\n') { // }
Comments
Post a Comment