'IDE does not recognize inet_pton
I am trying to write a simple-ish TCP client in C++. I was following this guide and this is the short code I have so far:
main.cpp:
#include "messenger.h"
#ifndef _WIN32_WINNT
#define _WIN32_WINNT 0x0600
#endif
#include <winsock2.h>
#pragma comment (lib, "Ws2_32.lib")
int main()
{
WSADATA d;
if (WSAStartup(MAKEWORD(2, 2), &d)) {
perror("Failed to initialize.\n");
}
Messenger::connect();
WSACleanup();
return 0;
}
`messenger.h':
class Messenger {
public:
static void connect();
...
}
and messenger.cpp:
#include "messenger.h"
#include <stdio.h>
#include <stdlib.h>
#include <string>
#include <unistd.h>
#include <winsock2.h>
#include <wspiapi.h>
#include <Ws2tcpip.h>
#pragma comment(lib, "ws2_32.lib")
using namespace std::chrono_literals;
#define IP "192.168.0.99"
#define PORT 3030
SOCKET prop_socket = INVALID_SOCKET;
std::thread Messenger::receive_thread;
void Messenger::connect() {
setup();
receive_thread = std::thread{listen_for_messages};
}
void PropulsionMessenger::setup() {
std::string ipAddress = IP;
sockaddr_in hint;
ZeroMemory( &hint, sizeof(hint) );
hint.sin_family = AF_INET;
hint.sin_port = htons(PORT);
inet_pton(AF_INET, ipAddress.c_str(), &hint.sin_addr);
}
...
However CLion highlights inet_pton and tells me that Use of undeclared identifier 'inet_pton'. I believe all of the fields are filled with the correct data types and I have all of the required header files. I get no other errors.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
