int main(int argc, char *argv[]) { IP4_init(argc, argv); struct udp_metadata_parsed meta; struct finsFrame* pff; struct finsFrame ff; unsigned char str[] = "00000000ALEX"; ff.dataFrame.pdu = &str[0]; meta.u_IPdst = IP4_ADR_P2N(171,2,14,100); meta.u_IPsrc = IP4_ADR_P2N(153,18,8,105); meta.u_destPort = 13; meta.u_srcPort = 1087; ff.dataFrame.pduLength = 4; ff.dataOrCtrl = DATA; ff.destinationID = UDPID; ff.dataFrame.directionFlag = DOWN; memcpy(&ff.dataFrame.metaData, &meta, 16); udp_out_fdf(&ff); return EXIT_SUCCESS; }
void udp_get_ff(struct fins_module *module) { struct finsFrame *ff; do { secure_sem_wait(module->event_sem); secure_sem_wait(module->input_sem); ff = read_queue(module->input_queue); sem_post(module->input_sem); } while (module->state == FMS_RUNNING && ff == NULL); //TODO change logic here, combine with switch_to_udp? if (module->state != FMS_RUNNING) { if (ff != NULL) { freeFinsFrame(ff); } return; } if (ff->metaData == NULL) { PRINT_ERROR("Error fcf.metadata==NULL"); exit(-1); } if (ff->dataOrCtrl == FF_CONTROL) { udp_fcf(module, ff); PRINT_DEBUG(""); } else if (ff->dataOrCtrl == FF_DATA) { if (ff->dataFrame.directionFlag == DIR_UP) { udp_in_fdf(module, ff); PRINT_DEBUG(""); } else if (ff->dataFrame.directionFlag == DIR_DOWN) { udp_out_fdf(module, ff); PRINT_DEBUG(""); } else { PRINT_ERROR("todo error"); exit(-1); } } else { PRINT_ERROR("todo error: dataOrCtrl=%u", ff->dataOrCtrl); exit(-1); } }
/* udp_out test */ int main(int argc, char *argv[]) { struct udp_metadata_parsed meta; struct finsFrame* pff; struct finsFrame ff; unsigned short checksum = 0; IP4_init(argc, argv); char str[20] = "TESTING"; ff.dataFrame.pdu = &str[0]; meta.u_IPdst = IP4_ADR_P2N(192,168,1,28); meta.u_IPsrc = IP4_ADR_P2N(192,168,1,28); meta.u_destPort = 13; meta.u_srcPort = 1087; ff.dataFrame.pduLength = 7; ff.dataOrCtrl = DATA; ff.destinationID = UDPID; ff.dataFrame.directionFlag = DOWN; memcpy(&ff.dataFrame.metaData, &meta, 16); pff = &ff; // printf("The metadata's value for the length is %d\n", pseudoheader2.u_pslen); // printf("The UDP packet's value for the length is %d\n", packet2.u_len); /* Time to split into two processes * 1) the child Process is for capturing (incoming) * 2) the parent process is for injecting frames (outgoing) */ /* inject handler is initialized earlier to make sure that forwarding * feature is able to work even if the parent process did not start injecting yet */ inject_init(); pid_t pID = fork(); int status; if (pID == 0) // child { // Code only executed by child process /* PRINT_DEBUG("child started to capture"); capture_init(); pcap_close ( capture_handle ); */ } else if (pID < 0) // failed to fork { PRINT_DEBUG("\n Error while forking, program will exit"); exit(1); // Throw exception } else // parent { // Code only executed by parent process PRINT_DEBUG("parent started to inject"); int i=0; for ( i=0; i< 20; i++ ) { sleep(1); PRINT_DEBUG("#%d",i); udp_out_fdf(pff); PRINT_DEBUG("UDP done"); } /* terminate the wifi module */ wifi_terminate(); /* wait until the child return */ wait(&status); if (WIFEXITED(status)) { PRINT_DEBUG("Parent: child has exited normally with status %d", WEXITSTATUS(status)); } else { PRINT_DEBUG("Parent: child has not terminated normally"); } } return (0); }