1
我在使用Microsoft Platform SDK提供的示例LSP中的WSPSend函数中获取目标端口号时遇到问题。在WSPSend中获取目标端口
这是我正在使用的代码。如下所示,不输入if语句。我使用调试功能对此进行了验证。
我试图使用目的端口80
int WSPAPI
WSPSend(
SOCKET s,
LPWSABUF lpBuffers,
DWORD dwBufferCount,
LPDWORD lpNumberOfBytesSent,
DWORD dwFlags,
LPWSAOVERLAPPED lpOverlapped,
LPWSAOVERLAPPED_COMPLETION_ROUTINE lpCompletionRoutine,
LPWSATHREADID lpThreadId,
LPINT lpErrno
)
{
INT ret = SOCKET_ERROR;
SOCK_INFO *SocketContext = NULL;
LPWSAOVERLAPPEDPLUS ProviderOverlapped = NULL;
*lpErrno = NO_ERROR;
//
// Find our provider socket corresponding to this one
//
SocketContext = FindAndRefSocketContext(s, lpErrno);
if (NULL == SocketContext)
{
dbgprint("WSPSend: FindAndRefSocketContext failed!");
goto cleanup;
}
// My code starts here!!!
SOCKET app = SocketContext->LayeredSocket;
struct sockaddr FAR name;
int FAR namelen;
getpeername(app, &name, &namelen);
struct sockaddr_in sin;
sin =* (const struct sockaddr_in *) (&name);
if(sin.sin_port == htons(80))
{
// This code is not executed after sending HTTP packets!!
}
}
任何想法,认识到这一点函数内部传出HTTP数据包?
我检查了getpeername的返回值。它没有返回0! – Khaled 2010-11-14 13:48:09
@Khaled - 这是有用的信息 - 将'namelen'设置为'sizeof(struct sockaddr)',这应该会更好。 – 2010-11-14 14:02:03
非常感谢。它现在有效。 – Khaled 2010-11-14 14:10:57