Hi everybody,
Does anybody know how is it possible in MASM to listen to a port (e.g port 7777) and also, send packets from a remote host to a specific host on that port and be able to read and retrieve packets ? I have downloaded an ASM webserver from www.japheth.de and this seems to be pretty straightforward but he has used a function which name is listen and has not been implemented in his code. Is it a standard API function ? If yes, how the data can be read from a port ?
Thanks,
Danesh
mail AT japheth DOT de
even though, japeth had resign to be in the masm board; as I can't see his username in the memberlist.
Danesh,
One our members from Melbourne Australia has already written a socket library but had the misfortune of losing it before it was posted. I have no doubt he will get it back up and going shortly and there will be a reliable way to do what you want.
I'm not sure this will help you as far as your question goes but I found a neat little assembly program on the net (don't remember where) but you can download my copy of that project. It's pretty neat and it uses the winsock dll.
http://www.futureedge.com/sparc/sparc.zip
Thanks Hutch. I hope he post it ASAP. I need related funcs badly... ;) Can you please update us when he send his library ? But, the program which Robert recommended was great ! It helps so much. Thank you Robert. BTW, another question. Is it possible to send an email from inside the code to a specific email address ? Well, I am sure it is possible, I need someone to show me the way. I am not asking it because of hacking purposes, I need to write a small executeable program ot be joined to a report generator (for my job) and then I have to send updated info automatically to admin. I am wasn't sure if I should posted my next question into another topic, if so, forgive me.
Here's another sample assembly program that deals with Winsock. I think I got it from this web site but don't remember. Anyway you can download my copy of it from below link.
http://www.futureedge.com/win32asm_710/win32asm_710.zip
From MSDN:
listen
The listen function places a socket in a state in which it is listening for an incoming connection.
int listen(
SOCKET s,
int backlog
);
Parameters
s
[in] Descriptor identifying a bound, unconnected socket.
backlog
[in] Maximum length of the queue of pending connections. If set to SOMAXCONN, the underlying service provider responsible for socket s will set the backlog to a maximum reasonable value. There is no standard provision to obtain the actual backlog value.
Return Values
If no error occurs, listen returns zero. Otherwise, a value of SOCKET_ERROR is returned, and a specific error code can be retrieved by calling WSAGetLastError.Error code Meaning
WSANOTINITIALISED A successful WSAStartup call must occur before using this function.
WSAENETDOWN The network subsystem has failed.
WSAEADDRINUSE The socket's local address is already in use and the socket was not marked to allow address reuse with SO_REUSEADDR. This error usually occurs during execution of the bind function, but could be delayed until this function if the bind was to a partially wildcard address (involving ADDR_ANY) and if a specific address needs to be committed at the time of this function.
WSAEINPROGRESS A blocking Windows Sockets 1.1 call is in progress, or the service provider is still processing a callback function.
WSAEINVAL The socket has not been bound with bind.
WSAEISCONN The socket is already connected.
WSAEMFILE No more socket descriptors are available.
WSAENOBUFS No buffer space is available.
WSAENOTSOCK The descriptor is not a socket.
WSAEOPNOTSUPP The referenced socket is not of a type that supports the listen operation.
Remarks
To accept connections, a socket is first created with the socket function and bound to a local address with the bind function, a backlog for incoming connections is specified with listen, and then the connections are accepted with the accept function. Sockets that are connection oriented, those of type SOCK_STREAM for example, are used with listen. The socket s is put into passive mode where incoming connection requests are acknowledged and queued pending acceptance by the process.
The listen function is typically used by servers that can have more than one connection request at a time. If a connection request arrives and the queue is full, the client will receive an error with an indication of WSAECONNREFUSED.
If there are no available socket descriptors, listen attempts to continue to function. If descriptors become available, a later call to listen or accept will refill the queue to the current or most recent backlog, if possible, and resume listening for incoming connections.
An application can call listen more than once on the same socket. This has the effect of updating the current backlog for the listening socket. Should there be more pending connections than the new backlog value, the excess pending connections will be reset and dropped.
Notes for IrDA Sockets
The Af_irda.h header file must be explicitly included.
Compatibility
The backlog parameter is limited (silently) to a reasonable value as determined by the underlying service provider. Illegal values are replaced by the nearest legal value. There is no standard provision to find out the actual backlog value.
Requirements
Client: Included in Windows XP, Windows 2000 Professional, Windows NT Workstation, Windows Me, Windows 98, and Windows 95.
Server: Included in Windows Server 2003, Windows 2000 Server, and Windows NT Server.
Header: Declared in Winsock2.h.
Library: Use Ws2_32.lib.
For anyone that downloaded that sparc.zip file and either does not have Telnet or does not know how to use it (which I doubt) you can download a small program to communicate with the sparc server.
http://www.futureedge.com/sparc/TalkToSPARC.exe
Thanks Robert for the links, they help so much. Also the listen function description was so useful. I found resv() and send() functions in Winsock library too, at MSDN library which are useful to send and receive data to and from a port, but my problem is sending email from the program. There are many functions in VC and VB tasks, but does anybody know about mailing API functions ?
Regards,
Danesh
Quote from: Danesh on January 05, 2005, 01:49:14 AM
Thanks Robert for the links, they help so much. Also the listen function description was so useful. I found resv() and send() functions in Winsock library too, at MSDN library which are useful to send and receive data to and from a port, but my problem is sending email from the program. There are many functions in VC and VB tasks, but does anybody know about mailing API functions ?
Regards,
Danesh
I have a Winsock API book and it tells you how to do all that neat stuff using pure Winsock commands. All of the program samples in the book are in 'C' but the API's can be used in assembly. And yes, the book does have SMTP samples. Of course, I can't send you the book but I can get the sample programs off the CD and wrap them up in zip files and then post back here with a link to the zip files. Give me a little time to do this, OK.
Thank you Robert. I don't want you to be in trouble, can you please give me the name of that book too, so I will search to see if I can find it ? Which year has it published ? Is it possible to find it now ?
Regards,
Danesh
Quote from: Danesh on January 05, 2005, 03:28:29 AM
Thank you Robert. I don't want you to be in trouble, can you please give me the name of that book too, so I will search to see if I can find it ? Which year has it published ? Is it possible to find it now ?
Regards,
Danesh
Title: "Developing for the Internet with Winsock"
Author: Dave Roberts
Publisher: Coriolis Group Books
Year: 1995
Fax: 602-483-0193
Phone: 800-410-0192
The Coriolis Group
7339 E. Acoma Drive, Suite 7
Scottsdale, AZ 85260
I don't have their Web address but if you do a search on 'coriolis group' through google.com you will get many hits
I know the book is like 10 years old but the stuff in it still applies and I have gone through many of it's chapters with great success.
Quote from: Danesh on January 03, 2005, 08:56:14 PMDoes anybody know how is it possible in MASM to listen to a port (e.g port 7777) and also, send packets from a remote host to a specific host on that port and be able to read and retrieve packets ?
What are your project function & goals?
I find many times, that I do not need to re-invent the wheel. There are many completed and working open source projects to do what I need without too much re-writing.
I believe you need to start with a basic working chat client & server software and work from there.
Regards, P1 :8)
Well, this problem has been solved by great samples from Robert. Now, I am looking around for Mailing APIs. This is not a private project. As I have explained, it is a small program and will run on a server and will listen to a specified port. Under some conditions, it has to send a message to admin's email. Its all and it will install on a local LAN. Almost small LAN.
Regards,
Danesh
Danesh,
OK, Those sample programs can be downloaded from the below link. Keep in mind, however, they are in C/C++ but I have found that it is not a real big problem to translate the C code into assembly code and the API calls are probably the same whether you use them in C or assembly. These are samples from just one of the chapters out of the book and they deal with creating a SMTP Mail Client program. Hope they will do you some good.
You might also go to Google.com and do a search on 'Winsock programs using assembly language'. I already did that and found many pages of good hits so you might find just what you are looking for.
Also, you might try www.programmersheaven.com. I am a member there and they have a hugh resource of sample programs in all languages.
Download sample SMTP at http://www.futureedge.com/smtp/MAIL_WINSOCK.ZIP
http://winprog.org/tutorial/
I was reading this for my C course and it teaches NETWORK programming handling WinHTTP.
don't foget that when your listenning keep your listen() code in a thread, because you 'always' listen.
you don't want your app to be jammed in a endless loop while listenning.
:U
Yes wizzra, you are right. Thanks for the tip. Thank you Robert, for the samples and help and thank you all for your valuable tips.
Regards,
Danesh
Quote from: Danesh on January 05, 2005, 09:13:34 PM... This is not a private project.
Ok. Why are you 'listening' to this port? What is trigger event to signal this e-mail notification to the Admin?
i.e. In one my projects, I used a technique simular to this to monitor Error Messages generated by client software to address the fact users assumed they caused the error and would not report them to me.
Regards, P1 :8)
Hey,
Im the person that hutch is referring too.
Ill be working all day to get the first part of my tutorial up.
It probably wont contain the function your looking for as its a tutorial and im not at that stage yet.
I am, but I dont want to post code for later parts now.
If you need help them PM me or msn me.
Watch the forum for a notification of the web site being up the tutorial being available.
Does anybody know how is it possible in MASM to listen to a port (e.g port 7777) and also, send packets from a remote host to a specific host on that port and be able to read and retrieve packets ?
The answer to the question is yes you can listen to a port. Using listen or WSA equivilant.
Sending and receiving packets is done with other functions but I prefer using select/WSAAsyncSelect or equivilant.
This removes the need to create a thread for each task and connection and makes the resulting application more scalable.
These topics will be covered in the tutorial.
regs striker.
Quote from: Danesh on January 05, 2005, 09:13:34 PM
Well, this problem has been solved by great samples from Robert. Now, I am looking around for Mailing APIs. This is not a private project. As I have explained, it is a small program and will run on a server and will listen to a specified port. Under some conditions, it has to send a message to admin's email. Its all and it will install on a local LAN.
If very limited email functionality is all that is required, why don't you look at using a Windows port of Blam? It is a small exe, you just give it the details on the command line and it puts together and sends the mail for you.
Thanks Striker. I will keep watching the forum for your toturials and I will contact you if I had any problem.
P1, as I said, this is a small program which will install on a server and will listen for some special incoming messages on a specified port. It should also be able to send a message to admin (on his email) to inform him that something need urgent attantion and I think this is exactly what you have done. Sending emails is now clear for me (thanks to Roberts great examples) and I am just working on it.
Sluggy, I don't know anything about Blam. I searched for it, but nothing found. What is it ? Can you explain more ?
Thanks,
Danesh
The winsock framework and tutorials (work in progress) is here: http://www.masmforum.com/simple/index.php?topic=431.0