[Winpcap-users] capture tcp packets directly
yzhang1985 at gmail.com
Fri Jun 9 19:44:02 GMT 2006
Hi. I'm trying to build a port forwarding program that lets two computers
that are behind NATs (mutually invisible to each other) communicate via a
computer they both can connect to (bridge). To do this, I need to be able to
capture TCP packets directly and send them. Is there a way to capture TCP
packets (either without or with headers) without being superuser on UNIX
like systems or Administrator on Windows?
I tried the following program, but the socket cannot be bound. I suppose
that this is because there is no mechanism receiving TCP packets in the
network stack - only stream communication?
int main(int argc, char **argv)
if (WSAStartup(MAKEWORD(2, 0), &wsa_data) != 0)
cout << "WSAStartup() failed\n";
socket = socket(AF_INET, SOCK_DGRAM, IPPROTO_TCP);
addrLocal.sin_family = AF_INET;
addrLocal.sin_addr.s_addr = inet_addr("127.0.0.1");
addrLocal.sin_port = htons(3390);
if (bind(socket, (sockaddr *)&addrLocal, sizeof(sockaddr_in)) ==
cout << "error bind" << endl;
int address_length = sizeof(addr), connection;
while ((connection = accept(g_socket, (sockaddr *)&addr,
&address_length)) < 0);
cout << "connected";
int length = recvfrom(connection, (char *)buffer, 2048, 0, (sockaddr
// int length = recv(connection, (char *)buffer, 2048, 0);
cout << length << endl;
Any ideas about how to do what I want or alternatives? Thanks for any help.
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Winpcap-users