// FILENAME = send2.c // "headdef.h" contains all the headers needed #include "../include/headdef.h" // initializes the socket and check for existance of tile and connect to server static int init(char *argv[]); // start sending file with given fd to server static void send_file(int fd); static int sd_me; static struct sockaddr_in sa_other; int main(int argc, char *argv[]) { if (argc != 3) { printf("Usage: %s \n", argv[0]); exit(EXIT_FAILURE); } int fd = init(argv); send_file(fd); return EXIT_SUCCESS; } static int init(char *argv[]) { // the other's socket address info struct hostent *hp; et_null(hp = gethostbyname(argv[1])); sa_other.sin_addr = *((struct in_addr*)hp->h_addr); sa_other.sin_family = hp->h_addrtype; sa_other.sin_port = htons(atoi(S_PORT)); memset(sa_other.sin_zero, '\0', 8); et_neg1(sd_me = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP)); et_nzero(connect(sd_me, (struct sockaddr *)&sa_other, sizeof sa_other)); int fd; et_neg1(fd = open(argv[2], O_RDONLY)); struct nego_pack nego; strcpy(nego.hello, HELLO); // TODO: add the key here // TODO: add the cipher here struct stat fst; et_neg1(fstat(fd, &fst)); nego.nbytes = fst.st_size; et_neg1(write_all(sd_me, (const char *)&nego, sizeof nego)); return fd; } static void send_file(int fd) { char buf[BUFFER_SIZE]; ssize_t nread; while ((nread = read_all(fd, buf, sizeof buf))) { write_all(sd_me, buf, nread); } ec_nzero(close(fd)); }