未处理的异常-访问冲突读取位置 [英] Unhandled Exception - Access Violation Reading Location

查看:87
本文介绍了未处理的异常-访问冲突读取位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编译的代码,除了此行上的此错误.未处理的异常访问冲突读取位置

The code I have is compiling except for this error on this line. Unhandled Exception Access Violation Reading Location

int s = socket(res->ai_family, res->ai_socktype, res->ai_protocol);

推荐答案

不确定,但doco表示getaddrinfo返回0表示成功.您应该将测试更改为!= 0而不是<它可能返回的所有错误代码都可能是< 0. 0,但仍然不正确.

同样,将res设置为指向结果链接列表的开头.可能是该列表中的第一项不是ai_family == AF_INET,并且您正在访问的某些成员对该项的家庭无效.

您可以将res初始化为NULL,然后测试res!= NULL,以确保getaddrinfo实际上正在填充指针.

来自 http://linux.die.net/man/3/getaddrinfo [
Not sure but the doco says that getaddrinfo returns 0 for success. You should change your test to != 0 rather than < 0. It may be that all the error codes it can return are < 0 but it''s still incorrect.

Also, res will be set to point to the head of a linked list of results. It may be that the first item in that list is not ai_family == AF_INET and some of the members you''re accessing are not valid for the family of that item.

You could initialise res to NULL and then test for res != NULL to make sure getaddrinfo is actually populating the pointer.

from http://linux.die.net/man/3/getaddrinfo[^]


getaddrinfo(3) sets res to point to a dynamically-allocated linked list of addrinfo structures, linked by the ai_next member. There are several reasons why the linked list may have more than one addrinfo structure, including: if the network host is multi-homed; or if the same service is available from multiple socket protocols (one SOCK_STREAM address and another SOCK_DGRAM address, for example).


res的值是什么?我怀疑它为NULL或至少没有指向内存的有效位.
what is the value of res? I suspect it''s NULL or at least not pointing to a valid bit of memory.


您应该将系列设置为AF_INET

您知道如何使用调试器单步执行程序并检查变量的值吗?
You should be setting the family to AF_INET

Do you know how to use the debugger to step through the program and inspect the value of variables?


这篇关于未处理的异常-访问冲突读取位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆