Thank you to anyone who has already donated - your generous donations helped make three months of treatment possible.
My brother Nate continues to fight stage IV Hodgkin's lymphoma. He's just 31, with a wife and baby girl. They have no active income (since he's been unable to return to work), no insurance, and cannot afford the treatment he needs. Nate and his family need your help. Please consider a donation, every dollar helps. Thanks.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 |
/* * Copyright (c) 2005 Ian McDonald <imcdnzl@gmail.com> * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ void* dostuff(void*); void* dostuff(void* sock) { //int* data = reinterpret_cast<int*>(sock); int sockfd; memcpy(&sockfd,sock,sizeof(sockfd)); //delete data; ssize_t n; char buf[MAXLINE]; char outstr[MAXLINE]; int64_t size = 4294967295; int64_t readChars = 0; int64_t unitsize = 0; int64_t toTransfer = 4294967295; do { readChars = 0; fstream* fs; fs = new fstream(default_dest_path.c_str(), ios::out | ios::in | ios::binary | ios::trunc); if { //n = read(sockfd,(char *) &size, sizeof(int64_t)); while { unitsize = ((toTransfer >= MAXLINE) ? MAXLINE : toTransfer); n = recv(sockfd,buf,MAXLINE,0); strncpy(outstr,buf,n); outstr[n] = '\0'; // should really check if N == MAXLINE fs->write(buf, MAXLINE); toTransfer -= unitsize; //cout << outstr; } } else { //n = recv(sockfd, (char*) &size, sizeof(int64_t), 0); while { unitsize = ((toTransfer >= MAXLINE) ? MAXLINE : toTransfer); n = recv(sockfd,buf,MAXLINE, 0); strncpy(outstr,buf,n); outstr[n] = '\0'; // should really check if N == MAXLINE if printerrno("dostuff UDP"); //cout << outstr; fs->write(buf, MAXLINE); toTransfer -= unitsize; //readChars += MAXLINE; } } fs->flush(); fs->close(); delete (fs); toTransfer = size; } while (n < 0 && errno == EINTR); if printerrno("dostuff"); } int { int listenfd, connfd; , cliaddr; socklen_t clilen; string test; pid_t childpid; //argv++; //argc--; int ind = 1; while { //cout << ind << argv[ind] << endl; switch { // protocol case 'P': test = string(argv[++ind]); if,"TCP")==0) { default_proto = TCP; printf("Using TCP\n"); } else if,"DCCP")==0) { default_proto = DCCP; printf("Using DCCP\n"); } else if,"UDP")==0) { default_proto = UDP; printf("Using UDP\n"); } else { goto usage; } break; // port case 'p': port = string(argv[++ind]); cout << "Listening on port " << port.c_str() << endl; break; // destination path case 'd': default_dest_path = string(argv[++ind]); cout << "Saving files in " << default_dest_path.c_str() << endl; break; default: goto usage; break; } ind++; //cout << ind << argv[ind] << endl; //cout << ind << argv[ind][1] << argv[ind++] << endl; //argv++; //argc--; } if) < 0) { printerrno("socket"); return 1; } bzero(&servaddr, sizeof(servaddr)); servaddr.sin_family = AF_INET; servaddr.sin_addr.s_addr = htonl(INADDR_ANY); servaddr.sin_port = htons(str_to_int(port)); bind(listenfd, ()&servaddr, sizeof(servaddr)); if { printerrno("bind"); return 1; } socket_options(listenfd); if { printerrno("socket_options"); return 1; } if { listen(listenfd, 0); if { printerrno("listen"); return 1; } cout << "Listen on port " << port.c_str() << endl; for { clilen = sizeof(cliaddr); if ((connfd = accept(listenfd,()&cliaddr, &clilen)) <0) { if continue; else printerrno("accept"); } pthread_t rcvthread; pthread_create(&rcvthread, NULL, dostuff, (void *)&connfd); pthread_detach(rcvthread); if printerrno("close - postfork"); } close(connfd); } else { cout << "Listen on port " << port.c_str() << endl; while(true) { pthread_t rcvthread; pthread_create(&rcvthread, NULL, dostuff, (void *)&listenfd); pthread_detach(rcvthread); } close(listenfd); } return 0; usage: fprintf(stderr,"-P proto defines the protocol to use where proto\n"); fprintf(stderr,"-p port defines the port to connect to\n"); //fprintf(stderr,"can be TCP or DCCP\n"); return 1; } |