diff --git a/apps/app_dial.c b/apps/app_dial.c
index d9b068dc7bd97db00b67eb805c8da41bf93d8ba7..ac97f5a323bdb976ba8c147eb948244481e13535 100644
--- a/apps/app_dial.c
+++ b/apps/app_dial.c
@@ -109,7 +109,8 @@ static char *descrip =
 "           party has answered, but before the call gets bridged. The 'called'\n"
 "           DTMF string is sent to the called party, and the 'calling' DTMF\n"
 "           string is sent to the calling party. Both parameters can be used\n"
-"           alone.\n"  	
+"           alone.\n"
+"    e    - execute the 'h' extension for peer after the call ends\n"
 "    f    - Force the callerid of the *calling* channel to be set as the\n"
 "           extension associated with the channel using a dialplan 'hint'.\n"
 "           For example, some PSTNs do not allow CallerID to be set to anything\n"
@@ -256,10 +257,11 @@ enum {
 	OPT_IGNORE_FORWARDING = (1 << 27),
 	OPT_CALLEE_GOSUB =	(1 << 28),
 	OPT_CANCEL_ELSEWHERE =  (1 << 29),
+	OPT_PEER_H =            (1 << 30),
 };
 
-#define DIAL_STILLGOING			(1 << 30)
-#define DIAL_NOFORWARDHTML		(1 << 31)
+#define DIAL_STILLGOING			(1 << 31)
+#define DIAL_NOFORWARDHTML		((uint64_t)1 << 32) /* flags are now 64 bits, so keep it up! */
 
 enum {
 	OPT_ARG_ANNOUNCE = 0,
@@ -282,6 +284,7 @@ AST_APP_OPTIONS(dial_exec_options, {
 	AST_APP_OPTION('c', OPT_CANCEL_ELSEWHERE),
 	AST_APP_OPTION('d', OPT_DTMF_EXIT),
 	AST_APP_OPTION_ARG('D', OPT_SENDDTMF, OPT_ARG_SENDDTMF),
+	AST_APP_OPTION('e', OPT_PEER_H),
 	AST_APP_OPTION('f', OPT_FORCECLID),
 	AST_APP_OPTION('g', OPT_GO_ON),
 	AST_APP_OPTION_ARG('G', OPT_GOTO, OPT_ARG_GOTO),
@@ -314,7 +317,7 @@ AST_APP_OPTIONS(dial_exec_options, {
 struct chanlist {
 	struct chanlist *next;
 	struct ast_channel *chan;
-	unsigned int flags;
+	uint64_t flags;
 	int forwards;
 };
 
@@ -1789,7 +1792,29 @@ static int dial_exec_full(struct ast_channel *chan, void *data, struct ast_flags
 
 		snprintf(toast, sizeof(toast), "%ld", (long)(end_time - start_time));
 		pbx_builtin_setvar_helper(chan, "DIALEDTIME", toast);
-
+		
+		
+		if (ast_test_flag(&opts, OPT_PEER_H)) {
+			ast_log(LOG_NOTICE,"PEER context: %s; PEER exten: %s;  PEER priority: %d\n", 
+					peer->context, peer->exten, peer->priority);
+		}
+		
+		strcpy(peer->context, chan->context);
+
+		if (ast_test_flag(&opts, OPT_PEER_H) && ast_exists_extension(peer, peer->context, "h", 1, peer->cid.cid_num)) {
+			strcpy(peer->exten, "h");
+			peer->priority = 1;
+			while (ast_exists_extension(peer, peer->context, peer->exten, peer->priority, peer->cid.cid_num)) {
+				if ((res = ast_spawn_extension(peer, peer->context, peer->exten, peer->priority, peer->cid.cid_num))) {
+					/* Something bad happened, or a hangup has been requested. */
+					ast_debug(1, "Spawn extension (%s,%s,%d) exited non-zero on '%s'\n", peer->context, peer->exten, peer->priority, peer->name);
+					if (option_verbose > 1)
+						ast_verbose( VERBOSE_PREFIX_2 "Spawn extension (%s, %s, %d) exited non-zero on '%s'\n", peer->context, peer->exten, peer->priority, peer->name);
+					break;
+				}
+				peer->priority++;
+			}
+		}
 		if (res != AST_PBX_NO_HANGUP_PEER) {
 			if (!chan->_softhangup)
 				chan->hangupcause = peer->hangupcause;
diff --git a/apps/app_minivm.c b/apps/app_minivm.c
index 2bc3da3b77f8f4aa53d7367fa82f8600e871b855..24ebd0cb9215aeb5626296fe3b86b2ff56384efa 100644
--- a/apps/app_minivm.c
+++ b/apps/app_minivm.c
@@ -364,7 +364,7 @@ struct minivm_account {
 	char attachfmt[80];		/*!< Format for voicemail audio file attachment */
 	char etemplate[80];		/*!< Pager template */
 	char ptemplate[80];		/*!< Voicemail format */
-	unsigned int flags;		/*!< MVM_ flags */	
+	uint64_t flags;	    	/*!< MVM_ flags */	
 	struct ast_variable *chanvars;	/*!< Variables for e-mail template */
 	double volgain;			/*!< Volume gain for voicemails sent via e-mail */
 	AST_LIST_ENTRY(minivm_account) list;	
@@ -395,7 +395,7 @@ static AST_LIST_HEAD_STATIC(message_templates, minivm_template);
 
 /*! \brief Options for leaving voicemail with the voicemail() application */
 struct leave_vm_options {
-	unsigned int flags;
+	uint64_t flags;
 	signed char record_gain;
 };
 
diff --git a/apps/app_mixmonitor.c b/apps/app_mixmonitor.c
index fbbde45aa36f70d4c2a3d5df17bb67fdf901d089..3df6676dc9b771177a4cc6b1ae9815ed6e0bf1ce 100644
--- a/apps/app_mixmonitor.c
+++ b/apps/app_mixmonitor.c
@@ -97,7 +97,7 @@ struct mixmonitor {
 	char *filename;
 	char *post_process;
 	char *name;
-	unsigned int flags;
+	uint64_t flags;
 };
 
 enum {
@@ -226,7 +226,7 @@ static void *mixmonitor_thread(void *obj)
 	return NULL;
 }
 
-static void launch_monitor_thread(struct ast_channel *chan, const char *filename, unsigned int flags,
+static void launch_monitor_thread(struct ast_channel *chan, const char *filename, uint64_t flags,
 				  int readvol, int writevol, const char *post_process) 
 {
 	pthread_t thread;
diff --git a/apps/app_voicemail.c b/apps/app_voicemail.c
index b700e76b2ab181ce805b8646a4c7d43370d0ae73..96461fce9a0e8d1d148e0e7f45b911ea7dd2f600 100644
--- a/apps/app_voicemail.c
+++ b/apps/app_voicemail.c
@@ -370,7 +370,7 @@ struct ast_vm_user {
 	char uniqueid[20];               /*!< Unique integer identifier */
 	char exit[80];
 	char attachfmt[20];              /*!< Attachment format */
-	unsigned int flags;              /*!< VM_ flags */	
+	uint64_t flags;              /*!< VM_ flags */	
 	int saydurationm;
 	int maxmsg;                      /*!< Maximum number of msgs per folder for this mailbox */
 	int maxsecs;                     /*!< Maximum number of seconds per message for this mailbox */
@@ -2193,7 +2193,7 @@ static int sendmail(char *srcemail, struct ast_vm_user *vmu, int msgnum, char *c
 	}
 	if (!strcmp(format, "wav49"))
 		format = "WAV";
-	ast_debug(3, "Attaching file '%s', format '%s', uservm is '%d', global is %d\n", attach, format, attach_user_voicemail, ast_test_flag((&globalflags), VM_ATTACH));
+	ast_debug(3, "Attaching file '%s', format '%s', uservm is '%d', global is %lld\n", attach, format, attach_user_voicemail, ast_test_flag((&globalflags), VM_ATTACH));
 	/* Make a temporary file instead of piping directly to sendmail, in case the mail
 	   command hangs */
 	if ((p = vm_mkftemp(tmp)) == NULL) {
@@ -2991,7 +2991,7 @@ static void run_externnotify(char *context, char *extension)
 }
 
 struct leave_vm_options {
-	unsigned int flags;
+	uint64_t flags;
 	signed char record_gain;
 };
 
diff --git a/channels/chan_iax2.c b/channels/chan_iax2.c
index 2e452c3892be06db6404f4e9c71995b83c3a1c03..eb804a8543910acea91fdee5c45882a7909c479c 100644
--- a/channels/chan_iax2.c
+++ b/channels/chan_iax2.c
@@ -315,7 +315,7 @@ struct iax2_user {
 	int encmethods;
 	int amaflags;
 	int adsi;
-	unsigned int flags;
+	uint64_t flags;
 	int capability;
 	int maxauthreq; /*!< Maximum allowed outstanding AUTHREQs */
 	int curauthreq; /*!< Current number of outstanding AUTHREQs */
@@ -353,7 +353,7 @@ struct iax2_peer {
 	int sockfd;					/*!< Socket to use for transmission */
 	struct in_addr mask;
 	int adsi;
-	unsigned int flags;
+	uint64_t flags;
 
 	/* Dynamic Registration fields */
 	struct sockaddr_in defaddr;			/*!< Default address if there is one */
@@ -604,7 +604,7 @@ struct chan_iax2_pvt {
 	/*! Associated peer for poking */
 	struct iax2_peer *peerpoke;
 	/*! IAX_ flags */
-	unsigned int flags;
+	uint64_t flags;
 	int adsi;
 
 	/*! Transferring status */
@@ -2758,7 +2758,7 @@ static void realtime_update_peer(const char *peername, struct sockaddr_in *sin,
 
 struct create_addr_info {
 	int capability;
-	unsigned int flags;
+	uint64_t flags;
 	int maxtime;
 	int encmethods;
 	int found;
diff --git a/channels/chan_local.c b/channels/chan_local.c
index b4072cecc46a8710777ef2fa2818ac96302f99a7..b1bca29a6a657d252698b439d5ee1009e5b6d554 100644
--- a/channels/chan_local.c
+++ b/channels/chan_local.c
@@ -104,7 +104,7 @@ static const struct ast_channel_tech local_tech = {
 
 struct local_pvt {
 	ast_mutex_t lock;			/* Channel private lock */
-	unsigned int flags;                     /* Private flags */
+	uint64_t flags;                     /* Private flags */
 	char context[AST_MAX_CONTEXT];		/* Context to call */
 	char exten[AST_MAX_EXTENSION];		/* Extension to call */
 	int reqformat;				/* Requested format */
diff --git a/channels/chan_sip.c b/channels/chan_sip.c
index 18cb4aa653eff66f951213a56a28f5abd0f821ee..b22d798ff4d94b570e10793774231477c3c2378c 100644
--- a/channels/chan_sip.c
+++ b/channels/chan_sip.c
@@ -639,7 +639,7 @@ struct sip_request {
 	int headers;            /*!< # of SIP Headers */
 	int method;             /*!< Method of this request */
 	int lines;              /*!< Body Content */
-	unsigned int flags;     /*!< SIP_PKT Flags for this packet */
+	uint64_t flags;     /*!< SIP_PKT Flags for this packet */
 	char *header[SIP_MAX_HEADERS];
 	char *line[SIP_MAX_LINES];
 	char data[SIP_MAX_PACKET];
@@ -1080,7 +1080,7 @@ struct sip_pkt {
 	int retrans;				/*!< Retransmission number */
 	int method;				/*!< SIP method for this packet */
 	int seqno;				/*!< Sequence number */
-	unsigned int flags;			/*!< non-zero if this is a response packet (e.g. 200 OK) */
+	uint64_t flags;			/*!< non-zero if this is a response packet (e.g. 200 OK) */
 	struct sip_pvt *owner;			/*!< Owner AST call */
 	int retransid;				/*!< Retransmission ID */
 	int timer_a;				/*!< SIP timer A, retransmission timer */
@@ -11536,7 +11536,7 @@ static int sip_show_channel(int fd, int argc, char *argv[])
 				ast_cli(fd, "  Original uri:           %s\n", cur->uri);
 			if (!ast_strlen_zero(cur->cid_num))
 				ast_cli(fd, "  Caller-ID:              %s\n", cur->cid_num);
-			ast_cli(fd, "  Need Destroy:           %d\n", ast_test_flag(&cur->flags[0], SIP_NEEDDESTROY));
+			ast_cli(fd, "  Need Destroy:           %lld\n", ast_test_flag(&cur->flags[0], SIP_NEEDDESTROY));
 			ast_cli(fd, "  Last Message:           %s\n", cur->lastmsg);
 			ast_cli(fd, "  Promiscuous Redir:      %s\n", ast_test_flag(&cur->flags[0], SIP_PROMISCREDIR) ? "Yes" : "No");
 			ast_cli(fd, "  Route:                  %s\n", cur->route ? cur->route->hop : "N/A");
diff --git a/channels/iax2-provision.c b/channels/iax2-provision.c
index 962e6d9582b36e772dfa0da0f24b53cf04462577..8c20ab88a5786c35e64d0ae7b43dfbe94c6d5a40 100644
--- a/channels/iax2-provision.c
+++ b/channels/iax2-provision.c
@@ -69,7 +69,7 @@ struct iax_template {
 	unsigned int server;
 	unsigned short serverport;
 	unsigned int altserver;
-	unsigned int flags;
+	uint64_t flags;
 	unsigned int format;
 	unsigned int tos;	
 } *templates;
@@ -88,7 +88,7 @@ static struct iax_flag {
 	{ "disable3way", PROV_FLAG_DIS_THREEWAY },
 };
 
-char *iax_provflags2str(char *buf, int buflen, unsigned int flags)
+char *iax_provflags2str(char *buf, int buflen, uint64_t flags)
 {
 	int x;
 
@@ -117,7 +117,7 @@ static unsigned int iax_str2flags(const char *buf)
 	int x;
 	int len;
 	int found;
-	unsigned int flags = 0;
+	uint64_t flags = 0;
 	char *e;
 	while(buf && *buf) {
 		e = strchr(buf, ',');
diff --git a/channels/iax2-provision.h b/channels/iax2-provision.h
index d951502532479728cb55ae89e6888cdaa75a34ba..a54aaebfd403a88692f9630c7674b679c4f261c6 100644
--- a/channels/iax2-provision.h
+++ b/channels/iax2-provision.h
@@ -45,7 +45,7 @@
 #define PROV_FLAG_DIS_CIDCW		(1 << 6)	/* CID/CW Disabled */
 #define PROV_FLAG_DIS_THREEWAY	(1 << 7)	/* Three-way calling, transfer disabled */
 
-char *iax_provflags2str(char *buf, int buflen, unsigned int flags);
+char *iax_provflags2str(char *buf, int buflen, uint64_t flags);
 int iax_provision_reload(void);
 int iax_provision_unload(void);
 int iax_provision_build(struct iax_ie_data *provdata, unsigned int *signature, const char *template, int force);
diff --git a/funcs/func_odbc.c b/funcs/func_odbc.c
index 4852a08673d3c4692a364bd9e96ee6051b192186..10758680a9f82dd0d25158f53c7f32315274725c 100644
--- a/funcs/func_odbc.c
+++ b/funcs/func_odbc.c
@@ -67,7 +67,7 @@ struct acf_odbc_query {
 	char writehandle[5][30];
 	char sql_read[2048];
 	char sql_write[2048];
-	unsigned int flags;
+	uint64_t flags;
 	int rowlimit;
 	struct ast_custom_function *acf;
 };
diff --git a/include/asterisk/abstract_jb.h b/include/asterisk/abstract_jb.h
index 145256fcf433bba1679b2e6a03693fda141f3f8f..37ff5b9d38017064a3b6edebc52ee8e5db141d02 100644
--- a/include/asterisk/abstract_jb.h
+++ b/include/asterisk/abstract_jb.h
@@ -55,7 +55,7 @@ enum {
 struct ast_jb_conf
 {
 	/*! \brief Combination of the AST_JB_ENABLED, AST_JB_FORCED and AST_JB_LOG flags. */
-	unsigned int flags;
+	uint64_t flags;
 	/*! \brief Max size of the jitterbuffer implementation. */
 	long max_size;
 	/*! \brief Resynchronization threshold of the jitterbuffer implementation. */
@@ -98,7 +98,7 @@ struct ast_jb
 	/*! \brief File for frame timestamp tracing. */
 	FILE *logfile;
 	/*! \brief Jitterbuffer internal state flags. */
-	unsigned int flags;
+	uint64_t flags;
 };
 
 
diff --git a/include/asterisk/cdr.h b/include/asterisk/cdr.h
index cdbf35e09e80d40148ea8651169cde2858e3717d..f8d4b5d8dff5c5e8544b12340bc5ca01444b8f5d 100644
--- a/include/asterisk/cdr.h
+++ b/include/asterisk/cdr.h
@@ -83,7 +83,7 @@ struct ast_cdr {
 	/*! What account number to use */
 	char accountcode[AST_MAX_ACCOUNT_CODE];			
 	/*! flags */
-	unsigned int flags;				
+	uint64_t flags;				
 	/*! Unique Channel Identifier */
 	char uniqueid[32];
 	/*! User field */
diff --git a/include/asterisk/channel.h b/include/asterisk/channel.h
index 9bfc3dd4dcba09adc115e8bf18f06ad66d52395a..0a5b7c1a067a6dbf6487f61b3dec417908184119 100644
--- a/include/asterisk/channel.h
+++ b/include/asterisk/channel.h
@@ -468,7 +468,7 @@ struct ast_channel {
 								(see \ref AstChanVar ) */
 	ast_group_t callgroup;				/*!< Call group for call pickups */
 	ast_group_t pickupgroup;			/*!< Pickup group - which calls groups can be picked up? */
-	unsigned int flags;				/*!< channel flags of AST_FLAG_ type */
+	uint64_t flags;				/*!< channel flags of AST_FLAG_ type */
 	unsigned short transfercapability;		/*!< ISDN Transfer Capbility - AST_FLAG_DIGITAL is not enough */
 	AST_LIST_HEAD_NOLOCK(, ast_frame) readq;
 	int alertpipe[2];
@@ -567,7 +567,7 @@ struct ast_bridge_config {
 	const char *end_sound;
 	const char *start_sound;
 	int firstpass;
-	unsigned int flags;
+	uint64_t flags;
 };
 
 struct chanmon;
diff --git a/include/asterisk/chanspy.h b/include/asterisk/chanspy.h
index 8550210d030fff4d38d4a67753f76b653f00de26..f8a979dd537e0342216f86665486ba4b6fe0ab58 100644
--- a/include/asterisk/chanspy.h
+++ b/include/asterisk/chanspy.h
@@ -61,7 +61,7 @@ struct ast_channel_spy {
 	struct ast_channel *chan;
 	struct ast_channel_spy_queue read_queue;
 	struct ast_channel_spy_queue write_queue;
-	unsigned int flags;
+	uint64_t flags;
 	enum chanspy_states status;
 	const char *type;
 	/* The volume adjustment values are very straightforward:
diff --git a/include/asterisk/dundi.h b/include/asterisk/dundi.h
index e588338ae6a3d6b70bb8b440542c940913f72b45..bc64576ef55de42dd005ad9f622ecc25016c66d0 100644
--- a/include/asterisk/dundi.h
+++ b/include/asterisk/dundi.h
@@ -192,7 +192,7 @@ struct dundi_peer_status {
 #define DEFAULT_MAXMS			2000
 
 struct dundi_result {
-	unsigned int flags;
+	uint64_t flags;
 	int weight;
 	int expiration;
 	int techint;
diff --git a/include/asterisk/features.h b/include/asterisk/features.h
index 5e9d5f3d2de669a583492c4ad28f8f7a41c70930..c59acca16ec123ff3ce79a430f0643673165853b 100644
--- a/include/asterisk/features.h
+++ b/include/asterisk/features.h
@@ -39,7 +39,7 @@ struct ast_call_feature {
 	char exten[FEATURE_MAX_LEN];
 	char default_exten[FEATURE_MAX_LEN];
 	int (*operation)(struct ast_channel *chan, struct ast_channel *peer, struct ast_bridge_config *config, char *code, int sense);
-	unsigned int flags;
+	uint64_t flags;
 	char app[FEATURE_APP_LEN];		
 	char app_args[FEATURE_APP_ARGS_LEN];
 	char moh_class[FEATURE_MOH_LEN];
diff --git a/include/asterisk/jabber.h b/include/asterisk/jabber.h
index 53c3fbed51377a1aa0f4ace3b714d74e8984d942..028d0bc3a14d6f995b362d71780bd4873a88a023 100644
--- a/include/asterisk/jabber.h
+++ b/include/asterisk/jabber.h
@@ -102,7 +102,7 @@ struct aji_buddy {
 	char channel[160];
 	struct aji_resource *resources;
 	enum aji_btype btype;
-	unsigned int flags;
+	uint64_t flags;
 };
 
 struct aji_buddy_container {
@@ -137,7 +137,7 @@ struct aji_client {
 	int timeout;
 	int message_timeout;
 	int authorized;
-	unsigned int flags;
+	uint64_t flags;
 	int component; /* 0 client,  1 component */
 	struct aji_buddy_container buddies;
 	AST_LIST_HEAD(messages,aji_message) messages;
diff --git a/include/asterisk/module.h b/include/asterisk/module.h
index d53e6086ce4788517a7f9392957c0a56a140b543..d75e2d4fcfdc7c825a166b8419c5881cef1d7949 100644
--- a/include/asterisk/module.h
+++ b/include/asterisk/module.h
@@ -215,7 +215,7 @@ struct ast_module_info {
 	 */
 
 	const char *key;
-	unsigned int flags;
+	uint64_t flags;
 };
 
 void ast_module_register(const struct ast_module_info *);
diff --git a/include/asterisk/speech.h b/include/asterisk/speech.h
index 02d056f336ea59662b4c0fdeedb0aa0a3fbcefd5..b3b853bf296fd367aec4f1fb03cf3f77a5a07b57 100644
--- a/include/asterisk/speech.h
+++ b/include/asterisk/speech.h
@@ -51,7 +51,7 @@ struct ast_speech {
 	/*! Structure lock */
 	ast_mutex_t lock;
 	/*! Set flags */
-	unsigned int flags;
+	uint64_t flags;
 	/*! Processing sound (used when engine is processing audio and getting results) */
 	char *processing_sound;
 	/*! Current state of structure */
diff --git a/include/asterisk/utils.h b/include/asterisk/utils.h
index 76f90c7b0403e255a3ce40211f20545d90439b12..e87157f2f59312aab012bf9fb741224328753f29 100644
--- a/include/asterisk/utils.h
+++ b/include/asterisk/utils.h
@@ -50,7 +50,7 @@
    your variable.
 
    The flag macros below use a set of compiler tricks to verify
-   that the caller is using an "unsigned int" variable to hold
+   that the caller is using an "unsigned long long" variable to hold
    the flags, and nothing else. If the caller uses any other
    type of variable, a warning message similar to this:
 
@@ -64,7 +64,7 @@
  \endverbatim
 */
 
-extern unsigned int __unsigned_int_flags_dummy;
+extern uint64_t __unsigned_int_flags_dummy;
 
 #define ast_test_flag(p,flag) 		({ \
 					typeof ((p)->flags) __p = (p)->flags; \
@@ -146,7 +146,7 @@ extern unsigned int __unsigned_int_flags_dummy;
 /*! \brief Structure used to handle boolean flags 
 */
 struct ast_flags {
-	unsigned int flags;
+	uint64_t flags;
 };
 
 struct ast_hostent {
diff --git a/main/channel.c b/main/channel.c
index 105dc030e5842244609717f650c137319917a54f..be1b293fa1b4f228ad6d9ed998ce8c8c8eb1edd1 100644
--- a/main/channel.c
+++ b/main/channel.c
@@ -2454,7 +2454,7 @@ done:
 int ast_internal_timing_enabled(struct ast_channel *chan)
 {
 	int ret = ast_opt_internal_timing && chan->timingfd > -1;
-	ast_debug(5, "Internal timing is %s (option_internal_timing=%d chan->timingfd=%d)\n", ret? "enabled": "disabled", ast_opt_internal_timing, chan->timingfd);
+	ast_debug(5, "Internal timing is %s (option_internal_timing=%lld chan->timingfd=%d)\n", ret? "enabled": "disabled", ast_opt_internal_timing, chan->timingfd);
 	return ret;
 }
 
diff --git a/main/loader.c b/main/loader.c
index 5f29fc6b9891eed4b6d392dc4c2dea9935356eb0..20227b59ebb24e5624d6f1b840261233a3c275c1 100644
--- a/main/loader.c
+++ b/main/loader.c
@@ -86,8 +86,8 @@ struct ast_module {
 	int usecount;					/* the number of 'users' currently in this module */
 	struct module_user_list users;			/* the list of users in the module */
 	struct {
-		unsigned int running:1;
-		unsigned int declined:1;
+		uint64_t running:1;
+		uint64_t declined:1;
 	} flags;
 	AST_LIST_ENTRY(ast_module) entry;
 	char resource[0];
diff --git a/main/rtp.c b/main/rtp.c
index 8aa86a61378de7fb0d6828068fa3836823397043..0cba1a984adc88affaa227cc1a04f1f4d14183ed 100644
--- a/main/rtp.c
+++ b/main/rtp.c
@@ -152,7 +152,7 @@ struct ast_rtp {
 	int send_payload;
 	int send_duration;
 	int nat;
-	unsigned int flags;
+	uint64_t flags;
 	struct sockaddr_in us;		/*!< Socket representation of the local endpoint. */
 	struct sockaddr_in them;	/*!< Socket representation of the remote endpoint. */
 	struct timeval rxcore;
@@ -845,7 +845,7 @@ static struct ast_frame *process_cisco_dtmf(struct ast_rtp *rtp, unsigned char *
 	char resp = 0;
 	struct ast_frame *f = NULL;
 	unsigned char seq;
-	unsigned int flags;
+	uint64_t flags;
 	unsigned int power;
 
 	/* We should have at least 4 bytes in RTP data */
@@ -888,7 +888,7 @@ static struct ast_frame *process_cisco_dtmf(struct ast_rtp *rtp, unsigned char *
 	event = data[3] & 0x1f;
 
 	if (option_debug > 2 || rtpdebug)
-		ast_debug(0, "Cisco DTMF Digit: %02x (len=%d, seq=%d, flags=%02x, power=%d, history count=%d)\n", event, len, seq, flags, power, (len - 4) / 2);
+		ast_debug(0, "Cisco DTMF Digit: %02x (len=%d, seq=%d, flags=%02llx, power=%d, history count=%d)\n", event, len, seq, flags, power, (len - 4) / 2);
 	if (event < 10) {
 		resp = '0' + event;
 	} else if (event < 11) {
diff --git a/pbx/pbx_dundi.c b/pbx/pbx_dundi.c
index e63f903978ef1adb5217af243c0bdbe2358cb5b6..b21b17ec97083e00f754f0bdcf464b6bba561298 100644
--- a/pbx/pbx_dundi.c
+++ b/pbx/pbx_dundi.c
@@ -179,7 +179,7 @@ struct dundi_transaction {
 	dundi_eid them_eid;                            /*!< Their EID, to us */
 	ast_aes_encrypt_key ecx;                       /*!< AES 128 Encryption context */
 	ast_aes_decrypt_key dcx;                       /*!< AES 128 Decryption context */
-	unsigned int flags;                            /*!< Has final packet been sent */
+	uint64_t flags;                                /*!< Has final packet been sent */
 	int ttl;                                       /*!< Remaining TTL for queries on this one */
 	int thread;                                    /*!< We have a calling thread */
 	int retranstimer;                              /*!< How long to wait before retransmissions */
@@ -892,7 +892,7 @@ static int cache_save(dundi_eid *eidpeer, struct dundi_request *req, int start,
 		/* Skip anything with an illegal pipe in it */
 		if (strchr(req->dr[x].dest, '|'))
 			continue;
-		snprintf(data + strlen(data), sizeof(data) - strlen(data), "%d/%d/%d/%s/%s|", 
+		snprintf(data + strlen(data), sizeof(data) - strlen(data), "%lld/%d/%d/%s/%s|", 
 			req->dr[x].flags, req->dr[x].weight, req->dr[x].techint, req->dr[x].dest, 
 			dundi_eid_to_str_short(eidpeer_str, sizeof(eidpeer_str), &req->dr[x].eid));
 	}
@@ -1154,7 +1154,7 @@ static int cache_lookup_internal(time_t now, struct dundi_request *req, char *ke
 				if (option_debug)
 					ast_log(LOG_DEBUG, "Found cache expiring in %d seconds!\n", expiration);
 				ptr += length + 1;
-				while((sscanf(ptr, "%d/%d/%d/%n", &(flags.flags), &weight, &tech, &length) == 3)) {
+				while((sscanf(ptr, "%lld/%d/%d/%n", &(flags.flags), &weight, &tech, &length) == 3)) {
 					ptr += length;
 					term = strchr(ptr, '|');
 					if (term) {
diff --git a/res/res_features.c b/res/res_features.c
index 3f71bfadfeb380be78292a5bbc3ba5392b58f82d..c01c11802db39e0891a09e8e741b95fbb5a10e7d 100644
--- a/res/res_features.c
+++ b/res/res_features.c
@@ -1318,7 +1318,7 @@ static int ast_feature_interpret(struct ast_channel *chan, struct ast_channel *p
 		ast_copy_flags(&features, &(config->features_caller), AST_FLAGS_ALL);
 	else
 		ast_copy_flags(&features, &(config->features_callee), AST_FLAGS_ALL);
-	ast_debug(3, "Feature interpret: chan=%s, peer=%s, sense=%d, features=%d\n", chan->name, peer->name, sense, features.flags);
+	ast_debug(3, "Feature interpret: chan=%s, peer=%s, sense=%d, features=%lld\n", chan->name, peer->name, sense, features.flags);
 
 	ast_rwlock_rdlock(&features_lock);
 	for (x = 0; x < FEATURES_COUNT; x++) {
diff --git a/res/res_musiconhold.c b/res/res_musiconhold.c
index 84a44f3b75e1b816f3267f6a3312de64ee4e5af1..ce0eb8a1e421ca7cfaea6b8a572814c980a7d475 100644
--- a/res/res_musiconhold.c
+++ b/res/res_musiconhold.c
@@ -138,7 +138,7 @@ struct mohclass {
 	int allowed_files;
 	/*! The current number of files loaded into the filearray */
 	int total_files;
-	unsigned int flags;
+	uint64_t flags;
 	/*! The format from the MOH source, not applicable to "files" mode */
 	int format;
 	/*! The pid of the external application delivering MOH */
diff --git a/utils/ael_main.c b/utils/ael_main.c
index 9cd0bfd0898321fdf8be063cab135b5c9d602879..df8a01c37f7dfa65eab1709c0c609dcde3b61d5d 100644
--- a/utils/ael_main.c
+++ b/utils/ael_main.c
@@ -9,6 +9,7 @@
 #include <regex.h>
 #include <limits.h>
 
+#include "asterisk/compat.h"
 #include "asterisk/ast_expr.h"
 #include "asterisk/channel.h"
 #include "asterisk/module.h"
diff --git a/utils/check_expr.c b/utils/check_expr.c
index 7f0378b1614bf51ae865ea29a8d4136970bec9e4..f64147242d5d5b0cd2f1a12b6189c9cb3987bd77 100644
--- a/utils/check_expr.c
+++ b/utils/check_expr.c
@@ -21,6 +21,7 @@
 #include <stdarg.h>
 #include <string.h>
 #include <stdlib.h>
+#include <../include/asterisk/compat.h>
 #include <../include/asterisk/ast_expr.h>
 
 static int global_lineno = 1;