├── Vagrantfile ├── .gitignore ├── Makefile ├── README.md ├── LICENSE ├── transferserver.c └── transferclient.c /Vagrantfile: -------------------------------------------------------------------------------- 1 | Vagrant.configure(2) do |config| 2 | config.vm.box = "achille/gios" 3 | end 4 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Editor temp files: 2 | *.swp 3 | *~ 4 | .\#* 5 | \#*\# 6 | .idea/ 7 | 8 | # objects and binaries 9 | transferclient 10 | transferserver 11 | *.o 12 | 13 | # Misc 14 | .vagrant 15 | .DS_Store 16 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | CFLAGS := -Wall --std=gnu99 -g 2 | 3 | default: transferserver transferclient 4 | 5 | transferserver: $(LDFLAGS) transferserver.o 6 | 7 | transferclient: $(LDFLAGS) transferclient.o 8 | 9 | .PHONY: clean 10 | 11 | clean: 12 | rm -fr *.o transferserver transferclient 13 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # ios-project-1-file-transfer 2 | File transfer sample code 3 | 4 | ## To get it setup follow these steps: 5 | 1. Download vagrant binary for your OS at [the downloads section on their website](https://www.vagrantup.com/downloads.html) 6 | 2. Run `vagrant up` to download the VM (it will take a long time the first time you get this VM) 7 | 3. Run `vagrant ssh` to get into the VM 8 | 1. Inside the VM, go to the shared folder with the project `cd /vagrant` 9 | 2. And then compile the code `make` (`make clean` to delete the binaries) 10 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2015 Miguel Morales 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | 23 | -------------------------------------------------------------------------------- /transferserver.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | 12 | 13 | #define BUFSIZE 4096 14 | 15 | #define USAGE \ 16 | "usage:\n" \ 17 | " transferserver [options]\n" \ 18 | "options:\n" \ 19 | " -p Port (Default: 8888)\n" \ 20 | " -f Filename (Default: bar.txt)\n" \ 21 | " -h Show this help message\n" 22 | 23 | int main(int argc, char **argv) { 24 | int option_char; 25 | int portno = 8888; /* port to listen on */ 26 | char *filename = "bar.txt"; /* file to transfer */ 27 | 28 | // Parse and set command line arguments 29 | while ((option_char = getopt(argc, argv, "p:f:h")) != -1){ 30 | switch (option_char) { 31 | case 'p': // listen-port 32 | portno = atoi(optarg); 33 | break; 34 | case 'f': // listen-port 35 | filename = optarg; 36 | break; 37 | case 'h': // help 38 | fprintf(stdout, "%s", USAGE); 39 | exit(0); 40 | break; 41 | default: 42 | fprintf(stderr, "%s", USAGE); 43 | exit(1); 44 | } 45 | } 46 | 47 | /* Socket Code Here */ 48 | } 49 | -------------------------------------------------------------------------------- /transferclient.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | 11 | #define BUFSIZE 4096 12 | 13 | #define USAGE \ 14 | "usage:\n" \ 15 | " transferclient [options]\n" \ 16 | "options:\n" \ 17 | " -s Server (Default: localhost)\n" \ 18 | " -p Port (Default: 8888)\n" \ 19 | " -o Output file (Default foo.txt)\n" \ 20 | " -h Show this help message\n" 21 | 22 | /* Main ========================================================= */ 23 | int main(int argc, char **argv) { 24 | int option_char = 0; 25 | char *hostname = "localhost"; 26 | unsigned short portno = 8888; 27 | char *filename = "foo.txt"; 28 | 29 | // Parse and set command line arguments 30 | while ((option_char = getopt(argc, argv, "s:p:o:h")) != -1) { 31 | switch (option_char) { 32 | case 's': // server 33 | hostname = optarg; 34 | break; 35 | case 'p': // listen-port 36 | portno = atoi(optarg); 37 | break; 38 | case 'o': // filename 39 | filename = optarg; 40 | break; 41 | case 'h': // help 42 | fprintf(stdout, "%s", USAGE); 43 | exit(0); 44 | break; 45 | default: 46 | fprintf(stderr, "%s", USAGE); 47 | exit(1); 48 | } 49 | } 50 | 51 | /* Socket Code Here */ 52 | 53 | } 54 | --------------------------------------------------------------------------------