Today, researching technology has landed me in some interesting places:
Bochs - The Open Source IA-32 Emulator.
Somewhat of an understatement, the "Virtual-PC-like" project Bochs emulates the processor, basic hardware, and BIOS. You can install many versions of Windows and Linux within a Bochs emulation. This is great if you want to try a Linux distribution or even develop your own OS within a simple crash proof environment when you don't have an extra PC lying around.
Win32 Program Disassembler - A Win32 disassembly project by Sang Cho. It's a bit dated, but the full source is provided and there's some good links to other disassembly and decompilation sites.
X86 Machine Code - An old-school site with lots of good assembly information and links. One link that stood out in particular was to an extensive list of interrupt calls.
Showing posts with label c++. Show all posts
Showing posts with label c++. Show all posts
Saturday, February 02, 2008
Wednesday, February 22, 2006
Porting Berkeley Sockets
Over the past few days I've had the opportunity to port a program using Berkeley sockets to Winsock. It's actually a lot easier than it sounds.
A large part Winsock was designed based on Berkeley sockets, and for the most part, the only things that have been changed are a few function names. I'll touch on the main one's you'll run into while porting.
read / write The functions used for I/O (Input and output) operations on a socket.
read(socketfd, buf, left);
write(socketfd, buf, left);
In Winsock 2 the functions are nearly the same, except under the name send and recv
int recv(SOCKET s, char* buf, int len, int flags);
int send(SOCKET s, const char* buf, int len, int flags);
The extra parameter flags is for special things like just peeking the recv stream instead of removing from it. If you want to do a direct port, you can just set flags to 0 and keep the other parameters the same.
fcntl Change the I/O mode on a socket, in this case, change the socket to nonblocking.
fcntl(fd, F_SETFL, O_NONBLOCK);
Once again, Winsock 2 is very similar, with a few extra features. To put the socket into nonblocking using Winsock 2 you have to use the following method:
unsigned long nonblocking = 1;
ioctlsocket(fd, FIONBIO, &nonblocking);
By changing the three functions above, you can port most any application that uses Berkeley sockets to one using Winsock 2. Of course, you mustn't forget to take care of all the Winsock specific stuff like including the libraries, header files, calling WSAStartup, and WSACleanup. If your interested in Winsock 2 you can check it out on MSDN
A large part Winsock was designed based on Berkeley sockets, and for the most part, the only things that have been changed are a few function names. I'll touch on the main one's you'll run into while porting.
read / write The functions used for I/O (Input and output) operations on a socket.
read(socketfd, buf, left);
write(socketfd, buf, left);
In Winsock 2 the functions are nearly the same, except under the name send and recv
int recv(SOCKET s, char* buf, int len, int flags);
int send(SOCKET s, const char* buf, int len, int flags);
The extra parameter flags is for special things like just peeking the recv stream instead of removing from it. If you want to do a direct port, you can just set flags to 0 and keep the other parameters the same.
fcntl Change the I/O mode on a socket, in this case, change the socket to nonblocking.
fcntl(fd, F_SETFL, O_NONBLOCK);
Once again, Winsock 2 is very similar, with a few extra features. To put the socket into nonblocking using Winsock 2 you have to use the following method:
unsigned long nonblocking = 1;
ioctlsocket(fd, FIONBIO, &nonblocking);
By changing the three functions above, you can port most any application that uses Berkeley sockets to one using Winsock 2. Of course, you mustn't forget to take care of all the Winsock specific stuff like including the libraries, header files, calling WSAStartup, and WSACleanup. If your interested in Winsock 2 you can check it out on MSDN
Subscribe to:
Posts (Atom)