将IP_HDRINCL设置为win32中的setsockopt函数

发布于 2024-07-26 06:42:00 字数 460 浏览 4 评论 0原文

我正在与 Win32 中的原始套接字进行斗争,现在我陷入了困境,setsockopt() 函数给了我 10022 错误(无效参数),但我认为我传递了正确的参数...当然我错了 u_u'

sock = socket(AF_INET,SOCK_RAW,IPPROTO_UDP);
if (sock == SOCKET_ERROR)
{
  printf("Error socket(): %d", WSAGetLastError());
  return;
}
char on = 1;
error =  setsockopt(sock,IPPROTO_IP,IP_HDRINCL,&on,sizeof(on)); 
if (sock == SOCKET_ERROR)
{
  printf("Error setsockopt(): %d", WSAGetLastError());
  return;
}

有人知道我的代码发生了什么吗?

I'm fighting with raw sockets in Win32 and now I'm stuck, the setsockopt() function give me the 10022 error (invalid argument), but I think I pass the correct arguments... of course I'm wrong u_u'

sock = socket(AF_INET,SOCK_RAW,IPPROTO_UDP);
if (sock == SOCKET_ERROR)
{
  printf("Error socket(): %d", WSAGetLastError());
  return;
}
char on = 1;
error =  setsockopt(sock,IPPROTO_IP,IP_HDRINCL,&on,sizeof(on)); 
if (sock == SOCKET_ERROR)
{
  printf("Error setsockopt(): %d", WSAGetLastError());
  return;
}

Anybody knows what happen to my code?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

夜清冷一曲。 2024-08-02 06:42:00

您应该使用 DWORD 1 或 bool true,有很多文档显示带有 char、int、DWORD、bool 的代码,但正确的一个是 book 或 DWORD,在某些系统中可能是 int...但目前它对我有用布尔。

顺便说一下,我在Win7中使用IP_HDRINCL执行相同的函数setsockopt时发现错误10014 WSAEFAULT,它在XP中工作,但在Win7中总是失败,不知道为什么......也许它在最近的Windows版本中被禁用?

You should use DWORD 1 or bool true, there are lots of documents that show code with char, int, DWORD, bool, but the right one is book or DWORD, maybe int in some systems... but currently it worked for me as bool.

By the way, I've found error 10014 WSAEFAULT when executing the same function setsockopt with IP_HDRINCL in Win7, it works in XP but in Win7 it always fails and don't know why... maybe it is disabled in recent windows versions?

迟月 2024-08-02 06:42:00

据我记得你需要使用 int on = 1 而不是 char...

As far as I remember you need to use int on = 1 instead of char...

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文