const + signed patch
Steve G <[email protected]> Thu, 29 Jan 2004 07:35:38 -0800 (PST)
| Newsgroups | gmane.network.zeroconf.workers |
|---|---|
| Message-ID | <[email protected]> |
Hi, This next patch completes the const cleanup and resolves all known signed/unsigned problems. It depends on the other 2 patches having been applied. Best Reagards, -Steve Grubb __________________________________ Do you Yahoo!? Yahoo! SiteBuilder - Free web site building tool. Try it! http://webhosting.yahoo.com/ps/sb/
tmdns-patch3.txt
(text/plain, 15.8 KB)
diff -urBb tmdns-devel-b/server/conf.c tmdns-devel/server/conf.c
--- tmdns-devel-b/server/conf.c 2004-01-27 23:00:12.000000000 -0500
+++ tmdns-devel/server/conf.c 2004-01-29 10:20:42.000000000 -0500
@@ -238,13 +238,13 @@
* end-of-array indicator, must be present and everything below
* this line will be ignored.
*/
- { NULL , NULL , NULL, NULL, NULL , NULL }
+ { NULL , NULL , NULL, NULL, NULL , NULL, NULL }
};
/**************************************************************************
Main function, called from tmdns.c
*/
-int conf_load (char *conf_file)
+int conf_load (const char *conf_file)
{
FILE *fp;
char line[1024], *cmd = NULL, *arg1 = NULL;
@@ -454,11 +454,11 @@
if( (config_params[i].print == NULL) ||
(config_params[i].print == print_dummy))
{
- fprintf(fd, config_params[i].comment);
+ fprintf(fd, "%s", config_params[i].comment);
} else {
fprintf(fd,"# param %s \n" , config_params[i].param_name );
fprintf(fd, "#\n");
- fprintf(fd, config_params[i].comment);
+ fprintf(fd, "%s", config_params[i].comment);
fprintf(fd, "#\n");
fprintf(fd, "# Default : " );
config_params[i].print(fd,config_params[i].def_value );
diff -urBb tmdns-devel-b/server/conf.h tmdns-devel/server/conf.h
--- tmdns-devel-b/server/conf.h 2004-01-27 22:56:03.000000000 -0500
+++ tmdns-devel/server/conf.h 2004-01-29 09:38:19.000000000 -0500
@@ -42,7 +42,7 @@
int dns_port;
int gather_delay;
int allow_nonlocal;
- char * also_local[MAX_ALSO_LOCAL + 1];
+ const char * also_local[MAX_ALSO_LOCAL + 1];
char dynamic_service_file[CONF_PATH_LEN];
};
@@ -56,8 +56,8 @@
* description for parameters in the config file
*/
typedef struct {
- char * param_name; /* name for this parameter */
- char * comment; /* a comment for this parameter */
+ const char * param_name; /* name for this parameter */
+ const char * comment; /* a comment for this parameter */
void * conf_value; /* pointer to a field in struct config */
void * def_value;
conf_copy_func init; /* a function to set the value in 'config'*/
@@ -67,7 +67,7 @@
extern struct config config;
-int conf_load (char *conf_file);
+int conf_load (const char *conf_file);
void conf_defaults (void);
void conf_print(void);
diff -urBb tmdns-devel-b/server/dns.c tmdns-devel/server/dns.c
--- tmdns-devel-b/server/dns.c 2004-01-27 23:00:42.000000000 -0500
+++ tmdns-devel/server/dns.c 2004-01-29 10:01:41.000000000 -0500
@@ -22,14 +22,12 @@
#define BYTESLEFT(x) (x->bufsize - (x->data - x->u.raw) + sizeof(HEADER))
-static dns_soa_rr * fake_soa = NULL;
-
/****************************************************************************
* get the length of the dns message.
*
* @param pkt a pointer to a dns package structure.
****************************************************************************/
-int dns_get_len( dns_t * pkt ) {
+unsigned int dns_get_len( dns_t * pkt ) {
return (pkt->data - pkt->u.raw);
}
/****************************************************************************
@@ -105,7 +103,7 @@
* compress a domain into a message
*
****************************************************************************/
-static int dns_compress_domain( dns_t * pkt , char * domain ) {
+static int dns_compress_domain( dns_t * pkt , const char * domain ) {
int count = 0;
count = dn_comp( domain,
pkt->data , BYTESLEFT(pkt) ,
@@ -122,9 +120,9 @@
* character strings are at most 255 bytes long, all strings are
* prefixed with a length byte.
****************************************************************************/
-static int dns_put_string( dns_t * pkt, char * string ) {
+static int dns_put_string( dns_t * pkt, const char * string ) {
- int slen = strlen(string);
+ size_t slen = strlen(string);
if( slen > 255 ) slen = 255;
if( BYTESLEFT(pkt) < slen + 1 ) return -1;
@@ -172,9 +170,9 @@
*
* @return length of this RR or -1 on error.
****************************************************************************/
-int dns_add_raw_rr( dns_t * pkt, char * domain,
+int dns_add_raw_rr( dns_t * pkt, const char * domain,
short type , short class, long ttl ,
- int rr_len, u_char * rr_data )
+ unsigned int rr_len, u_char * rr_data )
{
int count = 0;
u_char * old_data = pkt->data;
@@ -369,7 +367,7 @@
*
* @return a structure describing the query, NULL on error.
****************************************************************************/
-dns_query * dns_decode_query(u_char * query , int querysize) {
+dns_query * dns_decode_query(u_char * query , unsigned int querysize) {
static dns_query result;
int count = 0;
@@ -460,7 +458,7 @@
u_short dtype;
u_short dclass;
- u_long dttl;
+ long dttl;
char dname[MAXDNAME];
data = query + sizeof(HEADER);
@@ -498,7 +496,7 @@
int ac = 0;
int n = 0;
int count = 0;
- int len = 0;
+ unsigned int length = 0;
u_char * rr_data;
ac = ntohs(hdr->ancount);
@@ -518,14 +516,12 @@
GETSHORT(dtype, data );
GETSHORT(dclass, data );
GETLONG (dttl , data );
- GETSHORT(len , data );
+ GETSHORT(length, data );
rr_data = data;
- data += len;
+ data += length;
- callback(IN_ANSWER_SECT, dname , dtype, dclass, dttl , len, rr_data , userdata);
+ callback(IN_ANSWER_SECT, dname , dtype, dclass, dttl , length, rr_data , userdata);
}
}
-
- return ;
}
diff -urBb tmdns-devel-b/server/dns.h tmdns-devel/server/dns.h
--- tmdns-devel-b/server/dns.h 2004-01-27 22:54:57.000000000 -0500
+++ tmdns-devel/server/dns.h 2004-01-29 10:02:30.000000000 -0500
@@ -74,7 +74,7 @@
/* the query. */
int timeout; /* time when to send back the answer*/
- int bufsize; /* the size of the data buffer */
+ unsigned int bufsize; /* the size of the data buffer */
u_char * data; /* pointer to the first free byte in
the buffer. */
u_char * last_dnptr; /* pointer to the last used entry in
@@ -140,7 +140,7 @@
void dns_init( dns_t * );
-dns_query * dns_decode_query(u_char * query , int querysize);
+dns_query * dns_decode_query(u_char * query , unsigned int querysize);
int dns_init_answer( dns_t * , dns_query * );
@@ -151,11 +151,11 @@
int dns_add_qr( dns_t * pkt , char * domain,
short type, short class);
-int dns_add_raw_rr( dns_t * pkt, char * domain,
+int dns_add_raw_rr( dns_t * pkt, const char * domain,
short type , short class, long ttl ,
- int rr_len, u_char * rr_data );
+ unsigned int rr_len, u_char * rr_data );
-int dns_get_len(dns_t *);
+unsigned int dns_get_len(dns_t *);
int udp_is_bridgesock( int fd );
@@ -167,9 +167,9 @@
} dns_sect;
typedef int (* dnswalk_cb)(dns_sect section,
- char * domain,
+ const char * domain,
int type, int class, long ttl,
- int rr_len ,u_char * rr_data,
+ unsigned int rr_len ,u_char * rr_data,
void * user_data ) ;
void dns_walk_buf ( u_char * buf , int len,
diff -urBb tmdns-devel-b/server/info.c tmdns-devel/server/info.c
--- tmdns-devel-b/server/info.c 2004-01-27 23:03:51.000000000 -0500
+++ tmdns-devel/server/info.c 2004-01-29 10:23:11.000000000 -0500
@@ -31,7 +31,7 @@
*
*****************************************************************************/
static char * escapeDomainLabel(char * label) {
- int needed = 0;
+ unsigned int needed = 0;
char * now = NULL;
char * to = NULL;
char * result = NULL;
@@ -300,7 +300,6 @@
void info_init(void) {
- struct ifconf ifconfig;
struct ifaddrs * ifs = NULL;
struct ifaddrs * ifnow = NULL;
@@ -449,7 +448,7 @@
*****************************************************************************/
int info_search( search_state * state ) {
- char * dname;
+ const char * dname;
short type;
ll_entry_t * startAt = NULL;
ll_entry_t * el = NULL;
@@ -468,7 +467,7 @@
}
}
- if( state->el != NULL );
+ /* if( state->el != NULL ); FIXME - empty if statement */
if( records == NULL ) {
debug("Records array not initialized\n");
@@ -506,9 +505,9 @@
*/
int info_conflict_cb (
dns_sect section,
- char * domain,
+ const char * domain,
int type, int class, long ttl,
- int rr_len ,u_char * rr_data,
+ unsigned int rr_len ,u_char * rr_data,
void * user_data )
{
diff -urBb tmdns-devel-b/server/info.h tmdns-devel/server/info.h
--- tmdns-devel-b/server/info.h 2004-01-27 20:19:32.000000000 -0500
+++ tmdns-devel/server/info.h 2004-01-29 09:51:34.000000000 -0500
@@ -6,7 +6,7 @@
#include "llist.h"
typedef struct {
- char * dname;
+ const char * dname;
short type;
dns_rr * data; /* pointer to the resource record */
ll_entry_t * el; /* where to continue the search */
@@ -21,9 +21,9 @@
int info_conflict_cb (
dns_sect section,
- char * domain,
+ const char * domain,
int type, int class, long ttl,
- int rr_len ,u_char * rr_data,
+ unsigned int rr_len ,u_char * rr_data,
void * user_data );
diff -urBb tmdns-devel-b/server/llist.c tmdns-devel/server/llist.c
--- tmdns-devel-b/server/llist.c 2004-01-27 23:02:10.000000000 -0500
+++ tmdns-devel/server/llist.c 2004-01-29 09:02:37.000000000 -0500
@@ -177,7 +177,7 @@
@param element The element to be moved to the front of the linked list
***************************************************/
-static void ll_to_front(ll_entry_t *element)
+void ll_to_front(ll_entry_t *element)
{
list_t *control;
diff -urBb tmdns-devel-b/server/serv_udp.c tmdns-devel/server/serv_udp.c
--- tmdns-devel-b/server/serv_udp.c 2004-01-27 23:01:13.000000000 -0500
+++ tmdns-devel/server/serv_udp.c 2004-01-29 10:07:13.000000000 -0500
@@ -37,9 +37,9 @@
static int bridge_sock = -1;
static struct sockaddr mcast_v4_sa;
-static char * udp_answerdst2str(dns_t * answer);
+/* static const char * udp_answerdst2str(dns_t * answer); */
static int udp_sock_open( int mcast , struct sockaddr * sock );
-static char * udp_sockaddr_str( struct sockaddr * addr );
+static const char * udp_sockaddr_str( struct sockaddr * addr );
/*****************************************************************************
* open sockets we ar interested in.
@@ -55,7 +55,7 @@
* exclude_devs : device names to exclude when geting the addresses.
* not used yet.
* sockets : Array of intergers where to store the file
- * desctiptors.
+ * descriptors.
*
* Returns:
* number of fd's opened.
@@ -67,7 +67,6 @@
struct ifaddrs * ifnow = NULL;
- int idx;
int sockidx = 0;
if( config.dns_bridge ) {
@@ -335,7 +334,7 @@
#define INET6_ADDRSTRLEN 256
#endif
#define PORT_LEN 7
-static char * udp_sockaddr_str( struct sockaddr * addr ) {
+static const char * udp_sockaddr_str( struct sockaddr * addr ) {
static char result[INET6_ADDRSTRLEN+PORT_LEN+2];
int addr_port;
@@ -361,11 +360,11 @@
}
-static char * udp_answerdst2str(dns_t * answer) {
+/* static const char * udp_answerdst2str(dns_t * answer) {
return udp_sockaddr_str( &(answer->dst_address) );
-}
+}*/
-char * udp_pktsrc2str(struct udp_packet * udp_pkt) {
+const char * udp_pktsrc2str(struct udp_packet * udp_pkt) {
return udp_sockaddr_str( &(udp_pkt->src_address) );
}
diff -urBb tmdns-devel-b/server/serv_udp.h tmdns-devel/server/serv_udp.h
--- tmdns-devel-b/server/serv_udp.h 2004-01-27 22:50:33.000000000 -0500
+++ tmdns-devel/server/serv_udp.h 2004-01-29 10:05:09.000000000 -0500
@@ -11,8 +11,7 @@
void udp_copy_answer_address(dns_t * answer, struct udp_packet * udp_pkt);
-char * udp_sockaddr_str( struct sockaddr * addr );
-char * udp_pktsrc2str(struct udp_packet * udp_pkt);
+const char * udp_pktsrc2str(struct udp_packet * udp_pkt);
#endif /*SERV_UDP_H*/
diff -urBb tmdns-devel-b/server/tmdns.c tmdns-devel/server/tmdns.c
--- tmdns-devel-b/server/tmdns.c 2004-01-27 23:01:39.000000000 -0500
+++ tmdns-devel/server/tmdns.c 2004-01-29 09:56:55.000000000 -0500
@@ -29,20 +29,20 @@
static int handle_query(int sock, struct udp_packet * udp_pkt);
static int store_query(int sock, struct udp_packet * udp_pkt);
static int answer_outstanding_queries(void);
-static void fill_outstanding_queries(int sock, struct udp_packet * udp_pkt);
+static void fill_outstanding_queries(struct udp_packet * udp_pkt);
static int announce( int sock );
static int probe( int sock );
-volatile static int go_down = 0;
-volatile static int do_config = 0;
+static volatile int go_down = 0;
+static volatile int do_config = 0;
-/* a list of domain name suffixes that may be queried per multicast */
-static char * dot_local_domains[] = {
+/* a list of domain name suffixes that may be queried per multicast *
+static const char * dot_local_domains[] = {
".local" ,
".254.169.in-addr.arpa" ,
"0.8.e.f.ip6.arpa" ,
NULL
-};
+}; */
/* list of queries to answer. */
static list_t * query_list = NULL;
@@ -67,7 +67,7 @@
* print usage informations to stderr.
*
*****************************************************************************/
-static void usage(char * program , char * message ) {
+static void usage(const char * program , const char * message ) {
fprintf(stderr,"%s\n" , message );
fprintf(stderr,"%s ver. %s\n" , PACKAGE , VERSION );
fprintf(stderr,"usage : %s [-c <config-file>] [-bdFhP] [-p <port>\n",program );
@@ -97,7 +97,7 @@
int want_version = 0;
int debug_port = 0;
char * progname = argv[0];
- char * confname = NULL;
+ const char * confname = NULL;
conf_defaults();
@@ -362,8 +362,10 @@
}
if( numready != 0 ) {
+#ifdef DEBUG
if( errno != EINTR )
debug_perror("error on select !");
+#endif
continue;
}
@@ -422,7 +424,7 @@
debug(" from local = %d from mcast = %d\n" ,
pkt.from_local , pkt.from_mcast );
- if(numread < sizeof(HEADER)+1 ) {
+ if((size_t)numread < sizeof(HEADER)+1 ) {
debug("invalid size : %d < %d\n",numread,sizeof(HEADER)+1);
syslog(LOG_NOTICE,"dns packet from %s has invalid size of %d bytes.\n",
udp_pktsrc2str(&pkt), numread );
@@ -454,7 +456,7 @@
* we need to add rr's from this anser to
* the query.
*/
- fill_outstanding_queries(sockfd,&pkt);
+ fill_outstanding_queries(&pkt);
} else {
debug("ignore answer\n");
@@ -702,9 +704,9 @@
int didx = 0;
for( didx = 0; config.also_local[didx] != NULL; didx ++ ) {
- char * suffix = config.also_local[didx];
- int suflen = strlen(suffix);
- int qlen = strlen(query->question[n].query_arg);
+ const char * suffix = config.also_local[didx];
+ size_t suflen = strlen(suffix);
+ size_t qlen = strlen(query->question[n].query_arg);
char * end = NULL;
if( qlen < suflen ) {
@@ -825,7 +827,7 @@
char * domain;
int type;
int class;
- int rr_len;
+ unsigned int rr_len;
u_char * rr_data;
} _search_rr;
@@ -837,7 +839,7 @@
dns_sect section,
char * domain,
int type, int class, long ttl,
- int rr_len ,u_char * rr_data,
+ unsigned int rr_len ,u_char * rr_data,
void * user_data )
{
@@ -908,10 +910,10 @@
* Fill the RR's from the answer record we've got into the queries that
* may need them.
*
- * We do no duplicat elimination.
+ * We do no duplicate elimination.
*
*****************************************************************************/
-static void fill_outstanding_queries(int fd, struct udp_packet * pkt) {
+static void fill_outstanding_queries(struct udp_packet * pkt) {
ll_entry_t * el;
el = ll_first(query_list);