diff --git a/apps/app_chanspy.c b/apps/app_chanspy.c
index 5460e93765bed90695fd629db41cd107c3b8801d..3a27edfcc24776784227cbd10b8be07a423042d3 100644
--- a/apps/app_chanspy.c
+++ b/apps/app_chanspy.c
@@ -439,7 +439,7 @@ static int chanspy_exec(struct ast_channel *chan, void *data)
 
 	if (recbase) {
 		char filename[512];
-		snprintf(filename,sizeof(filename),"%s/%s.%ld.raw",ast_config_AST_MONITOR_DIR, recbase, time(NULL));
+		snprintf(filename,sizeof(filename),"%s/%s.%d.raw",ast_config_AST_MONITOR_DIR, recbase, (int)time(NULL));
 		if ((fd = open(filename, O_CREAT | O_WRONLY, O_TRUNC)) <= 0) {
 			ast_log(LOG_WARNING, "Cannot open %s for recording\n", filename);
 			fd = 0;
diff --git a/apps/app_externalivr.c b/apps/app_externalivr.c
index ad27c16599cc497d92f065f78ebd9047d4fee941..a53a59532b922b56a93e0939460280f30eac41bb 100644
--- a/apps/app_externalivr.c
+++ b/apps/app_externalivr.c
@@ -94,9 +94,9 @@ static void send_child_event(FILE *handle, const char event, const char *data,
 	char tmp[256];
 
 	if (!data) {
-		snprintf(tmp, sizeof(tmp), "%c,%10ld", event, time(NULL));
+		snprintf(tmp, sizeof(tmp), "%c,%10d", event, (int)time(NULL));
 	} else {
-		snprintf(tmp, sizeof(tmp), "%c,%10ld,%s", event, time(NULL), data);
+		snprintf(tmp, sizeof(tmp), "%c,%10d,%s", event, (int)time(NULL), data);
 	}
 
 	fprintf(handle, "%s\n", tmp);
diff --git a/apps/app_queue.c b/apps/app_queue.c
index c425c66ee1441b92ab11fafd2d5ced3c64be7360..c1054de0429a3438cc8aa6b2719f115aa141cd92 100644
--- a/apps/app_queue.c
+++ b/apps/app_queue.c
@@ -484,11 +484,11 @@ static void *changethread(void *data)
 							"Membership: %s\r\n"
 							"Penalty: %d\r\n"
 							"CallsTaken: %d\r\n"
-							"LastCall: %ld\r\n"
+							"LastCall: %d\r\n"
 							"Status: %d\r\n"
 							"Paused: %d\r\n",
 						q->name, cur->interface, cur->dynamic ? "dynamic" : "static",
-						cur->penalty, cur->calls, cur->lastcall, cur->status, cur->paused);
+						cur->penalty, cur->calls, (int)cur->lastcall, cur->status, cur->paused);
 					}
 				}
 			}
@@ -1262,11 +1262,11 @@ static int update_status(struct ast_call_queue *q, struct member *member, int st
 					"Membership: %s\r\n"
 					"Penalty: %d\r\n"
 					"CallsTaken: %d\r\n"
-					"LastCall: %ld\r\n"
+					"LastCall: %d\r\n"
 					"Status: %d\r\n"
 					"Paused: %d\r\n",
 				q->name, cur->interface, cur->dynamic ? "dynamic" : "static",
-				cur->penalty, cur->calls, cur->lastcall, cur->status, cur->paused);
+				cur->penalty, cur->calls, (int)cur->lastcall, cur->status, cur->paused);
 			}
 			break;
 		}
@@ -2421,11 +2421,11 @@ static int add_to_queue(char *queuename, char *interface, int penalty, int pause
 						"Membership: %s\r\n"
 						"Penalty: %d\r\n"
 						"CallsTaken: %d\r\n"
-						"LastCall: %ld\r\n"
+						"LastCall: %d\r\n"
 						"Status: %d\r\n"
 						"Paused: %d\r\n",
 					q->name, new_member->interface, new_member->dynamic ? "dynamic" : "static",
-					new_member->penalty, new_member->calls, new_member->lastcall, new_member->status, new_member->paused);
+					new_member->penalty, new_member->calls, (int)new_member->lastcall, new_member->status, new_member->paused);
 					
 					if (dump)
 						dump_queue_members(q);
@@ -3435,13 +3435,13 @@ static int manager_queues_status( struct mansession *s, struct message *m )
 						"Membership: %s\r\n"
 						"Penalty: %d\r\n"
 						"CallsTaken: %d\r\n"
-						"LastCall: %ld\r\n"
+						"LastCall: %d\r\n"
 						"Status: %d\r\n"
 						"Paused: %d\r\n"
 						"%s"
 						"\r\n",
 							q->name, mem->interface, mem->dynamic ? "dynamic" : "static",
-							mem->penalty, mem->calls, mem->lastcall, mem->status, mem->paused, idText);
+							mem->penalty, mem->calls, (int)mem->lastcall, mem->status, mem->paused, idText);
 				}
 			}
 			/* List Queue Entries */
diff --git a/apps/app_sms.c b/apps/app_sms.c
index c6feb55603c9be8b0f021282453915c448385573..4c15cc185fa28625247f952d2c666e777c85847d 100644
--- a/apps/app_sms.c
+++ b/apps/app_sms.c
@@ -694,7 +694,7 @@ static void sms_readfile (sms_t * h, char *fn)
 		}
 		while (fgets (line, sizeof (line), s))
 		{								 /* process line in file */
-			char *p;
+			unsigned char *p;
 			for (p = line; *p && *p != '\n' && *p != '\r'; p++);
 			*p = 0;					 /* strip eoln */
 			p = line;
@@ -1379,8 +1379,8 @@ static int sms_exec (struct ast_channel *chan, void *data)
 		ast_copy_string (h.cli, chan->cid.cid_num, sizeof (h.cli));
 
 	{
-		char *d = data,
-			*p,
+		unsigned char *p;
+		unsigned char *d = data,
 			answer = 0;
 		if (!*d || *d == '|') {
 			ast_log (LOG_ERROR, "Requires queue name\n");
@@ -1449,7 +1449,7 @@ static int sms_exec (struct ast_channel *chan, void *data)
 			d = p;
 			h.udl = 0;
 			while (*p && h.udl < SMSLEN)
-				h.ud[h.udl++] = utf8decode((unsigned char **)&p);
+				h.ud[h.udl++] = utf8decode(&p);
 			if (is7bit (h.dcs) && packsms7 (0, h.udhl, h.udh, h.udl, h.ud) < 0)
 				ast_log (LOG_WARNING, "Invalid 7 bit GSM data\n");
 			if (is8bit (h.dcs) && packsms8 (0, h.udhl, h.udh, h.udl, h.ud) < 0)
diff --git a/asterisk.c b/asterisk.c
index ce2eacfae4792b7f1696bd42c68ed8bd1f9d8c5d..54c9405fbfa4faac040a0a94026b20c4a12026e9 100644
--- a/asterisk.c
+++ b/asterisk.c
@@ -670,8 +670,10 @@ static int ast_makesocket(void)
 		ast_log(LOG_WARNING, "Unable to change ownership of %s: %s\n", ast_config_AST_SOCKET, strerror(errno));
 
 	if (!ast_strlen_zero(ast_config_AST_CTL_PERMISSIONS)) {
+		int p1;
 		mode_t p;
-		sscanf(ast_config_AST_CTL_PERMISSIONS, "%o", (int *) &p);
+		sscanf(ast_config_AST_CTL_PERMISSIONS, "%o", &p1);
+		p = p1;
 		if ((chmod(ast_config_AST_SOCKET, p)) < 0)
 			ast_log(LOG_WARNING, "Unable to change file permissions of %s: %s\n", ast_config_AST_SOCKET, strerror(errno));
 	}
@@ -1318,7 +1320,7 @@ static char *cli_prompt(EditLine *el)
 			if (*t == '%') {
 				char hostname[MAXHOSTNAMELEN]="";
 				int i;
-				struct timeval tv;
+				time_t ts;
 				struct tm tm;
 #ifdef linux
 				FILE *LOADAVG;
@@ -1346,8 +1348,8 @@ static char *cli_prompt(EditLine *el)
 						break;
 					case 'd': /* date */
 						memset(&tm, 0, sizeof(struct tm));
-						tv = ast_tvnow();
-						if (localtime_r(&(tv.tv_sec), &tm)) {
+						time(&ts);
+						if (localtime_r(&ts, &tm)) {
 							strftime(p, sizeof(prompt) - strlen(prompt), "%Y-%m-%d", &tm);
 						}
 						break;
@@ -1403,8 +1405,8 @@ static char *cli_prompt(EditLine *el)
 #endif
 					case 't': /* time */
 						memset(&tm, 0, sizeof(struct tm));
-						tv = ast_tvnow();
-						if (localtime_r(&(tv.tv_sec), &tm)) {
+						time(&ts);
+						if (localtime_r(&ts, &tm)) {
 							strftime(p, sizeof(prompt) - strlen(prompt), "%H:%M:%S", &tm);
 						}
 						break;
diff --git a/channels/chan_agent.c b/channels/chan_agent.c
index 6362487ea6b6c9cc7606ca5fb01a8ce445005c74..5177f11e1d92c528917501846b659ada9f6cc0df 100644
--- a/channels/chan_agent.c
+++ b/channels/chan_agent.c
@@ -1445,11 +1445,11 @@ static int action_agents(struct mansession *s, struct message *m)
 			"Name: %s\r\n"
 			"Status: %s\r\n"
 			"LoggedInChan: %s\r\n"
-			"LoggedInTime: %ld\r\n"
+			"LoggedInTime: %d\r\n"
 			"TalkingTo: %s\r\n"
 			"%s"
 			"\r\n",
-			p->agent, username, status, loginChan, p->loginstart, talkingtoChan, idText);
+			p->agent, username, status, loginChan, (int)p->loginstart, talkingtoChan, idText);
 		ast_mutex_unlock(&p->lock);
 		p = p->next;
 	}
diff --git a/channels/chan_iax2.c b/channels/chan_iax2.c
index 25ba89f5020bc11653fa5b3dec054fbdbebb1eed..1251c3c73b769e6b840982d08fcc02ca61f4ef32 100644
--- a/channels/chan_iax2.c
+++ b/channels/chan_iax2.c
@@ -2599,7 +2599,7 @@ static struct iax2_peer *realtime_peer(const char *peername, struct sockaddr_in
 				break;
 			} 
 		} else if (!strcasecmp(tmp->name, "regseconds")) {
-			if (sscanf(tmp->value, "%li", &regseconds) != 1)
+			if (sscanf(tmp->value, "%i", (int *)&regseconds) != 1)
 				regseconds = 0;
 		} else if (!strcasecmp(tmp->name, "ipaddr")) {
 			inet_aton(tmp->value, &(peer->addr.sin_addr));
@@ -2638,13 +2638,13 @@ static struct iax2_peer *realtime_peer(const char *peername, struct sockaddr_in
 		if ((nowtime - regseconds) > IAX_DEFAULT_REG_EXPIRE) {
 			memset(&peer->addr, 0, sizeof(peer->addr));
 			if (option_debug)
-				ast_log(LOG_DEBUG, "realtime_peer: Bah, '%s' is expired (%ld/%ld/%ld)!\n",
-						peername, nowtime - regseconds, regseconds, nowtime);
+				ast_log(LOG_DEBUG, "realtime_peer: Bah, '%s' is expired (%d/%d/%d)!\n",
+						peername, (int)(nowtime - regseconds), (int)regseconds, (int)nowtime);
 		}
 		else {
 			if (option_debug)
-				ast_log(LOG_DEBUG, "realtime_peer: Registration for '%s' still active (%ld/%ld/%ld)!\n",
-						peername, nowtime - regseconds, regseconds, nowtime);
+				ast_log(LOG_DEBUG, "realtime_peer: Registration for '%s' still active (%d/%d/%d)!\n",
+						peername, (int)(nowtime - regseconds), (int)regseconds, (int)nowtime);
 		}
 	}
 
@@ -2700,7 +2700,7 @@ static void realtime_update_peer(const char *peername, struct sockaddr_in *sin)
 	time_t nowtime;
 	
 	time(&nowtime);
-	snprintf(regseconds, sizeof(regseconds), "%ld", nowtime);
+	snprintf(regseconds, sizeof(regseconds), "%d", (int)nowtime);
 	ast_inet_ntoa(ipaddr, sizeof(ipaddr), sin->sin_addr);
 	snprintf(port, sizeof(port), "%d", ntohs(sin->sin_port));
 	ast_update_realtime("iaxpeers", "name", peername, "ipaddr", ipaddr, "port", port, "regseconds", regseconds, NULL);
@@ -4285,7 +4285,7 @@ static int iax2_show_firmware(int fd, int argc, char *argv[])
 #if !defined(__FreeBSD__)
 #define FORMAT "%-15.15s  %-15d %-15d\n"
 #else /* __FreeBSD__ */
-#define FORMAT "%-15.15s  %-15d %-15ld\n"
+#define FORMAT "%-15.15s  %-15d %-15d\n" /* XXX 2.95 ? */
 #endif /* __FreeBSD__ */
 	struct iax_firmware *cur;
 	if ((argc != 3) && (argc != 4))
@@ -4296,7 +4296,7 @@ static int iax2_show_firmware(int fd, int argc, char *argv[])
 	for (cur = waresl.wares;cur;cur = cur->next) {
 		if ((argc == 3) || (!strcasecmp(argv[3], (char *)cur->fwh->devname))) 
 			ast_cli(fd, FORMAT, cur->fwh->devname, ntohs(cur->fwh->version),
-				ntohl(cur->fwh->datalen));
+				(int)ntohl(cur->fwh->datalen));
 	}
 	ast_mutex_unlock(&waresl.lock);
 	return RESULT_SUCCESS;
diff --git a/channels/chan_sip.c b/channels/chan_sip.c
index a04d8e2632879e0dec8d7a07d55525529794a273..5ceaf1e5e317266c7d3ab0310e6b34cfbb90099e 100644
--- a/channels/chan_sip.c
+++ b/channels/chan_sip.c
@@ -1598,7 +1598,7 @@ static void realtime_update_peer(const char *peername, struct sockaddr_in *sin,
 		time_t nowtime;
 		time(&nowtime);
 		nowtime += expirey;
-		snprintf(regseconds, sizeof(regseconds), "%ld", nowtime);	/* Expiration time */
+		snprintf(regseconds, sizeof(regseconds), "%d", (int)nowtime);	/* Expiration time */
 		ast_inet_ntoa(ipaddr, sizeof(ipaddr), sin->sin_addr);
 		snprintf(port, sizeof(port), "%d", ntohs(sin->sin_port));
 	}
@@ -12058,7 +12058,7 @@ static struct sip_peer *build_peer(const char *name, struct ast_variable *v, int
 		}
 
 		if (realtime && !strcasecmp(v->name, "regseconds")) {
-			if (sscanf(v->value, "%li", &regseconds) != 1)
+			if (sscanf(v->value, "%i", (int *)&regseconds) != 1)
 				regseconds = 0;
 		} else if (realtime && !strcasecmp(v->name, "ipaddr") && !ast_strlen_zero(v->value) ) {
 			inet_aton(v->value, &(peer->addr.sin_addr));
@@ -12221,7 +12221,7 @@ static struct sip_peer *build_peer(const char *name, struct ast_variable *v, int
 			destroy_association(peer);
 			memset(&peer->addr, 0, sizeof(peer->addr));
 			if (option_debug)
-				ast_log(LOG_DEBUG, "Bah, we're expired (%ld/%ld/%ld)!\n", nowtime - regseconds, regseconds, nowtime);
+				ast_log(LOG_DEBUG, "Bah, we're expired (%d/%d/%d)!\n", (int)(nowtime - regseconds), (int)regseconds, (int)nowtime);
 		}
 	}
 	ast_copy_flags(peer, &peerflags, mask.flags);
diff --git a/cli.c b/cli.c
index a06f19f65708e271899acbd4d3516acb0e9b2253..98a50aee7cbd6d5938c3fe249967d4a6b424e8f8 100644
--- a/cli.c
+++ b/cli.c
@@ -368,7 +368,7 @@ static int handle_showuptime(int fd, int argc, char *argv[])
 	if (ast_startuptime) {
 		tmptime = curtime - ast_startuptime;
 		if (printsec) {
-			ast_cli(fd, "System uptime: %lu\n",tmptime);
+			ast_cli(fd, "System uptime: %lu\n",(u_long)tmptime);
 		} else {
 			timestr = format_uptimestr(tmptime);
 			if (timestr) {
@@ -380,7 +380,7 @@ static int handle_showuptime(int fd, int argc, char *argv[])
 	if (ast_lastreloadtime) {
 		tmptime = curtime - ast_lastreloadtime;
 		if (printsec) {
-			ast_cli(fd, "Last reload: %lu\n", tmptime);
+			ast_cli(fd, "Last reload: %lu\n", (u_long) tmptime);
 		} else {
 			timestr = format_uptimestr(tmptime);
 			if ((timestr) && (!printsec)) {
diff --git a/config.c b/config.c
index 447db67314c29e0496b1881423131ed50d226d03..dda916e209daceea10cb7f3eb8c5587198a5e0f0 100644
--- a/config.c
+++ b/config.c
@@ -470,7 +470,7 @@ static int process_text_line(struct ast_config *cfg, struct ast_category **cat,
 				/* #exec </path/to/executable>
 				   We create a tmp file, then we #include it, then we delete it. */
 				if (do_exec) { 
-					snprintf(exec_file, sizeof(exec_file), "/var/tmp/exec.%ld.%ld", time(NULL), (long)pthread_self());
+					snprintf(exec_file, sizeof(exec_file), "/var/tmp/exec.%d.%ld", (int)time(NULL), (long)pthread_self());
 					snprintf(cmd, sizeof(cmd), "%s > %s 2>&1", cur, exec_file);
 					ast_safe_system(cmd);
 					cur = exec_file;
diff --git a/pbx/pbx_dundi.c b/pbx/pbx_dundi.c
index 1e5f7446f952ee8f89dff1a893820df185695e0a..86e35a7f7e59a50ce6bb8d1aa89753d3a0fde833 100644
--- a/pbx/pbx_dundi.c
+++ b/pbx/pbx_dundi.c
@@ -1149,7 +1149,7 @@ static int cache_lookup_internal(time_t now, struct dundi_request *req, char *ke
 	/* Build request string */
 	if (!ast_db_get("dundi/cache", key, data, sizeof(data))) {
 		ptr = data;
-		if (sscanf(ptr, "%ld|%n", &timeout, &length) == 1) {
+		if (sscanf(ptr, "%d|%n", (int *)&timeout, &length) == 1) {
 			expiration = timeout - now;
 			if (expiration > 0) {
 				ast_log(LOG_DEBUG, "Found cache expiring in %d seconds!\n", (int)(timeout - now));
@@ -2032,7 +2032,7 @@ static void save_secret(const char *newkey, const char *oldkey)
 		snprintf(tmp, sizeof(tmp), "%s", newkey);
 	rotatetime = time(NULL) + DUNDI_SECRET_TIME;
 	ast_db_put(secretpath, "secret", tmp);
-	snprintf(tmp, sizeof(tmp), "%ld", rotatetime);
+	snprintf(tmp, sizeof(tmp), "%d", (int)rotatetime);
 	ast_db_put(secretpath, "secretexpiry", tmp);
 }
 
@@ -2044,7 +2044,7 @@ static void load_password(void)
 	time_t expired;
 	
 	ast_db_get(secretpath, "secretexpiry", tmp, sizeof(tmp));
-	if (sscanf(tmp, "%ld", &expired) == 1) {
+	if (sscanf(tmp, "%d", (int *)&expired) == 1) {
 		ast_db_get(secretpath, "secret", tmp, sizeof(tmp));
 		current = strchr(tmp, ';');
 		if (!current)
diff --git a/res/res_monitor.c b/res/res_monitor.c
index d805788eb65a3fe0129a4b14540d8e359325181f..660757b5865dbed21ddaec5876165e651ffa2781 100644
--- a/res/res_monitor.c
+++ b/res/res_monitor.c
@@ -150,8 +150,8 @@ int ast_monitor_start(	struct ast_channel *chan, const char *format_spec,
 				while((p = strchr(channel_name, '/'))) {
 					*p = '-';
 				}
-				snprintf(monitor->filename_base, FILENAME_MAX, "%s/%ld-%s",
-						 ast_config_AST_MONITOR_DIR, time(NULL),channel_name);
+				snprintf(monitor->filename_base, FILENAME_MAX, "%s/%d-%s",
+						 ast_config_AST_MONITOR_DIR, (int)time(NULL),channel_name);
 				monitor->filename_changed = 1;
 			} else {
 				ast_log(LOG_ERROR,"Failed to allocate Memory\n");