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