Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions .github/workflows/build-and-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ on:
workflow_dispatch:

env:
NS3_VER: "3.46"
NS3_VER: "3.48"

jobs:
build:
Expand All @@ -18,8 +18,6 @@ jobs:
fail-fast: false
matrix:
include:
- distro: ubuntu-22.04
image: ubuntu:22.04
- distro: ubuntu-24.04
image: ubuntu:24.04
- distro: debian-trixie
Expand Down
2 changes: 1 addition & 1 deletion helper/dce-manager-helper.cc
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
#include "ipv4-linux.h"
#include "dce-application-helper.h"
#include "ns3/ipv4-routing-protocol.h"
#include "ns3/ipv4-global-routing.h"
#include "ns3/global-routing.h"
#include <stdlib.h>
#include <stdio.h>
#include <limits.h>
Expand Down
16 changes: 14 additions & 2 deletions model/dce-stdio.cc
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#include <sys/mman.h>
#include <string.h>
#include <cstdarg>
#include <map>

NS_LOG_COMPONENT_DEFINE ("DceStdio");

Expand Down Expand Up @@ -171,6 +172,10 @@ FILE * dce_fdopen (int fildes, const char *mode)
fp->_fileno = fildes;
FILE *file = fopencookie(fp, mode, my_func);
current->process->openStreams.push_back (file);
if (file != 0)
{
current->process->openStreamFds[file] = fildes;
}
dce_fseek (file, dce_lseek (fildes, 0, SEEK_CUR), SEEK_SET);

return file;
Expand Down Expand Up @@ -278,6 +283,7 @@ remove_stream (FILE *fp)
{
Thread *current = Current ();
bool found = false;
current->process->openStreamFds.erase (fp);
for (std::vector<FILE*>::iterator i = current->process->openStreams.begin ();
i != current->process->openStreams.end (); ++i)
{
Expand Down Expand Up @@ -422,8 +428,14 @@ int dce_fileno (FILE *stream)
return 2;
}

// FIXME: Handle fopencookie things to. We need to detect those FILE*
// and return cookie->_fileno instead... But how?
// For fopencookie-backed streams, return the mapped DCE fd instead of the
// libc fileno() (which would return -1 since they have no real fd).
std::map<FILE *, int>::const_iterator it =
current->process->openStreamFds.find (stream);
if (it != current->process->openStreamFds.end ())
{
return it->second;
}

int status = fileno (stream);
if (status == -1)
Expand Down
2 changes: 1 addition & 1 deletion model/freebsd/ipv4-freebsd.cc
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
#include "ns3/ipv4-static-routing-helper.h"
#include "ns3/ipv4-global-routing-helper.h"
#include "ns3/ipv4-interface.h"
#include "ns3/ipv4-global-routing.h"
#include "ns3/global-routing.h"
#include "ns3/ipv4-routing-table-entry.h"
#include "dce-application-helper.h"
#include "freebsd-socket-fd-factory.h"
Expand Down
2 changes: 1 addition & 1 deletion model/linux/ipv4-linux.cc
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
#include "ns3/ipv4-static-routing-helper.h"
#include "ns3/ipv4-global-routing-helper.h"
#include "ns3/ipv4-interface.h"
#include "ns3/ipv4-global-routing.h"
#include "ns3/global-routing.h"
#include "ns3/ipv4-routing-table-entry.h"
#include "linux-stack-helper.h"
#include "linux-ipv4-raw-socket-factory-impl.h"
Expand Down
1 change: 1 addition & 0 deletions model/process.h
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ struct Process
// Key is the fd
std::map<int,FileUsage *> openFiles;
std::vector<FILE *> openStreams;
std::map<FILE *, int> openStreamFds; // Maps a fopencookie-backed stream to its DCE fd.
std::vector<DIR *> openDirs;
std::vector<SignalHandler> signalHandlers;
std::vector<Thread *> threads;
Expand Down
2 changes: 1 addition & 1 deletion netlink/netlink-socket-address.cc
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ bool NetlinkSocketAddress::IsMatchingType (const Address &address)

uint8_t NetlinkSocketAddress::GetType (void)
{
static uint8_t type = Address::Register ();
static uint8_t type = Address::Register ("NetlinkSocketAddress", 8);
return type;
}

Expand Down
44 changes: 44 additions & 0 deletions test/test-iostream.cc
Original file line number Diff line number Diff line change
@@ -1,8 +1,19 @@
#include <sstream>
#include <fstream>
#include <string>
#include <ios>
#include <unistd.h>
#include "test-macros.h"

static std::string
read_whole_file (const char *path)
{
std::ifstream ifs (path);
std::ostringstream oss;
oss << ifs.rdbuf ();
return oss.str ();
}

template<typename T>
static std::string
to_string_via_ostream (T value)
Expand Down Expand Up @@ -43,5 +54,38 @@ main (int argc, char *argv[])
TEST_ASSERT_EQUAL (oss.str (), std::string ("value=42 done"));
}

// std::ofstream: write to a file, close, read it back.
{
const char *path = "iostream-test.out";
unlink (path);

std::ofstream ofs;
ofs.open (path);
TEST_ASSERT (ofs.is_open ());
TEST_ASSERT (ofs.good ());
TEST_ASSERT ((bool) ofs);

ofs << "line1=" << 1 << "\n";
ofs << "pi=" << 3.5 << "\n";
ofs << "hex=" << std::hex << std::showbase << 255 << "\n";
TEST_ASSERT (ofs.good ());
ofs.close ();
TEST_ASSERT (!ofs.fail ());

std::string contents = read_whole_file (path);
TEST_ASSERT_EQUAL (contents, std::string ("line1=1\npi=3.5\nhex=0xff\n"));

unlink (path);
}

// std::ofstream opening a path that cannot be created must report failure.
{
std::ofstream bad;
bad.open ("no-such-dir/definitely-missing/status.new");
TEST_ASSERT (!bad);
TEST_ASSERT (bad.fail ());
bad.close ();
}

return 0;
}