# -*- coding: cp1253 -*- import sys #Επιλογή είδους ζητουμένου print 'Επέλεξε τι θέλεις δίνοντας:' print '1 για Συνολικό Μήκος και Μήκος Επικεφαλίδας' print '2 για Μήκος Δεδομένων και Μήκος Επικεφαλίδας' epil=input() while epil!=1 and epil!=2: print 'Δώσε 1 ή 2: ' epil=input() if epil==1: print 'Δώσε Συνολικό Μήκος (σε bytes)' syn_mikos=input() print 'Δώσε Μήκος Επικεφαλίδας (σε 4άδες bytes)' ihl=input() mikos_dedom = syn_mikos - ihl*4 else: print 'Δώσε Μήκος Δεδομένων (σε bytes)' mikos_dedom=input() print 'Δώσε Μήκος Επικεφαλίδας (σε 4άδες bytes)' ihl=input() syn_mikos= mikos_dedom + ihl*4 print 'Δώσε MTU (σε bytes)' mtu=input() mikos_dedom_mtu = mtu - ihl*4 print 'Δώσε DF (0 ή 1)' df=input() if (mikos_dedom_mtu >= mikos_dedom): print 'Δεν απαιτείται κατάτμηση (το αρχ. πακέτο χωράει στο πλαίσιο)!' sys.exit() if (df==1): print 'Δεν επιτρέπεται κατάτμηση (DF=1)!' sys.exit() #Υπολογισμός payload length σε οκτάδες bytes και σε bytes payload_length_oktades = int((mtu-ihl*4)/8) payload_length_bytes = payload_length_oktades * 8 #Υπολογισμός αριθμού τμημάτων arithmos_tmimatwn = mikos_dedom/float(payload_length_bytes) #print 'int((mtu-ihl*4)/8) :', int((mtu-ihl*4)/8) #print 'διαίρεση: ', mikos_dedom/float(payload_length_bytes) #print 'Αποτέλεσμα :', arithmos_tmimatwn if (arithmos_tmimatwn > int(mikos_dedom/payload_length_bytes)): arithmos_tmimatwn = int(arithmos_tmimatwn)+1 else: arithmos_tmimatwn = int(arithmos_tmimatwn) for i in range(0, arithmos_tmimatwn): print 'Τμήμα ', i print ' IHL : ', ihl if (i==arithmos_tmimatwn-1): print ' Συν. Μήκος : ', mikos_dedom-((arithmos_tmimatwn-1)*payload_length_bytes)+ihl*4 print ' Μήκος Δεδ. : ', mikos_dedom-((arithmos_tmimatwn-1)*payload_length_bytes) else: print ' Συν. Μήκος : ', payload_length_bytes+ihl*4 print ' Μήκος Δεδ. : ', payload_length_bytes print ' Πεδίο Αναγν. : Το ίδιο με το αρχικό' print ' DF : 0' if (i==arithmos_tmimatwn-1): print ' MF : 0' else: print ' MF : 1' print ' Σχ. Θέση Τμήμ. : ', payload_length_oktades *i