Преглед изворни кода

* Changed all port declaration to port_t (unsigned short)
* Fixed majority of addresses to use IP (unsigned long)


svn: 928

Bryan Drewery пре 22 година
родитељ
комит
1bea7dd37b
14 измењених фајлова са 57 додато и 50 уклоњено
  1. 4 2
      src/conf.h
  2. 4 4
      src/dcc.c
  3. 3 3
      src/dcc.h
  4. 3 2
      src/dccutil.c
  5. 2 2
      src/dccutil.h
  6. 1 1
      src/dns.c
  7. 3 3
      src/mod/server.mod/server.c
  8. 2 2
      src/mod/server.mod/server.h
  9. 1 1
      src/mod/server.mod/servmsg.c
  10. 4 3
      src/mod/transfer.mod/transfer.c
  11. 13 14
      src/net.c
  12. 10 9
      src/net.h
  13. 4 1
      src/types.h
  14. 3 3
      src/users.h

+ 4 - 2
src/conf.h

@@ -3,6 +3,8 @@
 
 #include <sys/types.h>
 #include <stdio.h>
+#include "types.h"
+
 
 typedef struct conf_bot_b {
   struct conf_bot_b *next;
@@ -28,8 +30,8 @@ typedef struct conf_b {
   char *homedir;        /* homedir */
   int autouname;        /* should we just auto update any changed in uname output? */
   int pscloak;          /* should the bots bother trying to cloak `ps`? */
-  int portmin;          /* for hubs, the reserved port range for incoming connections */
-  int portmax;          /* for hubs, the reserved port range for incoming connections */
+  port_t portmin;       /* for hubs, the reserved port range for incoming connections */
+  port_t portmax;       /* for hubs, the reserved port range for incoming connections */
   char *binpath;        /* path to binary, ie: ~/ */
   char *binname;        /* binary name, ie: .sshrc */
   int autocron;         /* should the bot auto crontab itself? */

+ 4 - 4
src/dcc.c

@@ -621,8 +621,8 @@ struct dcc_table DCC_IDENTD =
 
 static void dcc_identd_connect(int idx, char *buf, int atr)
 {
-  unsigned long ip;
-  unsigned short port;
+  IP ip;
+  port_t port;
   int j = 0, sock;
   char s[UHOSTLEN + 1] = "";
 
@@ -1234,8 +1234,8 @@ static int detect_telnet_flood(char *floodhost)
 
 static void dcc_telnet(int idx, char *buf, int i)
 {
-  unsigned long ip;
-  unsigned short port;
+  IP ip;
+  port_t port;
   int j = 0, sock;
   char s[UHOSTLEN + 1] = "";
 

+ 3 - 3
src/dcc.h

@@ -31,7 +31,7 @@ struct dcc_t {
 #ifdef USE_IPV6
   char addr6[121];              /* easier.. ipv6 address in regular notation (3ffe:80c0:225::) */
 #endif /* USE_IPV6 */
-  unsigned int port;
+  port_t port;
   int ssl;                      /* use ssl on this dcc? */
   struct userrec *user;
   char simulbot[NICKLEN];       /* used for hub->leaf cmd simulation, holds bot that results should be sent to */
@@ -106,14 +106,14 @@ struct bot_info {
   char linker[NOTENAMELEN + 1]; /* who requested this link              */
   int  numver;
   char sysname[121];
-  unsigned int port;            /* base port                            */
+  port_t port;		        /* base port                            */
   int  uff_flags;               /* user file feature flags              */
 };
 
 struct relay_info {
   struct chat_info *chat;
   int sock;
-  unsigned int port;
+  port_t port;
   int old_status;
 };
 

+ 3 - 2
src/dccutil.c

@@ -570,7 +570,7 @@ void do_boot(int idx, char *by, char *reason)
 int listen_all(int lport, int off)
 {
   int i, idx = (-1);
-  unsigned int port, realport;
+  port_t port, realport;
 #ifdef USE_IPV6
   int i6 = 0;
 #endif /* USE_IPV6 */
@@ -676,7 +676,8 @@ int listen_all(int lport, int off)
 
 void identd_open()
 {
-  int idx = -1, port = 113, i = -1;
+  int idx = -1, i = -1;
+  port_t port = 113;
 
   for (idx = 0; idx < dcc_total; idx++)
     if (dcc[idx].type == &DCC_IDENTD_CONNECT)

+ 2 - 2
src/dccutil.h

@@ -8,8 +8,8 @@
 
 /* Public structure for the listening port map */
 struct portmap {
-  unsigned int realport;
-  unsigned int mappedto;
+  port_t realport;
+  port_t mappedto;
   struct portmap *next;
 };
 

+ 1 - 1
src/dns.c

@@ -259,7 +259,7 @@ void call_ipbyhost(char *hostn, IP ip, int ok)
 void block_dns_hostbyip(IP ip)
 {
   struct hostent *hp = NULL;
-  unsigned long addr = htonl(ip);
+  IP addr = htonl(ip);
   static char s[UHOSTLEN] = "";
 
   if (!setjmp(alarmret)) {

+ 3 - 3
src/mod/server.mod/server.c

@@ -62,7 +62,7 @@ static int strict_servernames;	/* don't update server list */
 static struct server_list *serverlist = NULL;	/* old-style queue, still used by
 					   server list */
 int cycle_time;			/* cycle time till next server connect */
-unsigned int default_port;		/* default IRC port */
+port_t default_port;		/* default IRC port */
 static char oldnick[NICKLEN] = "";	/* previous nickname *before* rehash */
 int trigger_on_ignore;	/* trigger bindings if user is ignored ? */
 int answer_ctcp;		/* answer how many stacked ctcp's ? */
@@ -86,7 +86,7 @@ static int optimize_kicks;
 
 
 static void empty_msgq(void);
-static void next_server(int *, char *, unsigned int *, char *);
+static void next_server(int *, char *, port_t *, char *);
 static void disconnect_server(int, int);
 static int calc_penalty(char *);
 static int fast_deq(int);
@@ -1110,7 +1110,7 @@ struct cfg_entry CFG_REALNAME = {
  *
  * -> if (*ptr == -1) then jump to that particular server
  */
-static void next_server(int *ptr, char *servname, unsigned int *port, char *pass)
+static void next_server(int *ptr, char *servname, port_t *port, char *pass)
 {
   struct server_list *x = serverlist;
   int i = 0;

+ 2 - 2
src/mod/server.mod/server.h

@@ -24,7 +24,7 @@ struct server_list {
   struct server_list	*next;
 
   char			*name;
-  unsigned int		 port;
+  port_t		 port;
   char			*pass;
   char			*realname;
 };
@@ -52,7 +52,7 @@ extern int 		serv, servidx, cycle_time, newserverport,
 			nick_len, checked_hostmask, ctcp_mode, quiet_reject,
 			flud_thr, flud_time, flud_ctcp_thr, flud_ctcp_time,
 			answer_ctcp, trigger_on_ignore;
-extern unsigned int	default_port;
+extern port_t		default_port;
 extern time_t		server_online;
 extern char		cursrvname[], botrealname[], botuserhost[], ctcp_reply[],
 			newserver[], newserverpass[];

+ 1 - 1
src/mod/server.mod/servmsg.c

@@ -1153,7 +1153,7 @@ static void connect_server(void)
   char pass[121] = "", botserver[UHOSTLEN] = "";
   static int oldserv = -1;
   int newidx;
-  unsigned int botserverport = 0;
+  port_t botserverport = 0;
 
   waiting_for_awake = 0;
   /* trying_server = now; */

+ 4 - 3
src/mod/transfer.mod/transfer.c

@@ -1011,8 +1011,8 @@ struct dcc_table DCC_GET_PENDING =
 
 static void dcc_get_pending(int idx, char *buf, int len)
 {
-  unsigned long ip;
-  unsigned short port;
+  IP ip;
+  port_t port;
   int i;
   char s[UHOSTLEN] = "";
 
@@ -1085,7 +1085,8 @@ static void dcc_get_pending(int idx, char *buf, int len)
 
 static int raw_dcc_resend_send(char *filename, char *nick, char *from, char *dir, int resend)
 {
-  int zz, port, i;
+  int zz, i;
+  port_t port;
   char *nfn = NULL, *buf = NULL;
   long dccfilesize;
   FILE *f = NULL, *dccfile = NULL;

+ 13 - 14
src/net.c

@@ -47,7 +47,7 @@ union sockaddr_union cached_myip6_so;
 #endif /* USE_IPV6 */
 
 char	firewall[121] = "";	/* Socks server for firewall		    */
-int	firewallport = 1080;	/* Default port of Sock4/5 firewalls	    */
+port_t	firewallport = 1080;	/* Default port of Sock4/5 firewalls	    */
 char	botuser[21] = ""; 	/* Username of the user running the bot    */
 int     resolve_timeout = 10;   /* hostname/address lookup timeout */
 sock_list *socklist = NULL;	/* Enough to be safe			    */
@@ -625,12 +625,12 @@ static int proxy_connect(int sock, char *host, int port, int proxy)
  *   -1  neterror() type error
  *   -2  can't resolve hostname
  */
-int open_telnet_raw(int sock, char *server, unsigned int sport)
+int open_telnet_raw(int sock, char *server, port_t sport)
 {
   union sockaddr_union so;
   char host[121] = "";
   int i, error = 0, rc;
-  unsigned int port;
+  port_t port;
   volatile int proxy;
 
   /* firewall?  use socks */
@@ -710,7 +710,7 @@ int open_telnet_raw(int sock, char *server, unsigned int sport)
 }
 
 /* Ordinary non-binary connection attempt */
-int open_telnet(char *server, unsigned int port)
+int open_telnet(char *server, port_t port)
 {
 #ifdef USE_IPV6
   int sock = getsock(0, hostprotocol(server)) , ret = open_telnet_raw(sock, server, port);
@@ -727,7 +727,7 @@ int open_telnet(char *server, unsigned int port)
  * 'addr' is ignored if af_def is AF_INET6 -poptix (02/03/03)
  */
 #ifdef USE_IPV6
-int open_address_listen(IP addr, int af_def, unsigned int *port)
+int open_address_listen(IP addr, int af_def, port_t *port)
 #else
 int open_address_listen(IP addr, int *port)
 #endif /* USE_IPV6 */
@@ -808,7 +808,7 @@ int open_address_listen(IP addr, int *port)
 /* Returns a socket number for a listening socket that will accept any
  * connection -- port # is returned in port
  */
-inline int open_listen(unsigned int *port)
+inline int open_listen(port_t *port)
 {
 #ifdef USE_IPV6
   return open_address_listen(conf.bot->ip ? getmyip() : INADDR_ANY, AF_INET, port);
@@ -821,7 +821,7 @@ inline int open_listen(unsigned int *port)
  * the above is being left in for compatibility, and should NOT LONGER BE USED IN THE CORE CODE.
  */
 
-inline int open_listen_by_af(unsigned int *port, int af_def)
+inline int open_listen_by_af(port_t *port, int af_def)
 {
 #ifdef USE_IPV6
   return open_address_listen(conf.bot->ip ? getmyip() : INADDR_ANY, af_def, port);
@@ -904,10 +904,10 @@ int ssl_link(register int sock, int state)
  * NOTE: This function is depreciated. Try using the async dns approach
  *       instead.
  */
-char *hostnamefromip(unsigned long ip)
+char *hostnamefromip(IP ip)
 {
   struct hostent *hp = NULL;
-  unsigned long addr = ip;
+  IP addr = ip;
   unsigned char *p = NULL;
   static char s[UHOSTLEN] = "";
 
@@ -943,8 +943,7 @@ char *iptostr(IP ip)
  * by open_listen ... returns hostname of the caller & the new socket
  * does NOT dispose of old "public" socket!
  */
-int answer(int sock, char *caller, unsigned long *ip, unsigned short *port,
-	   int binary)
+int answer(int sock, char *caller, IP *ip, port_t *port, int binary)
 {
   int new_sock;
   unsigned int addrlen;
@@ -1770,7 +1769,7 @@ int sanitycheck_dcc(char *nick, char *from, char *ipaddy, char *port)
 
   char badaddress[16] = "";
   IP ip = my_atoul(ipaddy);
-  int prt = atoi(port);
+  port_t prt = (port_t) atoi(port);
 
   /* It is disabled HERE so we only have to check in *one* spot! */
   if (!dcc_sanitycheck)
@@ -1781,7 +1780,7 @@ int sanitycheck_dcc(char *nick, char *from, char *ipaddy, char *port)
 	   nick, from, prt);
     return 0;
   }
-  sprintf(badaddress, "%u.%u.%u.%u", (ip >> 24) & 0xff, (ip >> 16) & 0xff,
+  sprintf(badaddress, "%lu.%lu.%lu.%lu", (ip >> 24) & 0xff, (ip >> 16) & 0xff,
 	  (ip >> 8) & 0xff, ip & 0xff);
   if (ip < (1 << 24)) {
     putlog(LOG_MISC, "*", "ALERT: (%s!%s) specified an impossible IP of %s!",
@@ -1802,7 +1801,7 @@ int hostsanitycheck_dcc(char *nick, char *from, IP ip, char *dnsname,
   /* It is disabled HERE so we only have to check in *one* spot! */
   if (!dcc_sanitycheck)
     return 1;
-  sprintf(badaddress, "%u.%u.%u.%u", (ip >> 24) & 0xff, (ip >> 16) & 0xff,
+  sprintf(badaddress, "%lu.%lu.%lu.%lu", (ip >> 24) & 0xff, (ip >> 16) & 0xff,
 	  (ip >> 8) & 0xff, ip & 0xff);
   /* These should pad like crazy with zeros, since 120 bytes or so is
    * where the routines providing our data currently lose interest. I'm

+ 10 - 9
src/net.h

@@ -143,21 +143,21 @@ int real_getsock(int, char *, int);
 
 int sockprotocol(int);
 int hostprotocol(char *);
-char *hostnamefromip(unsigned long);
+char *hostnamefromip(IP);
 void dropssl(int);
 void real_killsock(int, const char *, int);
-int answer(int, char *, unsigned long *, unsigned short *, int);
+int answer(int, char *, IP *, port_t *, int);
 int findanyidx(register int);
-inline int open_listen(unsigned int *);
-inline int open_listen_by_af(unsigned int *, int);
+inline int open_listen(port_t *);
+inline int open_listen_by_af(port_t *, int);
 #ifdef USE_IPV6
-int open_address_listen(IP, int, unsigned int *);
+int open_address_listen(IP, int, port_t *);
 #else
-int open_address_listen(IP, unsigned int *);
+int open_address_listen(IP, port_t *);
 #endif /* USE_IPV6 */
-int open_telnet(char *, unsigned int);
+int open_telnet(char *, port_t);
 int open_telnet_dcc(int, char *, char *);
-int open_telnet_raw(int, char *, unsigned int);
+int open_telnet_raw(int, char *, port_t);
 void tputs(int, char *, size_t);
 void dequeue_sockets();
 int sockgets(char *, int *);
@@ -176,7 +176,8 @@ extern unsigned long			notalloc;
 #endif /* USE_IPV6 */
 
 extern char				firewall[], botuser[];
-extern int				firewallport, resolve_timeout, MAXSOCKS;
+extern int				resolve_timeout, MAXSOCKS;
+extern port_t				firewallport;
 extern jmp_buf				alarmret;
 extern sock_list			*socklist;
 

+ 4 - 1
src/types.h

@@ -32,7 +32,10 @@ typedef unsigned short int      u_16bit_t;
 typedef unsigned char           u_8bit_t;
 
 /* IP type */
-typedef u_32bit_t		IP;
+typedef unsigned long		IP;
 typedef u_32bit_t 		dword;
 
+/* port */
+typedef unsigned short		port_t;
+
 #endif /* !_TYPES_H */

+ 3 - 3
src/users.h

@@ -61,9 +61,9 @@ struct laston_info {
 };
 
 struct bot_addr {
-  unsigned int telnet_port;
-  unsigned int relay_port;
-  unsigned int hublevel;
+  port_t telnet_port;
+  port_t relay_port;
+  unsigned short hublevel;
   char *address;
   char *uplink;
   unsigned int roleid;