Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "csapp.h"
- //#include "csapp.c"
- #define BUFFLEN 256
- #define SET 0
- #define GET 1
- #define DIGEST 2
- #define RUN 3
- //structs
- #include <string>
- #include <netinet/in.h>
- struct set_request{
- uint32_t secretKey = 0;
- uint16_t requestType = 0;
- char two_b_pad[2] = {};
- char varName[15] = {};
- uint16_t valLength = 0;
- char value[100]={};
- };
- struct init_request{
- uint32_t secretKey = 0;
- uint16_t requestType = 0;
- char two_b_pad[2] = {};
- };
- /*
- struct set_request{
- char varName[15] = {};
- short valLength = 0;
- char value[100]={};
- };
- */
- struct get_request{
- char varName[15] = {};
- };
- struct digest_request{
- uint16_t valLength;
- char * value;
- };
- struct run_request{
- char * valid_value;
- };
- struct init_response{
- signed char returnCode;
- char three_b_pad[3];
- };
- struct get_response{
- uint16_t valLength;
- char * value;
- };
- int smallSet(char *MachineName, char* port, char* SecretKey, char *variableName, char *value){
- int clientfd;
- int set = SET;
- rio_t rio;
- char* host = MachineName;
- printf("%d %s\n", atoi(port), MachineName);
- //create connection
- //clientfd = Open_clientfd("daan222.netlab.uky.edu", 3001);
- clientfd = Open_clientfd(host, atoi(port));
- Rio_readinitb(&rio, clientfd);
- //initialBuf(initBuf,buf,4);
- //Rio_writen(clientfd,buf,4);
- printf("got this far\n");
- Rio_writen(clientfd, SecretKey, sizeof(SecretKey)); //send SecretKey
- Rio_readlineb(&rio, SecretKey, sizeof(SecretKey));
- Rio_writen(clientfd, (char*)&set, set);
- Rio_readlineb(&rio, (char*)&set, set);
- Rio_writen(clientfd, variableName, sizeof(variableName)); //send variable name
- Rio_readlineb(&rio, variableName, sizeof(variableName));
- Rio_writen(clientfd, value, sizeof(value)); //send variable value
- Rio_readlineb(&rio, value, sizeof(value));
- Close(clientfd);
- return 0;
- }
- int smallGet(char *MachineName, char* port, char* SecretKey, char *variableName, char *value){
- int clientfd;
- int set = SET;
- char *host;
- rio_t rio;
- host = MachineName;
- printf("got this far1\n");
- //create connection
- clientfd = Open_clientfd(host, atoi(port));
- Rio_readinitb(&rio, clientfd);
- printf("got this far\n");
- Rio_writen(clientfd, SecretKey, sizeof(SecretKey)); //send SecretKey
- Rio_readlineb(&rio, SecretKey, sizeof(SecretKey));
- Rio_writen(clientfd, (char*)&set, set);
- Rio_readlineb(&rio, (char*)&set, set);
- Rio_writen(clientfd, variableName, sizeof(variableName)); //send variable name
- Rio_readlineb(&rio, variableName, sizeof(variableName));
- Rio_writen(clientfd, value, sizeof(value)); //send variable value
- Rio_readlineb(&rio, value, sizeof(value));
- Close(clientfd);
- return 0;
- }
- int smallDigest(char *MachineName, int port, int SecretKey, char *data, int dataLength, char *result, int *resultLength){
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement