News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

Listening to a port

Started by Danesh, January 03, 2005, 08:56:14 PM

Previous topic - Next topic

Danesh

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


pbrennick


Statix Star

even though, japeth had resign to be in the masm board; as I can't see his username in the memberlist.

hutch--

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.
Download site for MASM32      New MASM Forum
https://masm32.com          https://masm32.com/board/index.php

Robert Collins

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

Danesh

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.


Robert Collins

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

The Dude of Dudes

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.


Robert Collins

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

Danesh

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


Robert Collins

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.

Danesh

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


Robert Collins

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.

P1

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)

Danesh

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