This is an old revision of the document!


tcp2sms.are
/* DESC: This script send a SMS received by a TCP message "<number>:<text>"
 * Don't forget to configure and enable the SMS service first
 * The number format is international e.g. +4912345678
 * Copyright (C) 2012 NetModule AG, Switzerland
 */
port = 2000;
 
if ((s = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP))  < 0) exit(1);
if (bind(s, port, "") == -1) exit(2);
if (listen(s, 1) == -1) exit(3);
 
for(;;) {
    if (c = accept(s))
        for(;;) {
            if ((r = select(c, 10)) == - 1) exit(4);
            if (r == 0) continue;
            m = recv(c);
            if (p = strchr(m, ":"))
                if (nb_sms_send(left(m, p), right(m, strlen(m) - p - 1)))
                   send(c, "Spooled\n");
                else
                   send(c, "Error\n");
	}
}