|
I know the basics, 8 bit makes a byte, and so forth, but I can't read the code I posted. I am however getting better at using the ethereal, and highlighting the portions of the transmission, such as data.
The data being sent seems to be just 1 byte, with a value of 02, and is represented as a dot .
I was thinking last night that perhaps instead of sending a char, like you would use to request a web page, I need to send a bytes.
|
|
|
|
|
If the actual data that is being sent is a x02 (hex), then that's what you need to send... looking at your packet, it looks like you have something like "0x2f0b" (as text, not bytes)... that seems like you're accidentally sending the address of your buffer instead of the values contained in it.
|
|
|
|
|
ohhhhhhhhhhh.
I think I'm closer now. I'm sending cc, but I'm suppose to send 20.
I manually altered the buffer size in send to 1, instead of using (int)strlen(sendbuf)
So I think I'm building the data too big.
This is a lot to learn, but I need to learn it. here's what I'm using now, I think I'm on the right track
BOOL CA_SQLServer_Scan::_socket_Broadcast_SQLServers( void )
{
#define DEFAULT_BUFLEN 512
#define DEFAULT_PORT 1434
int iResult;
WSADATA wsaData;
SOCKET ConnectSocket = INVALID_SOCKET;
struct sockaddr_in clientService;
int recvbuflen = DEFAULT_BUFLEN;
char recvbuf[DEFAULT_BUFLEN] = "";
char mac[5];
char sendbuf[1];
memset(sendbuf, 0x00, sizeof(sendbuf));
strcpy(sendbuf, "");
sprintf(sendbuf+strlen(sendbuf), "", strlen(sendbuf), sendbuf);
memcpy(sendbuf+strlen(sendbuf), mac, 5);
iResult = WSAStartup(MAKEWORD(2,2), &wsaData);
if (iResult != NO_ERROR) {
wprintf(L"WSAStartup failed with error: %d\n", iResult);
return 1;
}
ConnectSocket = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
if (ConnectSocket == INVALID_SOCKET) {
wprintf(L"socket failed with error: %ld\n", WSAGetLastError());
WSACleanup();
return 1;
}
clientService.sin_family = AF_INET;
clientService.sin_addr.s_addr = inet_addr( "255.255.255.255" );
clientService.sin_port = htons( DEFAULT_PORT );
iResult = connect( ConnectSocket, (SOCKADDR*) &clientService, sizeof(clientService) );
if (iResult == SOCKET_ERROR) {
wprintf(L"connect failed with error: %d\n", WSAGetLastError() );
closesocket(ConnectSocket);
WSACleanup();
return 1;
}
iResult = send( ConnectSocket, sendbuf, 1, 0 );
if (iResult == SOCKET_ERROR) {
wprintf(L"send failed with error: %d\n", WSAGetLastError());
closesocket(ConnectSocket);
WSACleanup();
return 1;
}
printf("Bytes Sent: %d\n", iResult);
iResult = shutdown(ConnectSocket, SD_SEND);
if (iResult == SOCKET_ERROR) {
wprintf(L"shutdown failed with error: %d\n", WSAGetLastError());
closesocket(ConnectSocket);
WSACleanup();
return 1;
}
do {
iResult = recv(ConnectSocket, recvbuf, recvbuflen, 0);
if ( iResult > 0 )
wprintf(L"Bytes received: %d\n", iResult);
else if ( iResult == 0 )
wprintf(L"Connection closed\n");
else
wprintf(L"recv failed with error: %d\n", WSAGetLastError());
} while( iResult > 0 );
iResult = closesocket(ConnectSocket);
if (iResult == SOCKET_ERROR) {
wprintf(L"close failed with error: %d\n", WSAGetLastError());
WSACleanup();
return 1;
}
WSACleanup();
return TRUE;
}
What I'm trying to copy
0000 ff ff ff ff ff ff 00 13 72 36 67 30 08 00 45 00 ........ r6g0..E.
0010 00 1d 6f 9a 00 00 80 11 07 8a c0 a8 03 04 ff ff ..o..... ........
0020 ff ff 05 8b 05 9a 00 09 2f 0b 02 ........ /..
What I got back with the posted code
0000 ff ff ff ff ff ff 00 13 72 36 67 30 08 00 45 00 ........ r6g0..E.
0010 00 1d 94 48 00 00 80 11 e2 db c0 a8 03 04 ff ff ...H.... ........
0020 ff ff 12 32 05 9a 00 09 58 63 cc ...2.... Xc.
|
|
|
|
|
why not just... ???
char sendbuf[] = {0x02};
|
|
|
|
|
I tried and sent the actual string 0x02
|
|
|
|
|
I took out the memset and did the straight char, yes it works and it's faster,
OK, feel stupid but I did not fully understand the process. I tried it earlier, but got some kind of Int error.
Do you know anything about the receive side of the socket? it just sits there and never closes, or transfer data to the receive buffer.
|
|
|
|
|
I don't remember exactly off hand what it should do... but since UDP is essentially connectionless (meaning no hand-shaking between server and client), I imagine the socket has to be closed explicitly by the application.
jkirkerx wrote: or transfer data to the receive buffer.
Don't know exactly what you mean by that.
|
|
|
|
|
I took a generic winsock2 sample code and modified it for UDP broadcast. I have come to the same conclusion, in which the socket will never close, because it's not an single machine to machine connection, in which the other side will never send the symbol saying it's done, or simply close it's port.
I just need to figure out how to capture the return data.
Not sure if I need 2 sockets, one to just send the broadcast, and the other to just listen. If I do that, I'm afraid the listening socket will cause my code to stop, and I won't be able do anything until the socket closes.
|
|
|
|
|
Finally figured it out, and got back packets from all the SQL Servers on the network, complete with all the information I need.
So now I know how to send a STX command to SQL Browser, to start a conversation. It's sort of like a modem command.
Now I have to figure out how and when to release the receive side of the socket, and only capture the packets that I need.
So the SendMessage, which is a char string, has to be set with memset, in order to send just the byte.
|
|
|
|
|
A char* is not necessarily a string... it's just a char pointer... in network programming, character buffers are commonly used to hold the data being transferred to/from a socket because of the size of a char is one byte. It's just convenient to use that since it's the smallest data element used/transferred.
|
|
|
|
|
To make my code more readable I'm trying to use a set of defined values in a switch statement. Basically I have a 4 CHAR tag I want to convert to a DWORD.
#define _makeTag(x) ((#x[0] << 24) | (#x[1] << 16) | (#x[2] << 8) | #x[3])
#define tag_cmap _makeTag(cmap)
In the above I have a 4 CHAR string "cmap" which in DWORD form should be 0x636d6170. However when using in a switch statement the compiler complains that it's not constant. The commented line works, however I believe it to be unreadable.
Any suggestions?
My previous method was to use a union but that required a loop over all the values, hence slow code.
Waldermort
|
|
|
|
|
no, it's not const. Because it's not a compile-time operation. You're accessing a memory location. If you were to look at the generated C-code, it would look like the following:
(("cmap"[0] << 24) | ("cmap"[1] << 16) | ("cmap"[2] << 8) | ("cmap"[3]))
So, it's runtime code, *not* a constant.
You could try assigning it to a constant though, as follows:
const tag_cmap = _makeTag(cmap);
instead of the
#define tag_cmap
If your actions inspire others to dream more, learn more, do more and become more, you are a leader." - John Quincy Adams You must accept one of two basic premises: Either we are alone in the universe, or we are not alone in the universe. And either way, the implications are staggering” - Wernher von Braun
|
|
|
|
|
ahmed zahmed wrote: You're accessing a memory location.
LOL, That thought hit me right after posting the message.
Compiler still complains when assigning to a const.
I've decided to go with my first method but instead to use _makeTag('c','m','a','p') directly in the switch.
Thanks again.
Waldermort
|
|
|
|
|
It turns out that you do not need a macro at all to do what you want.
Try this -
DWORD d = 'cmap';
Please note the single quotation marks.
|
|
|
|
|
Nice!
Out of curiosity what compiler are you using? I think I may have tried that back on VS8 but with errors.
Waldermort
|
|
|
|
|
I currently use VS2010, but I'm sure this works in older compilers, because this type of assignment is used to tag memory allocations in kernel mode code from ages ago.
|
|
|
|
|
WalderMort wrote: Any suggestions?
Why, yes: don't use macros, they make your code unreadable
No, seriously: using macros is dangerous, with very few exceptions. Regarding your example, your choice of symbol alone already breaks two common safeguards against macro problems:
1. Do not ever use a symbol with starting '_'! This is what the system libraries use internaly to prevent name clashes with any symbols the programmer may define! The problem with name clashes and macros is that macros clash silently, and may break system libraries, resulting in very hard to trace runtime errors (or compiler error,s, if you're lucky)
2. Use capital letters for symbols denoting const or #define symbols. This, also, has to do with preventing name clashes. It may seem overkill, but better be safe than sorry.
I've spent many, many weeks hunting down errors caused my macro name clashes caused by other people's code (and in some cases even by MS #defines!). Do yourself (and everyone else) a favor and don't add to that misery!
|
|
|
|
|
Hi all,
I am trying to play video files in my application. i have used MCIWndCreate function but i am having a problem.
I want to display video on my screen of a particular size, for aciheving this i have created a static control and passed its handle to MCIWndCreate. Video is displayed of its size only but it is cuting from sides i.e its not showing full video.
i have written this line of code
HWND h = m_static1.GetSafeHwnd();
m_Player = MCIWndCreate(h,AfxGetInstanceHandle(),
WS_CHILD | WS_VISIBLE|MCIWNDF_NOPLAYBAR, _T("D:\\2.mpeg"));
How can i do this??
Thanks in advance
|
|
|
|
|
I see from the docs [^]that you've also got the two flags MCIWNDF_NOAUTOSIZEWINDOW and MCIWNDF_NOAUTOSIZEMOVIE - one for preventing the window being sized to fit the movie, the other for preventing the movie being resized to fit the window.
I'd be inclined to try adding the first flag. (never used any of these functions)
|
|
|
|
|
Hello!
I've got a problem with a CHtmlView derived View on Windows 7.
The CHtmlView derived View is embedded in a CTabView with the following code:
int COSTabbedView::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CTabView::OnCreate(lpCreateStruct) == -1)
return -1;
AddView (RUNTIME_CLASS (CResultView), _T("Results"), 100);
AddView (RUNTIME_CLASS (CBrowserView), _T("Certificate"), 101);
return 0;
}
The view itself is initialized by:
void CBrowserView::OnInitialUpdate()
{
CHtmlView::OnInitialUpdate();
Navigate2(_T("http://www.google.de"));
}
On a Windows XP machine this works fine. The view displays the requested page.
On Windows 7 the status bar of my application says something like "Downloading from www.google.de" and then a new Internet Explorer window will open and display the site but not with "www.google.de" in the address bar, but the path of the temporary downloaded file (!?).
I've been searching around for several days now and found out at least one interesting thing:
When I use Spy++ on WinXP I see the following windows below my view window:
Shell Embedding
+ Shell DocObject View
+ Internet Explorer_Server
On Windows 7 the "Shell DocObject View" and the "Internet Explorer_Server" window are missing.
So I debugged into the creation of the CHtmlView window but they both behave the same on Win7 and XP.
Does anyone have a hint what is going wrong here?
|
|
|
|
|
I need to implement TCP hole punching in my application. I tried to google to find any sample implementation but could not get.
Please suggest me idea behind TCP hole punhing with example...
|
|
|
|
|
|
UDP/TCP hole punching is Communication between two computers without opening ports,
using a third computer to set up the connection
UDP/TCP hole punching is NOT a security violation in any way, even though the name suggests it is.
Once the hole has been punched in the firewall, only connections from the specified client
are accepted through it, it isn't like anyone can get in through the hole.
Get the win32 DLL here:
http://www.cis.nctu.edu.tw/~gis87577/xDreaming/XSTUNT/index.html[^]
It works like this:
A--->proxy --------proxy<---B
|
S
Let A be the client requesting the connection
Let B be the client that is responding to the request
Let S be the server that they contact to initiate the connection
A sends a connection request to S
S responds with B's IP and port info, and sends A's IP and port info to B
A sends a UDP/TCP packet to B, which B's router firewall drops but it still punches a hole in A's own firewall where B can connect
B sends a UDP/TCP packet to A, that both punches a hole in their own firewall, and reaches A through the hole that they punched in their own firewall
A and B can now communicate through their established connection without the help of S
All this does is make both A and B's firewalls think that they have initiated the connection,
just as it would let packets from a web server through ONLY if the client had initiated the connection
to the web server and the packets were expected.
This is not a security risk and software that uses this method should not be looked down upon,
this is how p2p software like AIM and most VoIP clients initiate connections.
TCP hole punching Algorithm
Let A and B be the two hosts, each in its own private network;
N1 and N2 are the two NAT devices;
S is a public server with a well-known globally reachable IP address.
A and B each begin a TCP conversation with S;
the NAT devices N1 and N2 create TCP translation states and assign temporary external port numbers
S relays these port numbers back to A and B
A and B contact each others' NAT devices directly on the translated ports;
the NAT devices use the previously created translation states and send the packets to A and B
The Low TTL is calculated as follow:
Send SYN with TTL of i=1
Wait for ICMP TTL Exceeded message
i = i + 1, loop
Loop until "ICMP TTL Exceeded" messages are no longer received.
The own NAT host has been traversed.
The LOW TTL Value = i + 1.
If the NAT host supports "ICMP TTL Exceeded" messages to internal hosts, then the RST reply from buddy can be inspected.
The LOW TTL Value = i - 1.
http://en.wikipedia.org/wiki/TCP_hole_punching
http://nutss.gforge.cis.cornell.edu/stunt.php
http://en.wikipedia.org/wiki/STUN
|
|
|
|
|
|
|