-1

I have been developing an ANTI SPAM system that I call NSA (No Spam Accepted) written in C (going on for 10 years).

My system works on net not content filtering & I have always wanted to add a feature which tries to open a socket to the inbound SMTP server (port 25), while it is attempting to deliver mail to our servers (thus in real time).

I have tried googling:

c program open socket port 25 -command -linux -c# -c++ -perl -excel -php -java -ce -script -vb -autostart.bat

plus many other variations, but no joy. Does anyone have a code snippet that would get me started?

I do not want to 'communicate' with the SMTP server. I just want to confirm that the socket is live. I have found over the years that programs are sending the spam, not SMTP servers. Thus, you cannot telnet to the inbound server & have an SMTP conversation - HELO ...

Anish Ramaswamy
  • 2,326
  • 3
  • 32
  • 63
NG_au
  • 7
  • 2
  • did you know you can already check if ports are open with "ss -pl" ? – tay10r Apr 17 '13 at 05:20
  • Hey Taylor - I appreciate that code snippets can be small but I do not understand "ss -pl" as a c program CS :) – NG_au Apr 17 '13 at 05:41
  • @NG_au `ss` is a linux command. From [`man ss`](http://linux.die.net/man/8/ss): `ss is used to dump socket statistics. It allows showing information similar to netstat. It can display more TCP and state informations than other tools.` – Bechir Apr 17 '13 at 05:53
  • @Bechir, I think the OP wants _code_ that can do this. – Anish Ramaswamy Apr 17 '13 at 05:56
  • i was just suggesting a simple tool if that's all you wanted. as a general guide to the coding, try reading Beej's guide to Network programming - it's very informative. and google sys/socket.h example for some snippets to get you started. – tay10r Apr 17 '13 at 06:09
  • @Taylor - If I understand u, your suggesting I need to check unix man pages for the dumping of socket statistics - this is nothing to do with a C code snippet - but I guess it gets your reply count++ – NG_au Apr 17 '13 at 06:58
  • You seem to be rejecting/ignoring all suggestions involving writing code. If you do not want to write code, why do you have a problem with using what Taylor suggested (viz. `ss -pl`)? – Anish Ramaswamy Apr 17 '13 at 08:38
  • 2
    If you have 10 years experience in network programming I wonder what your problem is? – alk Apr 17 '13 at 12:19

1 Answers1

0

You can create a TCP server which uses port 25. Then, you can execute a recv on that socket. If recv returns -1 and sets errno to ENOTCONN, then the socket is not connected to.

Here is an example TCP server to help you get started.

Anish Ramaswamy
  • 2,326
  • 3
  • 32
  • 63
  • Hey Guys - I am new to this site, so I am guessing you just say the 1st crazy idea that pops into your head for newbies, this is not encouraging me to return - @anish - Why do I need to spend days.weeks ... coding a TCP server - I need a few lines of code that "works" (a lot of example socket code on this site does not work) that show me how to open a socket (TCPIP Address:port) - sends a string & receive a response if there is one ??? – NG_au Apr 17 '13 at 08:31
  • 2
    @NG_au, Please look at my answer carefully. It happens to have a link at the end which includes more than a code snippet for a TCP server which would do more than help you get started. – Anish Ramaswamy Apr 17 '13 at 09:47