#include "base/misc.hh"
#include "base/types.hh"
+#include "sim/byteswap.hh"
using namespace std;
bool ListenSocket::listeningDisabled = false;
bool ListenSocket::anyListening = false;
+bool ListenSocket::bindToLoopback = false;
+
void
ListenSocket::disableAll()
{
return listeningDisabled;
}
+void
+ListenSocket::loopbackOnly()
+{
+ if (anyListening)
+ panic("Too late to bind to loopback, already have a listener");
+ bindToLoopback = true;
+}
+
////////////////////////////////////////////////////////////////////////
//
//
struct sockaddr_in sockaddr;
sockaddr.sin_family = PF_INET;
- sockaddr.sin_addr.s_addr = INADDR_ANY;
+ sockaddr.sin_addr.s_addr =
+ htobe<unsigned long>(bindToLoopback ? INADDR_LOOPBACK : INADDR_ANY);
sockaddr.sin_port = htons(port);
// finally clear sin_zero
memset(&sockaddr.sin_zero, 0, sizeof(sockaddr.sin_zero));
static bool listeningDisabled;
static bool anyListening;
+ static bool bindToLoopback;
+
public:
static void disableAll();
static bool allDisabled();
+ static void loopbackOnly();
+
protected:
bool listening;
int fd;