void CreateLCObjects() { int n; int obj; char c; for(obj=1; obj<=app_num_objects; obj++) { Print("+ Encoding Object #%-2d: ",obj); n=create_lc_object(obj); if(n!=0) { Print("Error! \n"); if(n==-1) err_seek(tempname1); if(n==-2) err_read(tempname1); if(n==-3) err_mem(); if(n==-4) err_write(tempname2); if(n==-5) err_lcobjhdr(tempname1); } c = app_obj_seekattr[obj] ? '*':' '; if(!quiet) { printf("[û] "); if(!verbose) printf("(%1.1f%%)\n", ((float)(obj_new_size+0.01)/(float)(obj_old_size+0.01))*100); else { printf("Old=%7d, New=%7d, (%1.1f%%) (%s)%c\n", obj_old_size,obj_new_size, ((float)(obj_new_size+0.01)/(float)(obj_old_size+0.01))*100, encodetype[app_enc_status], c); if(verbxtra) printf(" ** %s **, ** %s **, %7d - fixups\n", app_obj_iscode ? "CODE":"DATA", app_obj_is32bit ? "32bit":"16bit", app_obj_seekattr[obj]); } } } }
void CreateLCHeader() { int n; Print("+ Creating LC Header : "); n=create_lc_header(); if(n!=0) { Print("Error! \n"); if(n==-1) err_seek(tempname1); if(n==-2) err_read(tempname1); if(n==-3) err_write(tempname2); if(n==-4) err_linker(tempname1); if(n==-5) err_objects(tempname1); } else { if(!verbose) Print("Ok.\n"); else Print("Ok. (%d Objects)\n",app_num_objects); } }
int FindExecType() { int n; n=get_exec_type(); if(n==-1) err_read(tempname1); if(n==-2) err_support(oldfilename); if(n==3) err_formlc(oldfilename); if(n==4) err_formpe(oldfilename); if(n==5) err_formpmw1(oldfilename); return(n); }
void CreateLCFixups() { int n; Print("+ Encoding LC Fixups : "); n=create_lc_fixups(); if(n!=0) { Print("Error!\n"); if(n==-1) err_seek(tempname1); if(n==-2) err_read(tempname1); if(n==-3) err_mem(); if(n==-4) err_write(tempname2); } if(quiet!=TRUE) { printf("[û] "); if(!verbose) printf("(%1.1f%%)\n", ((float)(obj_new_size+0.01)/(float)(obj_old_size+0.01))*100); else printf("Old=%7d, New=%7d, (%1.1f%%) (%s)\n", obj_old_size,obj_new_size, ((float)(obj_new_size+0.01)/(float)(obj_old_size+0.01))*100, encodetype[app_enc_status]); } }
int main(int argc, char *argv[]) { int sockfd, newsockfd, portno; socklen_t clilen; char buffer[RCVLEN]; char sendbuff[SNDLEN]; struct sockaddr_in serv_addr, cli_addr; int n,i,j,newtargetsockfd; int yes = 1; // file descriptor bookkeeping int fdmax; fd_set master; fd_set read_fds; int connections[32][2] = {0}; // length of a fd_set if (argc < 2) { fprintf(stderr,"error, no port provided\n"); exit(1); } // set up listener socket sockfd = err_socket(AF_INET, SOCK_STREAM, 0); bzero((char *) &serv_addr, sizeof(serv_addr)); portno = atoi(argv[1]); serv_addr.sin_family = AF_INET; serv_addr.sin_addr.s_addr = INADDR_ANY; serv_addr.sin_port = htons(portno); setsockopt(sockfd, SOL_SOCKET, SO_REUSEADDR, &yes, sizeof(int)); if (bind(sockfd, (struct sockaddr *) &serv_addr, sizeof(serv_addr)) < 0) err_exit("error on binding"); // listen only supports up to 5 backlog listen(sockfd,32); fdmax = sockfd; connections[0][0] = sockfd; connections[0][1] = sockfd; FD_SET(sockfd, &master); fprintf(stderr,"starting server \n"); int loop = 0; for (;;){ read_fds = master; if (select(fdmax+1, &read_fds, NULL, NULL, NULL) == -1) err_exit("error on select"); for(i = 0; i <= 32; i++){ if (connections[i][0] && connections[i][0] < 32) { if (!FD_ISSET(connections[i][0],&read_fds)) continue; fprintf(stderr,"checking connection...\n"); if (connections[i][0] == sockfd){ // handle new connections fprintf(stderr,"found new connection\n"); clilen = sizeof(cli_addr); newsockfd = accept(sockfd, (struct sockaddr *) &cli_addr, &clilen); if (newsockfd < 0) err_exit("error on accept"); // add new fd to connections list for (j = 0; j < 32; j++){ if (!connections[j][0]){ connections[j][0] = newsockfd; connections[j][1] = newsockfd; break; } } FD_SET(newsockfd, &master); if (newsockfd > fdmax) fdmax = newsockfd; } else { // handle each client fprintf(stderr,"handling client %d\n",connections[i][0]); bzero(buffer,256); err_read(connections[i][0],buffer,RCVLEN-1); if (strcmp(buffer,"LIST\n") == 0){ // list all connected clients sprintf(buffer,"you are client %d\n",connections[i][0]); err_write(connections[i][0],buffer,strlen(buffer)); err_write(connections[i][0],"listing all connections...\n",27); for (j = 0; j < 32; j++){ if (connections[j][0] && connections[j][0] != sockfd){ sprintf(buffer,"client found: %d\n",connections[j][0]); err_write(connections[i][0],buffer, strlen(buffer)); } } n = err_write(connections[i][0],"done listing connections\n",25); } else if (sscanf(buffer,"CONNECT TO %d\n",&newtargetsockfd) > 0){ // set up forwarding fprintf(stderr,"connecting client %d to client %d\n",connections[i][0],newtargetsockfd); for(j = 0; j < 32; j++){ if (connections[j][0] == newtargetsockfd){ connections[i][1] = newtargetsockfd; sprintf(buffer,"connected to client %d\n",newtargetsockfd); err_write(connections[i][0],buffer,strlen(buffer)); j = 40; break; } } if (j != 40){ err_write(connections[i][0],"could not connect to client\n",28); } } else{ // read from one client, and write to another (input/output clients could be the same) printf("Here is the message: %s\n",buffer); err_write(connections[i][0],"message recieved\n",17); sprintf(sendbuff,"recieved message from client %d: %s\n",connections[i][0],buffer); err_write(connections[i][1],sendbuff,strlen(sendbuff)); } } } }// loop through file descriptors } close(newsockfd); close(sockfd); return 0; }