Hello,
I have made some additionnal test for sip.c, and I encounter a problem:
if we do 2 tests, one with udp and the other with tcp, the first test will
pass, but the second test will be ignored, and be treated like a
retransmission
(case of 2 tests within one second)
So, I join a little workaround for sip.c, in order to differenciate the 2
tests :
Index: sip.c
===================================================================
--- sip.c (revision 1)
+++ sip.c (revision 2)
@@ -90,6 +90,7 @@
const char *myip;
char *rport= "";
char *proto;
+ int seed;
ASSERT(s);
@@ -104,9 +105,11 @@
case SOCK_DGRAM:
transport="UDP";
rport=";rport";
+ seed=1;
break;
case SOCK_STREAM:
transport="TCP";
+ seed=2;
break;
default:
LogError("Unsupported socket type, only TCP and UDP are supported\n");
@@ -116,7 +119,7 @@
myip= socket_get_local_host(s);
/* initialization of random param */
- srand(time(NULL)+getpid());
+ srand(time(NULL)+getpid()+seed);
if(socket_print(s,
"OPTIONS %s:%s SIP/2.0\r\n"
--
Grasland Pierrick
ENSSAT LSI3
Tutorat NEXCOM Systems
/*
* Copyright (C), 2008 by Bret McDanel <trixter AT 0xdecafbad.com>
* Copyright (C), 2008 by Pierrick Grasland <[EMAIL PROTECTED]>
* All Rights Reserved.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/ >.
*/
#include <config.h>
#ifdef HAVE_STDIO_H
#include <stdio.h>
#endif
#ifdef HAVE_ERRNO_H
#include <errno.h>
#endif
#ifdef HAVE_STRING_H
#include <string.h>
#endif
#ifdef HAVE_TIME_H
#include <time.h>
#endif
#ifdef HAVE_STDLIB_H
#include <stdlib.h>
#endif
#ifdef HAVE_SYS_TYPES_H
#include <sys/types.h>
#endif
#ifdef HAVE_UNISTD_H
#include <unistd.h>
#endif
#ifdef HAVE_ARPA_INET_H
#include <arpa/inet.h>
#endif
#include "protocol.h"
/**
*
* A SIP test.
*
* This test has been created in order to construct valid SIP message,
* even with a low poll cycle. (In case of low poll cycle, chance are
* high for a misinterpretation of the generic test by the SIP AS. It
* will considered it for a retransmission, not for a new message)
*
* The test sends an OPTIONS request and check the server's status code.
*
* The status code must be between 200 and 300
* Return TRUE if the status code is OK, otherwise FALSE
*
* In this current version, redirection is not supported.
*
* @author Pierrick Grasland <[EMAIL PROTECTED]>
* @author Bret McDanel, <trixter AT 0xdecafbad.com>
* @version \$Id: sip.c,v 1.4 2008/01/18 13:48:39 hauk Exp $
*
* @file
*/
/* -------------------------------------------------------------- Public*/
int check_sip(Socket_T s) {
int status;
char buf[STRLEN];
int port;
char *transport;
Port_T P;
const char *request;
const char *myip;
char *rport= "";
char *proto;
int seed;
ASSERT(s);
P= socket_get_Port(s);
ASSERT(P);
request= P->request?P->request:"[EMAIL PROTECTED]";
port = socket_get_local_port(s);
proto = socket_is_secure(s) ? "sips" : "sip";
switch(socket_get_type(s)) {
case SOCK_DGRAM:
transport="UDP";
rport=";rport";
seed=1;
break;
case SOCK_STREAM:
transport="TCP";
seed=2;
break;
default:
LogError("Unsupported socket type, only TCP and UDP are supported\n");
return TRUE;
}
myip= socket_get_local_host(s);
/* initialization of random param */
srand(time(NULL)+getpid()+seed);
if(socket_print(s,
"OPTIONS %s:%s SIP/2.0\r\n"
"Via: SIP/2.0/%s %s:%d;branch=z9hG4bKh%u%s\r\n"
"Max-Forwards: %d\r\n"
"To: <%s:%s>\r\n"
"From: monit <%s:[EMAIL PROTECTED]>;tag=%d\r\n"
"Call-ID: %u\r\n"
"CSeq: 63104 OPTIONS\r\n"
"Contact: <%s:%s:%d>\r\n"
"Accept: application/sdp\r\n"
"Content-Length: 0\r\n"
"User-Agent: %s/%s\r\n\r\n",
proto, // protocol
request, // to
transport, // via transport udp|tcp
myip, // who its from
port, // our port
rand(), // branch
rport, // rport option
P->maxforward, // maximum forwards
proto, // protocol
request, // to
proto, // protocol
myip, // from host
rand(), // tag
rand(), // call id
proto, // protocol
myip, // contact host
port, // contact port
prog, VERSION // user agent
) < 0) {
LogError("SIP: error sending data -- %s\n", STRERROR);
return FALSE;
}
if(! socket_readln(s, buf, sizeof(buf))) {
LogError("SIP: error receiving data -- %s\n", STRERROR);
return FALSE;
}
Util_chomp(buf);
DEBUG("Response from SIP server: %s\n", buf);
if(! sscanf(buf, "%*s %d", &status)) {
LogError("SIP error: cannot parse SIP status in response: %s\n", buf);
return FALSE;
}
if(status >= 400) {
LogError("SIP error: Server returned status %d\n", status);
return FALSE;
}
if(status >= 300 && status < 400) {
LogError("SIP info: Server redirection. Returned status %d\n", status);
return FALSE;
}
if(status > 100 && status < 200) {
LogError("SIP error: Provisional response . Returned status %d\n", status);
return FALSE;
}
return TRUE;
}
_______________________________________________
monit-dev mailing list
[email protected]
http://lists.nongnu.org/mailman/listinfo/monit-dev