winsock2

How to get domain name from Given IP in MFC (VC++)?

一笑奈何 提交于 2019-12-11 23:06:39
问题 How to get domain name from Given IP in MFC (VC++) ? The code i am using is as below: #include "stdafx.h" #include <winsock2.h> #include <ws2tcpip.h> #include <stdio.h> // link with ws2_32.lib #pragma comment(lib, "Ws2_32.lib") int _tmain(int argc, char **argv) { //----------------------------------------- // Declare and initialize variables WSADATA wsaData = {0}; int iResult = 0; DWORD dwRetval; struct sockaddr_in saGNI; char hostname[NI_MAXHOST]; char servInfo[NI_MAXSERV]; u_short port =

InetNtop and ws2tcpip.h under GCC / Cygwin

*爱你&永不变心* 提交于 2019-12-11 17:49:04
问题 I'm using the version of ws2tcpip.h provided with gcc 3.4.4 under cygwin 2.774 I was looking up the InetNtop function, which is Microsoft's implementation of inet_ntop , however the two versions of ws2tcpip.h I found don't contain that function. Including arpa/inet.h to get inet_ntop causes all sorts of terrible to happen with overlapping definitions. Is there a reason that the versions provided with gcc / cygwin don't have this function? Is there a (legal?) way get the version from Microsoft

How to Destroy a thread object [duplicate]

柔情痞子 提交于 2019-12-11 17:36:42
问题 This question already has answers here : How do I terminate a thread in C++11? (5 answers) Closed 2 years ago . I am writing a C++ based multithreaded chat server. When a new client joins, the main thread creates a new thread to manage the client. I want to destroy the thread when the client disconnects, so I properly setup this functionality, such that when the client sends an exit message Terminate() is called. But Terminate(), instead of destroying just the single thread, it destroyed all

Calling WinSock functions using LoadLibrary and GetProcAddress

主宰稳场 提交于 2019-12-11 07:09:25
问题 Basically I have a header file like this: #if WIN32 typedef DWORD (WSAAPI *SocketStartup) (WORD wVersionRequested, LPWSADATA lpWSAData); typedef SOCKET (WINAPI *MakeSocket)(IN int af, IN int type, IN int protocol, IN LPWSAPROTOCOL_INFOW lpProtocolInfo, IN GROUP g, IN DWORD dwFlags ); typedef DWORD (WINAPI *SocketSendFunc) (IN SOCKET s,__in_bcount(len) const char FAR * buf, IN int len,IN int flags); typedef DWORD (WINAPI *GetLastSocketErrorFunc)(); typedef DWORD (WINAPI *ShutdownSocketFunc)

Converting bytes to uint32 in C

不羁岁月 提交于 2019-12-11 04:39:36
问题 I'm continuously sending arrays of pixel values (uint32) from LabVIEW to a C-program through TCP/IP. I'm using the recv function in Ws2_32.lib to receive the bytes, but I have to convert them back to uint32 data type and doesn't really know how to do it in this case. I'll be thankful if anyone shows how to do it. Thanks in advance #define DEFAULT_BUFLEN 256 #include<stdio.h> #include<winsock2.h> #pragma comment(lib,"ws2_32.lib") //Winsock Library int main(int argc , char *argv[]) { WSADATA

tokenizing a string of data into a vector of structs?

痞子三分冷 提交于 2019-12-11 00:14:00
问题 So I have the following string of data, which is being received through a TCP winsock connection, and would like to do an advanced tokenization, into a vector of structs, where each struct represents one record. std::string buf = "44:william:adama:commander:stuff\n33:luara:roslin:president:data\n" struct table_t { std::string key; std::string first; std::string last; std::string rank; std::additional; }; Each record in the string is delimited by a carriage return. My attempt at splitting up

boost::asio::io_service crash in win_mutex lock

回眸只為那壹抹淺笑 提交于 2019-12-10 17:28:40
问题 I've been having a problem with boost::asio where timer and/or sockets created using a global io_service instance crash during construction. The system where the crash occurs is as follows: Windows 7 Visual Studio 2013 Express for Windows Desktop; v 12.0.31101.00 Update 4 Boost 1.57, dynamically linked, compiled with multithreading as, e.g. boost_thread-vc120-mt-gd-1_57.dll I've been able to replicate the issue in the following simplified code: // file global_io_service.h #ifndef INCLUDED

Are close() and closesocket() interchangable?

ⅰ亾dé卋堺 提交于 2019-12-10 03:34:18
问题 I've seen a lot of answers here that say to use close() to destroy a socket but the guide I used from msdn has me using closesocket(). I'm wondering if there is a difference and if there are reasons to use one or the other. In both cases, I am seeing the suggestion to use shutdown() so that's all well and good. 回答1: close() is a *nix function. It will work on any file descriptor, and sockets in *nix are an example of a file descriptor, so it would correctly close sockets as well. closesocket(

Winsock 2 Reading text from a URL

爱⌒轻易说出口 提交于 2019-12-08 09:36:52
问题 For example, this is what I'm wanting to do: if (http->Connect("http://pastebin.com/raw/9uL16CyN")) { YString data = ""; if (http->ReceiveData(data)) { std::cout << "Networked data: " << std::endl; std::cout << data << std::endl; } else std::cout << "Failed to connect to internet.\n"; } The page I'm trying to read from is a raw ASCII text (http://pastebin.com/raw/9uL16CyN) I was hoping this would work easily, but apparently not, I keep getting the WSA error: WSAHOST_NOT_FOUND (11001) My

Winsock Error 10022 on Listen

自闭症网瘾萝莉.ら 提交于 2019-12-08 08:59:17
问题 i'm making a small IRC server, but I've come across a problem; upon trying to listen to the socket, i get error 10022 (Invalid Argument). The error also appears on accept(), but this is because the socket isn't listening (the problem i'm posting about). I didn't include the accept function because i feel it isn't necessary and would be adding pointless code. #include <iostream> #include <ws2tcpip.h> #include <winsock2.h> #include <thread> #include <string> #pragma comment(lib, "Ws2_32.lib")