// Simulate a fragmentation algorithm // frag Omtu [Ihdrsz] // Barney Wolff 12/4/03 // Copyright (c) Databus Inc. Free to use with attribution. #include #include using namespace std; int main(int argc, char **argv) { int Ihdrsz=20, Omtu, MinIpaysz, MaxIpaysz, Opaylst, Opaysz; switch (argc) { default: cerr << "Usage: frag-alg Omtu [Ihdrsz]\n"; exit(1); case 3: Ihdrsz = atoi(argv[2]); case 2: Omtu = atoi(argv[1]); } MinIpaysz = Omtu - 1 - Ihdrsz; MaxIpaysz = 65535 - Ihdrsz; Opaylst = Omtu - Ihdrsz; Opaysz = Opaylst & 0xfff8; cout << "Output MTU " << Omtu << " Input header size " << Ihdrsz << endl; cout << "Max payload of last packet: "< Ipaysz) Opayn -= ((Maxin - Ipaysz) / Nfrag) & 0xfff8; Lastsz = Ipaysz - (Nfrag-1) * Opayn; Delta = Opayn - Lastsz; if (Delta >= 8) { int Nfrag2 = Delta / 8; Nfrag -= Nfrag2; Lastsz += 8 * Nfrag2; cout << " " << Nfrag2 << " " << Opayn-8+Ihdrsz; } if (Nfrag > 1) cout << " " << Nfrag-1 << " " << Opayn+Ihdrsz; cout << " " << Lastsz+Ihdrsz; if (Lastsz-Opayn>8 || Opayn-Lastsz>8) cout << " *"; cout << endl; } exit(0); }