VInt VSocket::Send(const char *buff, const VCard bufflen) { //adzm 2010-08-01 m_LastSentTick = GetTickCount(); unsigned int newsize=queuebuffersize+bufflen; char *buff2; buff2=(char*)buff; unsigned int bufflen2=bufflen; // adzm 2010-09 - flush as soon as we have a full buffer, not if we have exceeded it. if (newsize >= G_SENDBUFFER) { memcpy(queuebuffer+queuebuffersize,buff2,G_SENDBUFFER-queuebuffersize); if (!sendall(sock,queuebuffer,G_SENDBUFFER,0)) return FALSE; // vnclog.Print(LL_SOCKERR, VNCLOG("SEND %i\n") ,G_SENDBUFFER); buff2+=(G_SENDBUFFER-queuebuffersize); bufflen2-=(G_SENDBUFFER-queuebuffersize); queuebuffersize=0; // adzm 2010-09 - flush as soon as we have a full buffer, not if we have exceeded it. while (bufflen2 >= G_SENDBUFFER) { if (!sendall(sock,buff2,G_SENDBUFFER,0)) return false; // vnclog.Print(LL_SOCKERR, VNCLOG("SEND 1 %i\n") ,G_SENDBUFFER); buff2+=G_SENDBUFFER; bufflen2-=G_SENDBUFFER; } } memcpy(queuebuffer+queuebuffersize,buff2,bufflen2); queuebuffersize+=bufflen2; if (queuebuffersize > 0) { if (!sendall(sock,queuebuffer,queuebuffersize,0)) return false; } // vnclog.Print(LL_SOCKERR, VNCLOG("SEND 2 %i\n") ,queuebuffersize); queuebuffersize=0; return bufflen; }
int cmc_crawl(int socketha,char collection_inn[], char *extra_in) { char collection[64]; char extrabuf[512]; int intrespons; int i; //toDo bruk strSspy strncpy(collection,collection_inn,sizeof(collection)); strncpy(extrabuf, extra_in, sizeof(extrabuf)); sendpacked(socketha,cm_crawlcollection,BLDPROTOCOLVERSION, 0, NULL,""); if(sendall(socketha,&collection, sizeof(collection)) == 0) { perror("sendall"); exit(1); } if(sendall(socketha,&extrabuf, sizeof(extrabuf)) == 0) { perror("sendall"); exit(1); } if ((i=recv(socketha, &intrespons, sizeof(intrespons),MSG_WAITALL)) == -1) { perror("Cant recv respons"); return 0; } return 1; }
int net_socketSSL_flush(net_socketSSL_t* self) { assert(self); int flushed = 1; if((self->type == NET_SOCKETSSL_TCP_BUFFERED) && (self->buffer)) { flushed = sendall(self, self->buffer, self->len, 0); self->len = 0; } return flushed; }
static ssize_t sendToVICC(struct vicc_ctx *ctx, size_t length, const unsigned char* buffer) { ssize_t r; uint16_t size; if (!ctx || length > 0xFFFF) { errno = EINVAL; return -1; } /* send size of message on 2 bytes */ size = htons((uint16_t) length); r = sendall(ctx->client_sock, (void *) &size, sizeof size); if (r == sizeof size) /* send message */ r = sendall(ctx->client_sock, buffer, length); if (r < 0) vicc_eject(ctx); return r; }
int cmd_download(int argc, char* argv[]) { //check if eligible for download if(localInfo.isServer){ printf("Command Not Avaiable on Server\n"); return EINVAL; } if(argc < 3){ printf("Peer ID and Filename required\n"); return EINVAL; } printf("ARG COUNT %d\n", argc); if(argc % 2 == 0){ printf("Provide connection ID and fileName for every host\n"); return EINVAL; } int index = 1; char * filename; int socketfd; char message[MESSAGE]; //Loop for every pair [ID, FILENAME] //send request for file to each of listed hosts while(index < argc){ socketfd = getSocketFromList(atoi(argv[index])); if(socketfd == EINVAL){ printf("Upload Failed.\n"); return EINVAL; } filename = argv[index + 1]; //REQUEST file from remote host sprintf(message, "%d %s\n", REQUEST_FILE, filename); if(sendall(socketfd, message, sizeof(message)) == -1){ perror("UPLOAD: message "); return -1; } index += 2; } return 0; }
/** * @brief Processes commands from client shell and passes them to server_auth, server_get or server_set. * * @param sock The socket connected to the client. * @param cmd The command received from the client. * @return Returns 0 on success, 1 otherwise. */ int handle_command(int sock, char *cmd) { sprintf(log_buffer, "handle_command: Processing command '%s'\n", cmd); logger(server_log, log_buffer); // replace LOG commands with logger() calls char buf[MAX_CMD_LEN] = {0}; if(sscanf(cmd, "%s", buf) != 1) return 0; else if(strcmp(buf, "AUTH") == 0) server_auth(cmd); else if(strcmp(buf, "GET") == 0) { gettimeofday(&start_time, NULL); server_get(cmd); gettimeofday(&end_time, NULL); get_processing_time.tv_usec += (end_time.tv_sec - start_time.tv_sec)*1000000L + (end_time.tv_usec - start_time.tv_usec); fprintf(server_time_log, "get performed in %ld microseconds\n", (end_time.tv_sec - start_time.tv_sec)*1000000L + (end_time.tv_usec - start_time.tv_usec)); } else if(strcmp(buf, "SET") == 0) { gettimeofday(&start_time, NULL); server_set(cmd); gettimeofday(&end_time, NULL); set_processing_time.tv_usec += (end_time.tv_sec - start_time.tv_sec)*1000000L + (end_time.tv_usec - start_time.tv_usec); fprintf(server_time_log, "storage_set performed in %ld microseconds\n", (end_time.tv_sec - start_time.tv_sec)*1000000L + (end_time.tv_usec - start_time.tv_usec)); } else return 1; // Send back the response to the client. sendall(sock, cmd, strlen(cmd)); sendall(sock, "\n", 1); return 0; }
int main(int argc, char **argv) { struct addrinfo hints, *res; struct sockaddr_storage their_addr; socklen_t addr_size; char *listenport; int listenfd, connfd; char buf[1024]; size_t bytes; int yes; listenport = argv[1]; bzero(&hints, sizeof(hints)); hints.ai_family = AF_UNSPEC; hints.ai_socktype = SOCK_STREAM; hints.ai_flags = AI_PASSIVE; getaddrinfo(NULL, listenport, &hints, &res); listenfd = socket(res->ai_family, res->ai_socktype, res->ai_protocol); bind(listenfd, res->ai_addr, res->ai_addrlen); listen(listenfd, BACKLOG); printf("Waiting for connections...\n"); while (1) { addr_size = sizeof(their_addr); connfd = accept(listenfd, (struct sockaddr*)&their_addr, &addr_size); yes = 60; setsockopt(connfd, SOL_SOCKET, SO_RCVTIMEO, &yes, sizeof(int)); printf("got connection.\n"); if (!fork()) { close(listenfd); while ((bytes = recv(connfd, buf, sizeof(buf), 0))) { buf[bytes] = 0; sendall(connfd, buf, strlen(buf), 0); } close(connfd); exit(0); } close(connfd); } freeaddrinfo(res); close(listenfd); close(connfd); return 0; }
int rComand(char dest[], int LotNr,char subname[]) { int destLen; int socketha = conectTo(LotNr); //sender heder sendpacked(socketha,C_rComand,BLDPROTOCOLVERSION, 0, NULL,subname); //sender lotnr sendall(socketha,&LotNr, sizeof(LotNr)); destLen = strlen(dest) +1; // \0 //sender destinasjonsstring lengde sendall(socketha,&destLen, sizeof(destLen)); //sender destinasjon sendall(socketha,dest, destLen); return 1; }
int cmc_killcrawl(int socketha, int port) { int resp; sendpacked(socketha, cm_killcrawl, BLDPROTOCOLVERSION, 0, NULL, ""); if (sendall(socketha, &port, sizeof port) == 0) { perror("killcrawl sendall"); exit(1); } if (recv(socketha, &resp, sizeof resp, MSG_WAITALL) == -1) { perror("killcrawl recv"); return 0; } return resp; }
int bsQuery(int *sock, void *data, size_t data_size) { //printf("Sending %d\n", data_size); if (sock == 0) return 0; if (sendall(*sock, data, data_size) != data_size) { perror("sendall"); *sock = 0; return 0; } return 1; }
char *send_cmd(char *cmd) { struct addrinfo hints; struct addrinfo *result, *rp; int sfd, s, j; size_t len; ssize_t nread; //printf("cmd: %s\n", cmd); /* Obtain address(es) matching host/port */ memset(&hints, 0, sizeof(struct addrinfo)); hints.ai_family = AF_INET; hints.ai_socktype = SOCK_STREAM; hints.ai_flags = 0; s = getaddrinfo(IP, PORT, &hints, &result); if (s != 0) { //fprintf(stderr, "getaddrinfo: %s\n", gai_strerror(s)); return "getaddrinfo: fail"; } for (rp = result; rp != NULL; rp = rp->ai_next) { sfd = socket(rp->ai_family, rp->ai_socktype, rp->ai_protocol); if (sfd == -1) continue; if (connect(sfd, rp->ai_addr, rp->ai_addrlen) < 0) { close(sfd); continue; } break; /* Success */ } if (rp == NULL) { /* No address succeeded */ return "?Err?"; } freeaddrinfo(result); /* No longer needed */ /* Send command as message and wait for a response */ len = strlen(cmd); len++; // include ZERO terminator if (sendall(sfd, cmd, &len) == -1) { //fprintf(stderr, "partial/failed send. Only sent %d/%d\n", len, strlen(argv[i])); return "partial send"; } nread = recv(sfd, buf, BUF_SIZE, 0); buf[nread] = 0; // Always terminate close(sfd); return buf; }
int forward_client_to_service(struct ConnectionState *st) { char buf[4096]; int r = 1; int ret = SSL_read(st->ssl, buf, sizeof(buf)); int err = SSL_get_error(st->ssl, ret); switch (err) { case SSL_ERROR_NONE: { // fcntl(st->service_conn, F_SETFL, 0); assert(ret > 0); stats.up_bytes += ret; int status = sendall(st->service_conn, buf, ret); log_data(st, buf, ret); if (status < 0) { fprintf(stderr, "couldn't forward data to service\n"); cleanup_connection(st); return 0; } // fcntl(st->service_conn, F_SETFL, O_NONBLOCK); break; } case SSL_ERROR_ZERO_RETURN: case SSL_ERROR_WANT_CONNECT: case SSL_ERROR_WANT_ACCEPT: case SSL_ERROR_WANT_X509_LOOKUP: case SSL_ERROR_SYSCALL: case SSL_ERROR_SSL: if (err == SSL_ERROR_SSL) { extern BIO *bio_err; if (!bio_err) { bio_err=BIO_new_fp(stderr,BIO_NOCLOSE); } ERR_print_errors(bio_err); } else if (err == SSL_ERROR_SYSCALL) { // Socket closed cleanup_connection_after_ssl(st, 1); return 0; } cleanup_connection(st); r = 0; break; case SSL_ERROR_WANT_READ: case SSL_ERROR_WANT_WRITE: //fprintf(stderr, "Ignoring recoverable SSL error %d while forwarding to service\n", err); break; } return r; }
int bbdn_HasSufficientSpace(int socketha, char subname[]) { int intrespons = 0; int len, i; //sender heder sendpacked(socketha,bbc_HasSufficientSpace,BLDPROTOCOLVERSION, 0, NULL,""); //subname len = strlen(subname) +1; debug("sending (len %i): \"%s\"",len,subname); if(sendall(socketha,&len, sizeof(int)) == 0) { perror("sendall subname len"); return 1; } if(sendall(socketha,subname, len) == 0) { perror("sendall subname"); return 1; } if ((i=recv(socketha, &intrespons, sizeof(intrespons),MSG_WAITALL)) == -1) { bperror("Cant recv respons"); return 1; } return intrespons; }
int net_socketSSL_sendall(net_socketSSL_t* self, const void* data, int len) { assert(self); assert(data); int buffered = 0; if((self->type == NET_SOCKETSSL_TCP_BUFFERED) && (self->buffer)) { buffered = 1; } return sendall(self, data, len, buffered); }
off_t rGetFileSize(char source[], int LotNr,char subname[]) { int socketha = conectTo(LotNr); #ifdef DEBUG printf("rGetFileSize\n"); #endif int filnamelen; off_t i; off_t fileBloks; //sender heder sendpacked(socketha,C_rGetSize,BLDPROTOCOLVERSION, 0, NULL,subname); //sender lotnr sendall(socketha,&LotNr, sizeof(LotNr)); //sender filnavn lengde filnamelen = strlen(source) +1; // +1 for \0 sendall(socketha,&filnamelen, sizeof(filnamelen)); //sender hvilken fil vi vil ha sendall(socketha,source, filnamelen); //leser inn filstørelsen if ((i=recv(socketha, &fileBloks, sizeof(fileBloks),MSG_WAITALL)) == -1) { perror("rGetFileSize: Cant recv fileBloks"); exit(1); } return fileBloks; }
int sendErrorResponse( int sock, int code, char* data, int datalen ) { char* errorString; errorString = (char*)malloc( datalen + 32 ); memset( errorString, 0, datalen + 32 ); sprintf( errorString, "E %i ", code ); errorString[strlen(errorString) + datalen] = '\n'; memcpy( errorString + strlen(errorString), data, datalen ); if ( sendall( sock, errorString, strlen(errorString), 0 ) != strlen(errorString) ) { fprintf( stderr, "The data could not be send to the pc.\n" ); return -1; } }
VBool VSocket::ClearQueue() { if (sock==-1) return VFalse; if (queuebuffersize!=0) { //adzm 2010-08-01 m_LastSentTick = GetTickCount(); //adzm 2010-09 - return a bool in ClearQueue if (!sendall(sock,queuebuffer,queuebuffersize,0)) return VFalse; queuebuffersize=0; } GetOptimalSndBuf(); return VTrue; }
int cmc_collectionislocked(int socketha, char *collection_in) { char collection[64]; int r, i; strncpy(collection, collection_in, sizeof(collection)); sendpacked(socketha, cm_collectionislocked, BLDPROTOCOLVERSION, 0, NULL, ""); sendall(socketha, &collection, sizeof(collection)); if ((i=recv(socketha, &r, sizeof(r),MSG_WAITALL)) == -1) { return 1; } return r; }
/** * @brief performs a basic error check and after everything has passed, passes the information onto server via sendall * after the execution of this function, we will have the values found inside the table * @param table name of the table we want to get from * @param key name of the key * @param record is the struct holding the configuration parameters of everything inside the configuration file * @param conn a pointer to the connection status of the server * @return return 0 for success, -1 for failure */ int storage_get(const char *table, const char *key, struct storage_record *record, void *conn) { // if we have not Connected, do not execute. Also raise the error if (didConnect != 1){ errno = ERR_CONNECTION_FAIL; return -1; } if (didAuthenticate != 1){ errno = ERR_NOT_AUTHENTICATED; return -1; } if (table == NULL || conn == NULL ){ errno = ERR_INVALID_PARAM; return -1; } // parse the values to see if its correct if (tablecheck(table) == 1 || keycheck(key) == 1){ errno = ERR_INVALID_PARAM; return -1; } // Connection is really just a socket file descriptor. int sock = (int)conn; // Send some data. char buf[MAX_CMD_LEN]; memset(buf, 0, sizeof buf); snprintf(buf, sizeof buf, "GET %s %s\n", table, key); if (sendall(sock, buf, strlen(buf)) == 0 && recvline(sock, buf, sizeof buf) == 0) { if (strcmp("table_fail", buf)== 0){ errno = ERR_TABLE_NOT_FOUND; return -1; } else if (strcmp("key_fail", buf)== 0){ errno = ERR_KEY_NOT_FOUND; return -1; } strncpy(record->value, buf, sizeof record->value); didAuthenticate = 1; return 0; } return -1; }
void sendIPLIST() { if(!localInfo.isServer){ printf("Only Server Boradcasts IP LIST\n"); return; } if(head == NULL){ //nothing to send return; } printf("Broadcasting IP LIST to peers..\n"); //buffer that will hold entire connection list from server char ipList[MESSAGE]; char* scanner = ipList; int nbytes; //add message header nbytes = sprintf(scanner, "%d ", ADD_IP_LIST); scanner += nbytes; struct peer *list = head; while(list != NULL){ nbytes = sprintf(scanner, "%s %s %s ", list->hostname, list->ipaddr, list->port); scanner += nbytes; list = list->next; } //tag the end of the buffer sprintf(scanner, "EOF EOF EOF"); //reset pointer over list for sending list = head; //send IP LIST buffer to every socket listed while(list != NULL){ if(sendall(list->socket, ipList, sizeof(ipList)) == -1){ perror("sendIPLIST: send "); return; } list = list->next; } }
static void dump_processing(int sock) { uint32_t dropped = 0, encoded = 0; int im = 0, fl = 0, ex = 0; char buf[TC_BUF_LINE]; int n; dropped = tc_get_frames_dropped(); encoded = tc_get_frames_encoded(); tc_framebuffer_get_counters(&im, &fl, &ex); n = tc_snprintf(buf, sizeof(buf), "E=%lu|D=%lu|im=%i|fl=%i|ex=%i", encoded, dropped, im, fl, ex); if (n > 0) sendall(sock, buf, n); }
void PruebaCliente() { printf("Inicia main de un socket\n"); struct addrinfo hints, *res; int sockfd; memset(&hints, 0, sizeof hints); hints.ai_family = AF_UNSPEC; hints.ai_socktype = SOCK_STREAM; printf("Busca info del socket\n"); getaddrinfo("192.168.1.104", "7777", &hints, &res); printf("Obtenida info del socket\n"); sockfd = socket(res->ai_family, res->ai_socktype, res->ai_protocol); printf("Arme la estructura del socket\n"); connect(sockfd, res->ai_addr, res->ai_addrlen); printf("Me conecte\n"); unsigned int size = 1024; //Maximo char* buffer = malloc(size); int i; // Limpio el buffer cada vez que voy a leer for (i = 0; i < 1024; i++) { buffer[i] = '\0'; } struct Registration regn ; regn.clientPid = getpid(); strcpy(regn.multicastGroup, "Hola Victor!!!"); printf("PID:%d\n", regn.clientPid); printf("MG:%s\n", regn.multicastGroup); printf("Size:%d\n", sizeof(regn)); //Size is 28 char* data; data = (unsigned char*)malloc(sizeof(regn)); memcpy(data, ®n, sizeof(regn)); printf("Size:%d\n", sizeof(data)); printf("Llego a mandar el socket"); sendall(sockfd, data, sizeof(regn)); }
bool TCPSocket::send(Buffer *buffer) { int len = buffer->getlength(); printf("Attempting to send %i bytes.\n",len); int l = 0; /*if ((l = sendall(mysocket,(char*)&len,4)) != 4) { printf("error occurred while sending length. Only sent %i bytes\n",l); return false; }*/ if ((l = sendall(mysocket,buffer->getbytes(),buffer->getlength())) != buffer->getlength()) { printf("error occurred while sending data. Only sent %i bytes\n",l); return false; } return true; }
int boithoad_sidToGroup(char sid_in[], char username_in[]) { int socketha; int intresponse; char username[64]; char sid[512]; int forreturn = 0; //ToDo: strscpy strncpy(sid,sid_in,sizeof(sid)); if ((socketha = cconnect("localhost", BADPORT)) == 0) { return 0; } sendpacked(socketha,bad_sidToGroup,BADPROTOCOLVERSION, 0, NULL,""); sendall(socketha, sid, sizeof(sid)); //read respons if (!recvall(socketha,&intresponse,sizeof(intresponse))) { return 0; } if (intresponse == 1) { if (!recvall(socketha,username,sizeof(username))) { return 0; } strcpy(username_in, username); forreturn = 1; } else { #ifdef DEBUG printf("didn't have a group at %s:%d\n",__FILE__,__LINE__); #endif strcpy(username_in,""); forreturn = 0; } close(socketha); return forreturn; }
static bool wsgi_sendheaders(Request* request) { char buf[1024*4]; size_t bufpos = 0; #define buf_write(src, len) \ do { \ size_t n = len; \ const char* s = src; \ while(n--) buf[bufpos++] = *s++; \ } while(0) buf_write("HTTP/1.0 ", strlen("HTTP/1.0 ")); buf_write(PyString_AS_STRING(request->status), PyString_GET_SIZE(request->status)); size_t n_headers = PyList_GET_SIZE(request->headers); for(size_t i=0; i<n_headers; ++i) { PyObject* tuple = PyList_GET_ITEM(request->headers, i); assert(tuple); TYPECHECK(tuple, PyTuple, "headers", true); if(PyTuple_GET_SIZE(tuple) < 2) { PyErr_Format( PyExc_TypeError, "headers must be tuples of length 2, not %zd", PyTuple_GET_SIZE(tuple) ); return true; } PyObject* field = PyTuple_GET_ITEM(tuple, 0); PyObject* value = PyTuple_GET_ITEM(tuple, 1); TYPECHECK(field, PyString, "header tuple items", true); TYPECHECK(value, PyString, "header tuple items", true); buf_write("\r\n", strlen("\r\n")); buf_write(PyString_AS_STRING(field), PyString_GET_SIZE(field)); buf_write(": ", strlen(": ")); buf_write(PyString_AS_STRING(value), PyString_GET_SIZE(value)); } buf_write("\r\n\r\n", strlen("\r\n\r\n")); return !sendall(request, buf, bufpos); }
void enviar_pcb_a_planificador(int fd, int id_proceso) { // typedef struct { // int id_proceso; // int ultima_sentencia; // int motivo; // 0: error, 1: finalizo, 2: termino rafaga, 3: termino E/S, 4: bloqueado // int sleep; // int mensaje_long; // char* mensaje; // } t_msg_a_planificador; printf("Trato de enviar el PCB al planificador, fd: %i, mProc ID: %i", fd, id_proceso); t_msg_a_planificador* msg_a_enviar = malloc(sizeof(t_msg_a_planificador)); msg_a_enviar->id_proceso = id_proceso; msg_a_enviar->ultima_sentencia = 3; msg_a_enviar->motivo = 2; msg_a_enviar->sleep = 2; msg_a_enviar->mensaje = "Prueba de mensaje desde la CPU"; msg_a_enviar->mensaje_long = strlen(msg_a_enviar->mensaje) + 1; int length = sizeof(int) + sizeof(int) + sizeof(int) + sizeof(int) + sizeof(int) + msg_a_enviar->mensaje_long; printf("[CPU] Envio el nuevo pcb con ID: %i\n", msg_a_enviar->id_proceso); printf("[CPU] Envio el nuevo pcb con ultima_sentencia: %i\n", msg_a_enviar->ultima_sentencia); printf("[CPU] Envio el nuevo pcb con motivo: %i\n", msg_a_enviar->motivo); printf("[CPU] Envio el nuevo pcb con sleep: %i\n", msg_a_enviar->sleep); printf("[CPU] Envio el nuevo pcb con mensaje_long: %i\n", msg_a_enviar->mensaje_long); printf("[CPU] Envio el nuevo pcb con mensaje: %s\n", msg_a_enviar->mensaje); printf("[CPU] El tamaño de lo que voy a enviar es: %i\n", length); void* buffer = malloc(length); memcpy(buffer, &(msg_a_enviar->id_proceso), sizeof(int)); memcpy(buffer + 4, &(msg_a_enviar->ultima_sentencia), sizeof(int)); memcpy(buffer + 8, &(msg_a_enviar->motivo), sizeof(int)); memcpy(buffer + 12, &(msg_a_enviar->sleep), sizeof(int)); memcpy(buffer + 16, &(msg_a_enviar->mensaje_long), sizeof(int)); strcpy(buffer + 20, msg_a_enviar->mensaje); sendall(fd, buffer, length); free(buffer); free(msg_a_enviar); }
int bbdn_conect(int *socketha, char tkey[], int PORT) { int intrespons; int i; if (((*socketha) = cconnect("127.0.0.1", PORT)) == 0) { bperror("Can't connect to back-end document manager"); return 0; } //sender heder sendpacked((*socketha),bbc_askToAuthenticate,BLDPROTOCOLVERSION, 0, NULL,""); if (!sendall((*socketha),tkey, 32)) { bperror("sendall"); goto bbdn_conect_err; } if ((i=recv((*socketha), &intrespons, sizeof(intrespons),MSG_WAITALL)) == -1) { bperror("Cant recv respons"); goto bbdn_conect_err; } if (intrespons == bbc_authenticate_ok) { debug("bbc authenticate ok\n"); return 1; } else if (intrespons == bbc_authenticate_feiled) { berror("bbc authenticate feiled"); goto bbdn_conect_err; } else { berror("respons from server was nider bbc_authenticate_feiled or bbc_authenticate_ok!\n"); goto bbdn_conect_err; } bbdn_conect_err: close(*socketha); return 0; }
void showRank(int clientfd, char user[MAXNAMELEN]) { unsigned char buffer[1024]; DATA data; FILE *fp,*fp2; char users[MAXRANKING][MAXNAMELEN], name[MAXNAMELEN]; int pos[MAXRANKING]; int count=0,i,j,k,temp,userRank; fp = fopen("allusers.txt","r"); //Read user data while (!feof(fp)) { fscanf(fp,"%s",name); if (feof(fp)) break; strcpy(users[count],name); fp2 = fopen(name,"rb"); fread(&data, sizeof(data), 1, fp2); pos[count] = data.win; fclose(fp2); ++count; }; fclose(fp); //Sort data for (i=0; i<count-1; ++i) for (j=i+1; j<count; ++j) if (pos[i]<pos[j]) { strcpy(name,users[i]); strcpy(users[i],users[j]); strcpy(users[j],name); temp = pos[i]; pos[i] = pos[j]; pos[j] = temp; } //Find user's rank for (k=0; k<count; ++k) if (strcmp(users[k],user)==0) { userRank = k+1; break; } if (count>5) count = 5; size_t packetsize= pack(buffer, "lllslslslslsl", 5, userRank, count, users[0],pos[0], users[1],pos[1], users[2],pos[2], users[3],pos[3], users[4],pos[4]); sendall(clientfd,buffer,&packetsize); }
int boithoad_getPassword(const char username_in[], char password_in[]) { int socketha; int intresponse; char username[64]; char password[64]; int forreturn = 0; //ToDo: strscpy strncpy(username,username_in,sizeof(username)); if ((socketha = cconnect("localhost", BADPORT)) == 0) { return 0; } sendpacked(socketha,bad_getPassword,BADPROTOCOLVERSION, 0, NULL,""); sendall(socketha,username, sizeof(username)); //read respons if (!recvall(socketha,&intresponse,sizeof(intresponse))) { return 0; } if (intresponse == 1) { if (!recvall(socketha,password,sizeof(password))) { return 0; } //printf("got \"%s\"\n",password); strcpy(password_in,password); forreturn = 1; } else { printf("dident have a passord at %s:%d\n",__FILE__,__LINE__); strcpy(password_in,""); forreturn = 0; } close(socketha); return forreturn; }
void BTest::send(CkReductionMsg *msg) { delete msg; if (thisIndex==0) CkPrintf("[%2d] totaltime with '%s' = %f\n",CmiMyPe(),conversion[type],(CmiWallTimer()-startTime)/(MAX_ITER-threshold_msgs)); if (++type==MAX_TYPE) { if (++length==MAX_LENGTH) { mainProxy.exit(); } else { type = 0; sendall(); //contribute(0, &count, CkReduction::sum_int, cball); } } else { //totalTime=0; //startTime = CmiWallTimer(); if (thisIndex==0) send(); //contribute(0, &count, CkReduction::sum_int, cb); } }