| 14 | namespace osidbg |
| 15 | { |
| 16 | DebugInterface::DebugInterface(uint16_t port) |
| 17 | : port_(port) |
| 18 | { |
| 19 | WSADATA wsaData; |
| 20 | WSAStartup(MAKEWORD(2, 2), &wsaData); |
| 21 | |
| 22 | uint32_t ip; |
| 23 | inet_pton(AF_INET, "127.0.0.1", &ip); |
| 24 | socket_ = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP); |
| 25 | sockaddr_in addr; |
| 26 | addr.sin_family = AF_INET; |
| 27 | addr.sin_addr.S_un.S_addr = ip; |
| 28 | addr.sin_port = htons(port_); |
| 29 | if (bind(socket_, (sockaddr *)&addr, sizeof(addr)) != 0) { |
| 30 | Debug("Could not bind debugger server socket: %d", WSAGetLastError()); |
| 31 | Fail("Debug server start failed"); |
| 32 | } |
| 33 | |
| 34 | if (listen(socket_, 30) != 0) { |
| 35 | Debug("Could not listen on server socket: %d", WSAGetLastError()); |
| 36 | Fail("Debug server start failed"); |
| 37 | } |
| 38 | |
| 39 | Debug("Debug interface listening on 127.0.0.1:%d; DBG protocol version %d", port_, DebugMessageHandler::ProtocolVersion); |
| 40 | } |
| 41 | |
| 42 | DebugInterface::~DebugInterface() |
| 43 | { |