Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "csapp.h"
- #define BUFFLEN 256
- #define SET 0
- #define GET 1
- #define DIGEST 2
- #define RUN 3
- int set(){
- return 0;
- }
- int get(){
- return 0;
- }
- int digest(){
- return 0;
- }
- int run(){
- return 0;
- }
- int main(int argc, char** argv){
- int listenfd, connfd, port;
- socklen_t clientLen;
- rio_t rio;
- struct sockaddr_in clientaddr;
- char *buff, *SecretKey;
- struct hostent *hp;
- char *haddrp;
- SecretKey = (argv[2]);
- port = atoi(argv[1]);
- //listen for connection request
- printf("%d %s", port, SecretKey);
- listenfd = Open_listenfd(port);
- printf("listening on port 3001");
- //clientlen = sizeof(clientaddr);
- //establish connection
- while(1){
- clientLen = sizeof(clientaddr);
- connfd = Accept(listenfd, (SA*)&clientaddr, &clientLen);
- hp = Gethostbyaddr((const char*)&clientaddr.sin_addr.s_addr, sizeof(clientaddr.sin_addr.s_addr),AF_INET);
- haddrp = inet_ntoa(clientaddr.sin_addr);
- printf("%s %s\n", hp->h_name, haddrp);
- printf("here");
- Rio_readinitb(&rio, connfd);
- //unsigned char buf[4];
- //Rio_readlineb(&rio, buf, 4);
- //printf("%s",buf);
- //Rio_readlineb(&rio, rio.rio_buf, sizeof(rio.rio_buf));
- printf("they tried");
- if (SecretKey != (rio.rio_buf)){ //if secret key is wrong, replies -1
- printf("Secret key = %d\n", atoi(SecretKey));
- printf("---------------------\n");
- buff = (char*)'1';
- Rio_writen(connfd, buff, sizeof(buff));
- }
- else{
- buff = (char*)'0';
- printf("this did a thing");
- Rio_writen(connfd, buff, sizeof(buff));
- Rio_readlineb(&rio, rio.rio_buf, sizeof(rio.rio_buf));
- if(atoi(rio.rio_buf) == SET)
- set();
- if(atoi(rio.rio_buf) == GET)
- get();
- if(atoi(rio.rio_buf) == DIGEST)
- digest();
- if(atoi(rio.rio_buf) == RUN)
- run();
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement