making send_file available to both client and server

master
andrew 2009-02-18 02:30:53 -06:00
parent e8c09582d6
commit c9d154d357
2 changed files with 27 additions and 0 deletions

26
cftp.c
View File

@ -11,6 +11,8 @@
#include <string.h> #include <string.h>
#include <strings.h> #include <strings.h>
#include <unistd.h> #include <unistd.h>
#include <errno.h>
#include <sys/socket.h>
#include "cftp.h" #include "cftp.h"
#include "server.h" #include "server.h"
@ -92,6 +94,30 @@ void debug(const char *prefix, const char *msg)
printf("%s: %s\n", prefix, 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. * Prints out the usage of the program to stderr.
* *

1
cftp.h
View File

@ -13,6 +13,7 @@ int validate_command(const char *);
void split_command(char *, char *, char *); void split_command(char *, char *, char *);
void error(const char *); void error(const char *);
void debug(const char *, const char *); void debug(const char *, const char *);
void send_message(int, char *);
#endif #endif