making send_file available to both client and server
parent
e8c09582d6
commit
c9d154d357
26
cftp.c
26
cftp.c
|
@ -11,6 +11,8 @@
|
|||
#include <string.h>
|
||||
#include <strings.h>
|
||||
#include <unistd.h>
|
||||
#include <errno.h>
|
||||
#include <sys/socket.h>
|
||||
|
||||
#include "cftp.h"
|
||||
#include "server.h"
|
||||
|
@ -92,6 +94,30 @@ void debug(const char *prefix, const char *msg)
|
|||
printf("%s: %s\n", prefix, msg);
|
||||
}
|
||||
|
||||
/*
|
||||
* Sends a message to the socket. Pass in the socket and message. Expects msg
|
||||
* to be already validated by validate_command first! Formats response into
|
||||
* string buffer given. Works for client or server, so long as you expect a
|
||||
* response message from the other side.
|
||||
*
|
||||
*/
|
||||
void send_message(int skt, char *msg)
|
||||
{
|
||||
char errmsg[ERRMSGLEN];
|
||||
memset(errmsg, '\0', ERRMSGLEN);
|
||||
|
||||
if(send(skt, msg, strlen(msg), 0) < 0)
|
||||
{
|
||||
sprintf(errmsg, "Send Error: %s", strerror(errno));
|
||||
error(errmsg);
|
||||
}
|
||||
else if(recv(skt, msg, MSGLEN, 0) < 0)
|
||||
{
|
||||
sprintf(errmsg, "Receive Error: %s", strerror(errno));
|
||||
error(errmsg);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Prints out the usage of the program to stderr.
|
||||
*
|
||||
|
|
Reference in New Issue