1 /*
2  * $Id: helper.h 397 2006-01-28 21:11:50Z calrissian $
3  *
4  * Copyright (C) 2002-2004 Fhg Fokus
5  * Copyright (C) 2004-2005 Nils Ohlmeier
6  *
7  * This file belongs to sipsak, a free sip testing tool.
8  *
9  * sipsak is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 2 of the License, or
12  * (at your option) any later version.
13  *
14  * sipsak is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  * GNU General Public License for more details.
18  */
19 
20 #ifndef SIPSAK_HELPER_H
21 #define SIPSAK_HELPER_H
22 
23 #include "sipsak.h"
24 
25 #ifdef HAVE_SYS_TIME_H
26 # include <sys/time.h>
27 #else
28 # include <time.h>
29 #endif
30 #ifdef HAVE_SYS_SELECT_H
31 # include <sys/socket.h>
32 #endif
33 
34 #ifdef HAVE_CARES_H
35 # define HAVE_SRV
36 #else
37 # ifdef HAVE_RULI_H
38 #  define HAVE_SRV
39 # endif
40 #endif
41 
42 #ifdef HAVE_CARES_H
43 # define CARES_TYPE_A 1
44 # define CARES_TYPE_CNAME 5
45 # define CARES_TYPE_SRV 33
46 # define CARES_CLASS_C_IN 1
47 /* copied from ares_dns.h */
48 # define DNS__16BIT(p)                   (((p)[0] << 8) | (p)[1])
49 # define DNS_HEADER_ANCOUNT(h)           DNS__16BIT((h) + 6)
50 # define DNS_HEADER_NSCOUNT(h)           DNS__16BIT((h) + 8)
51 # define DNS_HEADER_ARCOUNT(h)           DNS__16BIT((h) + 10)
52 # define DNS_RR_TYPE(r)                  DNS__16BIT(r)
53 # define DNS_RR_CLASS(r)                 DNS__16BIT((r) + 2)
54 # define DNS_RR_LEN(r)                   DNS__16BIT((r) + 8)
55 #endif
56 
57 #ifdef HAVE_SRV
58 # define SRV_SIP_TLS "_sip._tls"
59 # define SRV_SIP_TCP "_sip._tcp"
60 # define SRV_SIP_UDP "_sip._udp"
61 #endif
62 
63 int is_ip(char *str);
64 
65 unsigned long getaddress(char *host);
66 
67 unsigned long getsrvadr(char *host, int *port, unsigned int *transport);
68 
69 void get_fqdn();
70 
71 void replace_string(char *mes, char *search, char *replacement);
72 
73 void replace_strings(char *mes, char *strings);
74 
75 void insert_cr(char *mes);
76 
77 void swap_buffers(char *fst, char *snd);
78 
79 void swap_ptr(char **fst, char **snd);
80 
81 void trash_random(char *message);
82 
83 double deltaT(struct timeval *t1p, struct timeval *t2p);
84 
85 int is_number(char *number);
86 
87 int str_to_int(char *num);
88 
89 int read_stdin(char *buf, int size, int ret);
90 
91 void *str_alloc(size_t size);
92 #endif
93