WSASocket () Creating a socket is not a successful workaround

Source: Internet
Author: User

These days I am writing a copy of the Windows Ping program, but the socket is always created unsuccessful, found some information on the Internet finally solved the problem, and now summarize.

Workaround: Run vs on the administrator Yes, I'm vs2013,vs2010, too.

/*winsock Initialization */

if (WSAStartup (Makeword (2, 2), &wsadata)! = 0)
{
Error message if initialization is unsuccessful, GetLastError () returns
printf ("WSAStartup () failed:%d]\n", GetLastError ());
Return

}

/* Create the original socket for the ICMP protocol */

SOCKET M_socket;

M_socket = WSASocket (Af_inet, Sock_raw, ipproto_icmp, NULL, 0, wsa_flag_overlapped);
/* If the CREATE socket is unsuccessful */
if (M_socket = = Invalid_socket)
{
printf ("WSASocket () failed:%d\n", WSAGetLastError ());
Return
}

PS: Already linked ws2_32.lib, #pragma comment (lib, "Ws2_32.lib")

#include <winsock2.h>
#include <ws2tcpip.h>

has also joined the

Workaround: Run vs on the administrator Yes, I'm vs2013,vs2010, too.

vs2013 (2010) How to start a run with Administrator privileges:

It is easy to improve the permissions of the application itself when some projects are being developed. Find a shortcut to VS2013: Right-click Run as Administrator Open Project
or right-click the open file location to find the startup project for VS2013 devenv.exe: Right-click the property compatibility privilege level and run with administrator privileges;
If you want each user to run with administrator privileges, you can also change the set privilege level for all users and run with administrator privileges. Then make sure to open the program as VS2013 by default in the way the project is opened.


Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

WSASocket () Creating a socket is not a successful workaround

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.