service.c - File service.c Author Aung Myin 32812965 Pan Xu 32813676 Description This file contains the function definitions relating to the serving of

service.c - File service.c Author Aung Myin 32812965 Pan Xu...

This preview shows page 1 - 2 out of 4 pages.

/** File: service.c* Author: Aung Myin 32812965 & Pan Xu 32813676** Description: This file contains the function definitions relating to the * serving of a client that has connected to the myftpd server.*/#include "service.h"void serveClient(int socketID){int bytesRead, check, numFiles, i, openFile, bytesRemain;int int2bytes;long int4bytes;char commandSelection, tempChar;char inputBuffer[BUFFER_SIZE];char fileBuffer[BUFFER_SIZE];char tempString[256];struct dirent **fileList;struct stat fileInfo;while (1){// Read first opcodebytesRead = read(socketID, &commandSelection, sizeof(char));// If connection has broken down then exitif (bytesRead <= 0){break;}// Check for command givenif (commandSelection == 'A') // cd{// read in directory name lengthbytesRead = read(socketID, &int2bytes, sizeof(int2bytes));// convert back to host byte orderint2bytes = ntohs(int2bytes);// read in directory namebytesRead = read(socketID, inputBuffer, (sizeof(char) * int2bytes));// change the pwdcheck = chdir(inputBuffer);// Send back 'A' opcode for responsetempChar = 'A';write(socketID, &tempChar, sizeof(char));if (check == -1) // If directory change fails{if (errno == ENOENT) // Dir does not exist{tempChar = '1';} else if (errno == EACCES) // Access denied{tempChar = '2';} else // Other errors{tempChar = '3';}} else{tempChar = '0';}
Background image
Image of page 2

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture