Records the interface into the output file.
121 throw cRuntimeError(
"Cannot write interface: pcap output file is not open");
123 std::string name = networkInterface->getInterfaceName();
124 std::string fullPath = networkInterface->getInterfaceFullPath();
125 fullPath = fullPath.substr(fullPath.find(
'.') + 1);
126 uint32_t optionsLength = (4 +
roundUp(name.length())) + (4 +
roundUp(fullPath.length())) + (4 + 8) + (4 + 4 + 4) + 4;
127 uint32_t blockTotalLength = 20 + optionsLength;
128 ASSERT(blockTotalLength % 4 == 0);
131 pcapng_interface_block_header ibh;
132 ibh.blockTotalLength = blockTotalLength;
133 ibh.linkType = linkType;
136 fwrite(&ibh,
sizeof(ibh), 1,
dumpfile);
139 pcapng_option_header doh;
141 doh.length = name.length();
142 fwrite(&doh,
sizeof(doh), 1,
dumpfile);
143 fwrite(name.c_str(), name.length(), 1,
dumpfile);
144 char padding[] = { 0, 0, 0, 0 };
145 int paddingLength = pad(name.length());
146 fwrite(padding, paddingLength, 1,
dumpfile);
150 doh.length = fullPath.length();
151 fwrite(&doh,
sizeof(doh), 1,
dumpfile);
152 fwrite(fullPath.c_str(), fullPath.length(), 1,
dumpfile);
153 paddingLength = pad(fullPath.length());
154 fwrite(padding, paddingLength, 1,
dumpfile);
159 fwrite(&doh,
sizeof(doh), 1,
dumpfile);
160 uint8_t macAddressBytes[6];
161 networkInterface->getMacAddress().getAddressBytes(macAddressBytes);
162 fwrite(macAddressBytes, 6, 1,
dumpfile);
168 fwrite(&doh,
sizeof(doh), 1,
dumpfile);
169 uint8_t ipAddressBytes[4];
170 auto ipv4Address = networkInterface->getIpv4Address();
171 for (
int i = 0; i < 4; i++) ipAddressBytes[i] = ipv4Address.getDByte(i);
172 fwrite(ipAddressBytes, 4, 1,
dumpfile);
173 auto ipv4Netmask = networkInterface->getIpv4Netmask();
174 for (
int i = 0; i < 4; i++) ipAddressBytes[i] = ipv4Netmask.getDByte(i);
175 fwrite(ipAddressBytes, 4, 1,
dumpfile);
178 uint32_t endOfOptions = 0;
179 fwrite(&endOfOptions,
sizeof(endOfOptions), 1,
dumpfile);
182 pcapng_interface_block_trailer ibt;
183 ibt.blockTotalLength = blockTotalLength;
184 fwrite(&ibt,
sizeof(ibt), 1,
dumpfile);