WINDOWS INTERNET PROGRAMMING part2
<html>
<head>
<title>Windows Internet Programming Part2</title>
</head>
<body>
<pre>
<font color=red>
_________________
/_ /\
\/ _______ / \
/ / / / /
/ /______/ / /
/ __/ /
/ _______ \ __/
/ / / / \
/ /______/ / /
_/ / /
/______________/ / BLACK SUN RESEARCH FACILITY
\ \ / <a href="http://blacksun.box.sk">HTTP://BLACKSUN.BOX.SK</a>
\______________\/
</font>
WINDOWS INTERNET PROGRAMMING {part 2}
=================================================
WRITTEN BY [ <a href="mailto:cos125@hotmail.com">cos125@hotmail.com</a> :E-MAIL ]
<a href="mailto:cos125@hotmail.com">BINARY RAPE</a> [ 114603188 :ICQ# ]
[ <a href="http://www.geocities.com/wininetprogram">www.geocities.com/wininetprogram</a> :WEB SITE ]
[ <a href="http://blacksun.box.sk">http://blacksun.box.sk</a> :TURORIALS ]
Thanks to cyberwolf for letting me write this and BSRF for releasing it.
<br>
<p>Disclaimer
<p>None of the information or code in this tutorial is meant to be used
against others
<br>or to purposely damage computer systems and/or cause any loss of or
damage to property.
<p>Further more, neither myself or any other contributor to, or member
of, the Blacksun
<br>research Facility (BSRF) can be held responsible for damage or loss
of property to
<br>computer systems as a result of this tutorial.
<p>In this tutorial the code is provided as a learning aid so you can see
how its done
<br>its not meant for you to use against yourself or others.
<p>If you don't agree with any of this then please stop reading......
now!
<br>
<p>CONTENTS
<br>
<p>1. <a href="#1">Introduction</a>
<br>2. <a href="#2">UNIX and Windows</a>
<br>3. <a href="#3">Error Codes</a>
<br>4. <a href="#4">Port Numbers</a>
<br>5. <a href="#5">Include Files</a>
<br> -<a href="#5.1"> 5.1 socket()</a>
<br> -<a href="#5.2">5.2 bind()</a>
<br> -<a href="#5.3">5.3 connect()</a>
<br> -<a href="#5.4">5.4 listen()</a>
<br> -<a href="#5.5">5.5 accept()</a>
<br> -<a href="#5.6">5.6 gethostname()</a>
<p>6. <a href="#6">Common Functions</a>
<br>7. <a href="#7"> Renamed Functions</a>
<br>8. <a href="#8">Blocking Routines</a>
<br>9. <a href="#9">Additional Functions</a>
<br>10. <a href="#10">Porting Code</a>
<br> -10.1 <a href="#10.1">DNS Program</a>
<br> -10.2 <a href="#10.2">Streaming Server</a>
<br> -10.3 Streaming Client
<p>11. <a href="#11">Planning</a>
<br>12. <a href="#12">Last Words</a>
<p> APPENDIXES
<p> A - <a href="#appxA">The Compiler</a>
<p>______________________
<br>1.0<a NAME="1"></a> INTRODUCTION
<br>
<p>In the last part in this series of tutorials I discussed windows sockets
programming using
<br>the winsock API and in that document I mentioned that the windows Sockets
implementation is
<br>based on the Berkeley Sockets idea, therefore socket programming on
systems such as UNIX
<br>and Linux, which are also based on the Berkeley API would be quiet
similar. This aids us
<br>in porting from platform to platform, making it easy to move whole
programs from UNIX to
<br>windows in a very short time.
<p>This tutorial will discuss and illustrate the differences in code and
functions between the
<br>platforms and sample source code and applications will be provided
to show how to port the
<br>applications piece by piece.
<p>I suggest that you first read Part 1 in this series of tutorials and
also Bracaman's basic
<br>UNIX sockets tutorial, also available from blacksun.box.sk and also
from code.box.sk.
<p>Any add on information for this tutorial and updates are available as
usual from:
<br>http://www.geocities.com/winnetprogram.
<br>
<p>
<hr SIZE=1 WIDTH="70%">
<br>
<p>2.0 <a NAME="2"></a>UNIX AND WINDOWS
<br>=====================
<p>Unix and Windows handle sockets differently, UNIX treats sockets the
same as a file handle
<br>which is a small integer while in windows it is an unsigned type called
SOCKET.
<p>So from the start UNIX and windows actually think of there respective
sockets differently.
<p>To best explain the differences the following is an exert from bracamans
tutorial and
<br>describes sockets from the Unix point of view:
<br>
<p>"In a very simple way, a socket is a way to talk to other computer.
<p>To be more precise, it's a way to talk to other computers using standard
Unix file
<br>descriptors.
<p>In Unix, every I/O actions are done by writing or reading to a file
descriptor. A file
<br>descriptor is just an integer associated with an open file and it can
be a network connection,
<br>a terminal, or something else."
<br>
<p>
<hr SIZE=1 WIDTH="70%">
<br>
<p>3.0 <a NAME="3"></a>ERROR CODES
<br>=======================================
<p>In UNIX error codes are available trough the errno variable. In windows
we use the function
<br>WSAGetLastError() to obtain these error codes.
<br>
<p>_________________________
<p>4.0 <a NAME="4"></a>PORT NUMBERS
<br>=======================================
<p>In both Unix and Windows you define the port numbers by entering the
destination port number
<br>as a parameter to the function htons(), however in winsock.h several
port numbers are defined
<br>for common ports so that you can also use these.
<p>The following is a list of the default names and there relative port
numbers:
<br>
<pre>
1. IPPORT_ECHO - 7
2. IPPORT_DISCARD - 9
3. IPPORT_SYSTAT - 11
4. IPPORT_DAYTIME - 13
5. IPPORT_NETSTAT - 15
6. IPPORT_FTP - 21
7. IPPORT_TELNET - 23
8. IPPORT_SMTP - 25
9. IPPORT_TIMESERVER - 37
10. IPPORT_NAMESERVER - 42
11. IPPORT_WHOIS - 43
12. IPPORT_MTP - 57
</pre>
<p>
<hr SIZE=1 WIDTH="70%">
<br>
<p>5.0 <a NAME="5"></a>INCLUDE FILES
<br>=======================================
<p>In UNIX there are a number of include files to use in socket programming,
following is a
<br>list of these functions and related #include files:
<br>
<p>5.1 <a NAME="5.1"></a>socket()
<p> [ #include <sys/types.h> ]
<br> [ #include <sys/socket.h> ]
<br>
<p>5.2 <a NAME="5.2"></a>bind()
<p> [ #include <sys/types.h> ]
<br> [ #include <sys/socket.h> ]
<br>
<p>5.3 <a NAME="5.3"></a>connect()
<p> [ #include <sys/types.h> ]
<br> [ #include <sys/socket.h> ]
<br>
<p>5.4 <a NAME="5.4"></a>listen()
<p> [ #include <sys/types.h> ]
<br> [ #include <sys/socket.h> ]
<br>
<p>5.5 <a NAME="5.5"></a>accept()
<p> [ #include <sys/socket.h> ]
<p>5.6 <a NAME="5.6"></a>gethostname()
<p> [ #include <netdb.h> ]
<br>
<br>
<p>You will need some general socket include files also in UNIX programming:
<p>#include <netinet/in.h>
<br>#include <arpa/inet.h>
<br>
<p>Your average list of include files at the top of a UNIX socket program
would therefore
<br>look something like the following:
<p>#include <sys/types.h>
<br>#include <sys/socket.h>
<br>#include <netdb.h>
<br>#include <netinet/in.h>
<br>#include <arpa/inet.h>
<br>
<p>In windows the header file for socket and internet programming is contained
in windows.h,
<br>therefore the top of a windows socket programming would look like this:
<p>#include <windows.h>
<p>The name of the header file for windows socket programming is winsock.h
and including
<br>this file in your project as well wont cause any errors of course but
there’s just no need.
<p>Windows programs also need to be linked to the file Wsock32.lib before
they can be
<br>compiled.
<p>Consult your compilers documents for further information on this or
proceed to Appendix 1
<br>- The compiler.
<p>
<hr SIZE=1 WIDTH="70%">
<br>
<p>6.0<a NAME="6"></a>COMMON FUNCTIONS
<br>=======================================
<p>Both Unix and Windows sockets have a set of functions common to both
platforms. These are
<br>mostly the functions dealing with TCP and UDP and all conversion functions
and structures
<br>are the same for both platforms.
<p>For example htons() and inet_addr() are the same on both platforms,
also so is the
<br>structures sockaddr and sockaddr_in.
<br>
<p>Here is a list of common functions.
<p>1. Socket()
<p>2. Bind()
<p>3. Listen()
<p>4. Connect()
<p>5. Accept()
<p>6. Send()
<p>7. Recv()
<p>8. Sendto()
<p>9. Recvfrom()
<p>10. Gethostname()
<br>
<p>
<hr SIZE=1 WIDTH="70%">
<br>
<p>7.0<a NAME="7"></a> RENAMED FUNCTIONS
<br>=======================================
<p>There are some functions which exist in both windows and UNIX socket
programming but
<br>during the conversion the names have changed slightly.
<p>The following table contains a comparison of renamed functions in windows
and UNIX.<br>
<pre>
+===============+==================+
| Unix Function | Windows Function |
+===============+==================+
| close() | closesocket() |
+---------------+------------------+
| ioctl() | ioctlsocket() |
+---------------+------------------+
| read() | recv() |
+---------------+------------------+
| write() | send() |
+---------------+------------------+
</pre>
<p> FIG 1. - Comparison of Windows and Unix Socket functions.
<br>
<p>
<hr SIZE=1 WIDTH="70%">
<br>
<p>8.0<a NAME="8"></a> BLOCKING ROUTINES
<br>=======================================
<p>In windows you can use blocking routines but they are not recommended.
In windows 3.1
<br>using the event driven paradigm it is possible to have a blocked operation
disturbed
<br>by other event driven activity.
<p>Soon you will not be able to have blocking routines in Winsock applications
so it is
<br>not recommended you use them at all in this scenario as this would
limit distribution
<br>possibilities.
<br>
<p>
<hr SIZE=1 WIDTH="70%">
<br>
<p>9.0 <a NAME="9"></a>ADDITIONAL FUNCTIONS
<br>=======================================
<p>In windows there are some functions which aren't seen in UNIX sockets.
In every
<br>windows socket program you must call WSAStarup() before you can call
any socket
<br>functions or use any code.
<p>Additionally every WSAStartup() function has a corresponding WSACleanup()
which
<br>shuts down the Winsock and cleans up after us.
<p>Every Windows socket program must contain both of these functions.
<br>
<p>
<hr SIZE=1 WIDTH="70%">
<br>
<p>10.0 <a NAME="10"></a>PORTING CODE
<br>=======================================
<p>Now that we have discussed the different parts of the program in Unix
and its relevant
<br>Windows parts we can look at some real code.
<br>
<br>
<p>[ 10.1 ]<a NAME="10.1"></a> DNS PROGRAM
<p>The first program we come across is Bracamans DNS application. Here’s
the Unix Code.
<p>/* <---- SOURCE CODE STARTS HERE ----> */
<p>#include <stdio.h>
<br>#include <netdb.h> /* This is the header file needed
for gethostbyname() */
<br>#include <sys/types.h>
<br>#include <sys/socket.h>
<br>#include <netinet/in.h>
<br>
<p>int main(int argc, char *argv[])
<br>{
<br> struct hostent *he;
<p> if (argc!=2){
<br> printf("Usage: %s <hostname>\n",argv[0]);
<br> exit(-1);
<br> }
<p> if ((he=gethostbyname(argv[1]))==NULL){
<br> printf("gethostbyname() error\n");
<br> exit(-1);
<br> }
<p> printf("Hostname : %s\n",he->h_name); /* prints the hostname
*/
<br> printf("IP Address: %s\n",inet_ntoa(*((struct in_addr *)he->h_addr)));
/* prints IP address */
<br>}
<br>/* <---- SOURCE CODE ENDS HERE ----> */
<br>
<br>
<p>This is a very small but still a very useful program. If we attempt
to compile this
<br>right away under Microsoft Visual C++ We will get an error saying that
it can not
<br>find an include file, so our first duty is to remove all of the Unix
Socket include
<br>files and replace them with the line:
<p>#include <windows.h>
<p>remembering to leave stdio.h right where it is.
<br>When I tried compiling it now I got several more errors so I changed
the
<br>main() fuction from what it is above to:
<p>void main(int argc, char **argv) and the program then compiled.
<p>However I then got several linker errors. Remember when socket programming
on windows
<br>you must link to the file Wsock32.lib.
<p>After I linked to the proper .lib file the program compiles perfectly,
without the
<br>need to touch a single line of the socket code!!
<p>This is how compatible different platforms can be with socket code,
however this is a
<br>very small program and this is not usually the case. The following
is the windows
<br>source code for the port of Bracamans DNS program.
<p>Remember you will get an error unless you include WSAStartup() and WSACleanup()!!
<br>
<p>/* <---- SOURCE CODE STARTS HERE ----> */
<p>#include <windows.h>
<br>#include <stdio.h>
<p>int main(int argc, char *argv[])
<br>{
<p> WSADATA wsdata;
<p> WSAStartup(0x0101,&wsdata);
<p> struct hostent *he;
<p> if (argc! = 2)
<br> {
<br> printf("Usage: %s hostname\n",argv[0]);
<br> return -1;
<br> }
<p> if ((he = gethostbyname(argv[1])) == NULL)
<br> {
<br> printf("gethostbyname() error\n");
<br> return -1;
<br> }
<p> printf("Hostname : %s\n",he->h_name);
/* prints the hostname */
<br> printf("IP Address: %s\n",inet_ntoa(*((struct in_addr *)he->h_addr)));
/* prints IP address */
<p> WSACleanup();
<br> return -1;
<p>}
<br>/* <---- SOURCE CODE ENDS HERE ----> */
<br>
<p>This program has almost as few lines as the UNIX alternative and requires
practically
<br>no porting at all!
<p>Like I said you wouldn’t usually have a program that runs on windows
with such little altering.
<br>Lets discuss porting Bracamans TCP streaming server.
<br>
<p>[ 10.2 ] <a NAME="10.2"></a>STREAMING SERVER
<br>
<p>/* <---- SOURCE CODE STARTS HERE ----> */
<p>#include <stdio.h>
/* These are the usual header files */
<br>#include <sys/types.h>
<br>#include <sys/socket.h>
<br>#include <netinet/in.h>
<br>
<p>#define PORT 3550 /* Port that will be opened */
<br>#define BACKLOG 2 /* Number of allowed connections */
<p>main()
<br>{
<br>
<br> int fd, fd2; /* file descriptors */
<p> struct sockaddr_in server; /* server's address information */
<br> struct sockaddr_in client; /* client's address information */
<p> int sin_size;
<br>
<p> if ((fd=socket(AF_INET, SOCK_STREAM, 0)) == -1 ){ /* calls
socket() */
<br> printf("socket() error\n");
<br> exit(-1);
<br> }
<p> server.sin_family = AF_INET;
<br> server.sin_port = htons(PORT); /* Remember htons()
from "Conversions" section? =) */
<br> server.sin_addr.s_addr = INADDR_ANY; /* INADDR_ANY puts
your IP address automatically */
<br> bzero(&(server.sin_zero),8); /* zero the rest of the structure
*/
<p>
<br> if(bind(fd,(struct sockaddr*)&server,sizeof(struct sockaddr))==-1){
/* calls bind() */
<br> printf("bind() error\n");
<br> exit(-1);
<br> }
<p> if(listen(fd,BACKLOG) == -1){ /* calls listen() */
<br> printf("listen() error\n");
<br> exit(-1);
<br> }
<p>while(1){
<br> sin_size=sizeof(struct sockaddr_in);
<br> if ((fd2 = accept(fd,(struct sockaddr *)&client,&sin_size))==-1){
/* calls accept() */
<br> printf("accept() error\n");
<br> exit(-1);
<br> }
<br>
<br> printf("You got a connection from %s\n",inet_ntoa(client.sin_addr)
); /* prints client's IP */
<br>
<br> send(fd2,"Welcome to my server.\n",22,0); /* send to the client
welcome message */
<br>
<br> close(fd2); /* close fd2 */
<br>}
<br>}
<p>/* <---- SOURCE CODE ENDS HERE ----> */
<br>
<br>
<p>Well lets try and compile shall we...
<br>
<p>Straight away we should clear the obvious problems, link to Winsock32.lib
and
<br>only include windows.h and stdio.h.
<p>Having done so we receive 2 errors, the first pertains to bzero which
we do not
<br>have in our little program so we are going to just remove the line
that contains
<br>it. Once we do so we now have only 1 error, woohoo!
<p>This error tells us that the function close() is not a valid identifier
which is
<br>what I said earlier, close() has been replaced by closesocket() in
windows so we
<br>change that as well to closesocket().
<p>We run this program and we recieve a socket error :(. But remember we
never entered
<br>WSAStartup() and WSACleanup() in this program so we have to do that
first and then
<br>our program will work :).
<p>If you run the program the command prompt should remain blank, just
leave the program
<br>as it is now and move onto the next section to figure out where to
go from here!!
<p>First of course here’s the Windows code for the port ;).
<br>
<p>/* <---- SOURCE CODE STARTS HERE ----> */
<p>#include <stdio.h>
/* These are the usual header files */
<br>#include <windows.h>
<br>
<p>#define PORT 3550 /*
Port that will be opened */
<br>#define BACKLOG 2 /*
Number of allowed connections */
<p>main()
<br>{
<br> WSADATA wsdata;
<p> WSAStartup(0x0101,&wsdata);
<p> int fd, fd2; /* file
descriptors */
<br>
<p> struct sockaddr_in server; /* server's
address information */
<br> struct sockaddr_in client; /*
client's address information */
<p> int sin_size;
<br>
<p> if ((fd=socket(AF_INET, SOCK_STREAM, 0)) == -1 )
/* calls socket() */
<br> {
<br> printf("socket() error\n");
<br> exit(-1);
<br> }
<p> server.sin_family = AF_INET;
<br> server.sin_port
= htons(PORT); /* Remember htons() from "Conversions"
section? =) */
<br> server.sin_addr.s_addr = INADDR_ANY;
/* INADDR_ANY puts your IP address automatically */
<p>
<br> if(bind(fd,(struct sockaddr*)&server,sizeof(struct sockaddr))==-1)
/* calls bind() */
<br> {
<br> printf("bind() error\n");
<br> exit(-1);
<br> }
<br>
<p> if(listen(fd,BACKLOG) == -1) /*
calls listen() */
<br> {
<br> printf("listen() error\n");
<br> exit(-1);
<br> }
<br>
<p>while(1)
<br> {
<br> sin_size=sizeof(struct sockaddr_in);
<p> if ((fd2 = accept(fd,(struct sockaddr *)&client,&sin_size))
== -1) /* calls accept()
*/
<br> {
<br> printf("accept() error\n");
<br> exit(-1);
<br> }
<br>
<br> printf("You got a connection from %s\n",inet_ntoa(client.sin_addr)
); /* prints client's IP */
<br>
<br> send(fd2,"Welcome to my server.\n",22,0);
/* send to the client welcome message */
<br>
<br> closesocket(fd2); /*
close fd2 */
<p>
<br> WSACleanup();
<br> return -1;
<br>}
<br>}
<p>/* <---- SOURCE CODE ENDS HERE ----> */
<br>
<br>
<p>[ 10.3 ] STREAMING CLIENT
<br>
<br>
<p>/* <---- SOURCE CODE STARTS HERE ----> */
<p>#include <stdio.h>
<br>#include <sys/types.h>
<br>#include <sys/socket.h>
<br>#include <netinet/in.h>
<br>#include <netdb.h> /*
netbd.h is needed for struct hostent =) */
<p>#define PORT 3550 /* Open Port on Remote Host */
<br>#define MAXDATASIZE 100 /* Max number of bytes of data
*/
<p>int main(int argc, char *argv[])
<br>{
<br> int fd, numbytes; /* files descriptors */
<br> char buf[MAXDATASIZE]; /* buf will store received text
*/
<br>
<br> struct hostent *he;
/* structure that will get information about remote host */
<br> struct sockaddr_in server; /* server's address information
*/
<p> if (argc !=2) { /* this is
used because our program will need one argument (IP) */
<br> printf("Usage: %s <IP Address>\n",argv[0]);
<br> exit(-1);
<br> }
<p> if ((he=gethostbyname(argv[1]))==NULL){ /* calls gethostbyname()
*/
<br> printf("gethostbyname() error\n");
<br> exit(-1);
<br> }
<p> if ((fd=socket(AF_INET, SOCK_STREAM, 0))==-1){ /* calls
socket() */
<br> printf("socket() error\n");
<br> exit(-1);
<br> }
<p> server.sin_family = AF_INET;
<br> server.sin_port = htons(PORT); /* htons() is needed again */
<br> server.sin_addr = *((struct in_addr *)he->h_addr); /*he->h_addr
passes "*he"'s info to "h_addr" */
<br> bzero(&(server.sin_zero),8);
<p> if(connect(fd, (struct sockaddr *)&server,sizeof(struct sockaddr))==-1){
/* calls connect() */
<br> printf("connect() error\n");
<br> exit(-1);
<br> }
<p> if ((numbytes=recv(fd,buf,MAXDATASIZE,0)) == -1){ /* calls
recv() */
<br> printf("recv() error\n");
<br> exit(-1);
<br> }
<p> buf[numbytes]='\0';
<p> printf("Server Message: %s\n",buf); /*
it prints server's welcome message =) */
<p> close(fd); /* close fd =)
*/
<br>}
<p>/* <---- SOURCE CODE ENDS HERE ----> */
<br>
<p>That’s the source code for the Unix client and of course the windows
one doesn't
<br>look very different.
<br>
<p>/* <---- SOURCE CODE STARTS HERE ----> */
<p>#include <windows.h>
<br>#include <stdio.h>
<p>#define PORT 3550 /* Open Port on
Remote Host */
<br>#define MAXDATASIZE 100 /* Max number
of bytes of data */
<p>int main(int argc, char *argv[])
<br>{
<br> WSADATA wsdata;
<p> WSAStartup(0x0101,&wsdata);
<p> int fd, numbytes; /* files descriptors
*/
<br> char buf[MAXDATASIZE]; /* buf will store
received text */
<br>
<br> struct hostent *he;
/* structure that will get information about remote host */
<br> struct sockaddr_in server; /* server's address
information */
<p> if (argc !=2) {
/* this is used because our program will need one argument (IP) */
<br> printf("Usage: %s <IP Address>\n",argv[0]);
<br> exit(-1);
<br> }
<p> if ((he=gethostbyname(argv[1])) == NULL){ /* calls gethostbyname()
*/
<br> printf("gethostbyname() error\n");
<br> exit(-1);
<br> }
<p> if ((fd=socket(AF_INET, SOCK_STREAM, 0))==-1) /* calls socket()
*/
<br> {
<br> printf("socket() error\n");
<br> exit(-1);
<br> }
<p> server.sin_family = AF_INET;
<br> server.sin_port = htons(PORT);
/* htons() is needed again */
<br> server.sin_addr = *((struct in_addr *)he->h_addr);
/*he->h_addr passes "*he"'s info to "h_addr" */
<br>
<p> if(connect(fd, (struct sockaddr *)&server,sizeof(struct sockaddr))==-1)
/* calls connect() */
<br> {
<br> printf("connect() error\n");
<br> exit(-1);
<br> }
<p> if ((numbytes=recv(fd,buf,MAXDATASIZE,0)) == -1)
/* calls recv() */
<br> {
<br> printf("recv() error\n");
<br> exit(-1);
<br> }
<p> buf[numbytes] = '\0';
<p> printf("Server Message: %s\n",buf);
/* it prints server's welcome message =) */
<p> closesocket(fd);
/* close fd =) */
<p> WSACleanup();
<br> return -1;
<br>}
<p>/* <---- SOURCE CODE ENDS HERE ----> */
<br>
<p>There’s actually no real difference with this port and the last. The
same lines are
<br>changed and the same functions are included as before.
<p>Start the program by switching to its directory on the command line
and typing
<p>streamclient.exe local host
<p>Where streamclient.exe is the name of the stream client program we just
ported
<br>naturally :).
<p>Just make sure that the previous example, the streaming server is running
and
<br>your away. The screen will print the line "Welcome to my server." Congratulations
<br>you’ve ported your first Unix Socket client and server to windows and
you received
<br>a line of text back from your own server :).
<p>
<hr SIZE=1 WIDTH="70%">
<br>
<br>
<p>11.0 <a NAME="11"></a>Planning
<br>=======================================
<p>When porting its probably best to go trough things like a check list
before attempting
<br>to compile the bloody thing. Here’s a list of some recommendations
to run trough first.
<p>1. Replace all network header files with windows.h or winsock.h.
<br>2. Make sure to add WSAStartup() and WSACleanup() before and after
the code.
<br>3. Replace functions such as close() and ioctl() with windows counterparts.
<br>4. Take care of problems such as bzero() and add any windows specific
features like
<br> default ports.
<br>
<p>With so few and simple operations like this it would be pretty damn
easy to write
<br>a program that performs these actions for you, I doubt it would be
complete but hey
<br>it would save you a lot of time in the long run, especially with larger
applications.
<p>
<hr SIZE=1 WIDTH="70%">
<br>
<br>
<p>12.0<a NAME="12"></a> LAST WORDS
<br>==============
<p>Well that’s it for this tutorial, or at least this part of it. More
parts are planned so
<br>hopefully you should see them on blacksun soon :). This part covered
the basics of
<br>windows programming, there was no point in writing about UNIX programming
as bracaman
<br>has released a very good tutorial on basic UNIX sockets programming
which is available
<br>from blacksun.box.sk and code.box.sk.
<p>I will be discussing Unix sockets again however in the next part of
this tutorial but
<br>mostly in a porting sense. To see what’s planned for future parts so
far just look down :).
<br>
<p>Part 2. - GENERAL SOCKETS - Porting to windows and cross
platform code.
<br>Part 3. - RAW Sockets - Have more
control over packets with raw sockets.
<br>Part 4. - ADVANCED - A real
world example by building an internet communication suite.
<br>Part 5. - FINISHING OFF - Putting it
all together in one big program.
<p>So that’s what’s still to come, but I may change some of these future
tutorials at any
<br>time before there released if I do so it will be to improve the series
in my view and
<br>remember send me comments and suggestions and your ideas might also
change the layout
<br>of following tutorials.
<br>
<p>Well thank you for reading this tutorial and visit my website to keep
up to date with
<br>the series and for add on code and articles to the series.
<p>- BR ;)
<br>
<p>*<a NAME="final"></a>FINAL NOTE*
<p>Id really like to thank Bracaman for everything including allowing me
to use code from
<br>his tutorial and please remember that this tutorial should be read
with his (after his
<br>1 even :P), so thanks for everything Bracaman it helped so much :).
<p>
<hr SIZE=1 WIDTH="70%">
<p>APPENDIX A - THE COMPILER<a NAME="appxA"></a>
<br>
<p>All of the programs in this tutorial have been tested under Microsoft
Visual C++ 6.0,
<br>im running Windows 2000 Professional edition and I have an Intel Pentium
2.
<p>To set up the compiler for Winsock programming you need to link Wsock32.lib
to your project.
<br>Under Visual C++ do the following.
<p>1. Select the File view tab.
<br>2. Right Click the files menu and go to Settings.
<br>3. Select the Link tab in Project Settings.
<br>4. Add Wsock32.lib to the list of .lib files and press ok.
<p>The winsock.h header file is included in windows.h so don’t worry about
that.
<p>
<hr SIZE=1 WIDTH="70%">
</body>
</html>
0 comments:
Comment here / Ask your Query !!