本文介绍了inet_ntop和inet_pton未定义的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Windows 7,并且inet_ntop和inet_pton出现问题,这似乎是针对linux的.我将在Windows中使用什么?

I''m using windows 7 and have a problem with inet_ntop and inet_pton, this seems to be for linux. What would I use for windows?

#include "stdafx.h"
#include <iostream>
#include <string>
#include <sstream>
#include 
#include <winsock2.h>

#pragma comment( lib,"Advapi32.lib" ) //Reg
#pragma comment( lib, "ws2_32.lib" ) // linker must use this lib for sockets
using namespace std;

void BuildHeader(stringstream &hdr, const string &payload, const sockaddr_in *remoteServer)
{
    char buf[16] = { 0 };
    hdr << "POST /login.jsp HTTP/1.1\r\n";
    hdr << "Host: " << inet_ntop(AF_INET,
                                 (const void *)&remoteServer->sin_addr,
                                 buf,
                                 sizeof(buf)) << "\r\n";
    hdr << "Content-Length: " << payload.size() << "\r\n";
    hdr << "Content-Type: text/html; charset=ISO-8859-4\r\n\r\n";
}

int main(void)
{
    sockaddr_in sa;
    inet_pton(AF_INET, "127.0.0.1", &(sa.sin_addr));
    stringstream ss;
    BuildHeader(ss, "<payload></payload>", &sa);

    cout << ss.str();
    return 0;
}</winsock2.h></sstream></string></iostream>

推荐答案


这篇关于inet_ntop和inet_pton未定义的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-23 13:04