[asterisk-commits] elguero: trunk r362432 - /trunk/tests/test_security_events.c

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Wed Apr 18 12:03:26 CDT 2012


Author: elguero
Date: Wed Apr 18 12:03:16 2012
New Revision: 362432

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=362432
Log:
Fix building security events test

The Security Events Framework API changed in trunk to support IPv6.  This broke
the building of the security events test which was based around IPv4.  This
patches fixes the build by changing the test to conform to the new changes.

(related to issue ASTERISK-19447)

Review: https://reviewboard.asterisk.org/r/1874/

Modified:
    trunk/tests/test_security_events.c

Modified: trunk/tests/test_security_events.c
URL: http://svnview.digium.com/svn/asterisk/trunk/tests/test_security_events.c?view=diff&rev=362432&r1=362431&r2=362432
==============================================================================
--- trunk/tests/test_security_events.c (original)
+++ trunk/tests/test_security_events.c Wed Apr 18 12:03:16 2012
@@ -1,7 +1,7 @@
 /*
  * Asterisk -- An open source telephony toolkit.
  *
- * Copyright (C) 2009, Digium, Inc.
+ * Copyright (C) 2012, Digium, Inc.
  *
  * Russell Bryant <russell at digium.com>
  *
@@ -36,6 +36,7 @@
 #include "asterisk/cli.h"
 #include "asterisk/utils.h"
 #include "asterisk/security_events.h"
+#include "asterisk/netsock2.h"
 
 static void evt_gen_failed_acl(void);
 static void evt_gen_inval_acct_id(void);
@@ -70,12 +71,9 @@
 
 static void evt_gen_failed_acl(void)
 {
-	struct sockaddr_in sin_local = {
-		.sin_family = AF_INET
-	};
-	struct sockaddr_in sin_remote = {
-		.sin_family = AF_INET
-	};
+	struct ast_sockaddr addr_local = { {0,} };
+	struct ast_sockaddr addr_remote = { {0,} };
+
 	struct timeval session_tv = ast_tvnow();
 	struct ast_security_event_failed_acl failed_acl_event = {
 		.common.event_type = AST_SECURITY_EVENT_FAILED_ACL,
@@ -86,34 +84,34 @@
 		.common.session_id = "Session123",
 		.common.session_tv = &session_tv,
 		.common.local_addr = {
-			.sin  = &sin_local,
-			.transport  = AST_SECURITY_EVENT_TRANSPORT_UDP,
-		},
-		.common.remote_addr = {
-			.sin = &sin_remote,
+			.addr  = &addr_local,
+			.transport  = AST_SECURITY_EVENT_TRANSPORT_UDP,
+		},
+		.common.remote_addr = {
+			.addr = &addr_remote,
 			.transport  = AST_SECURITY_EVENT_TRANSPORT_UDP,
 		},
 
 		.acl_name   = "TEST_ACL",
 	};
 
-	inet_aton("192.168.1.1", &sin_local.sin_addr);
-	sin_local.sin_port = htons(12121);
-
-	inet_aton("192.168.1.2", &sin_remote.sin_addr);
-	sin_remote.sin_port = htons(12345);
+	char localaddr[53];
+	char remoteaddr[53];
+
+	ast_copy_string(localaddr, "192.168.1.1:12121", sizeof(localaddr));
+	ast_copy_string(remoteaddr, "192.168.1.2:12345", sizeof(remoteaddr));
+
+	ast_sockaddr_parse(&addr_local, localaddr, 0);
+	ast_sockaddr_parse(&addr_remote, remoteaddr, 0);
 
 	ast_security_event_report(AST_SEC_EVT(&failed_acl_event));
 }
 
 static void evt_gen_inval_acct_id(void)
 {
-	struct sockaddr_in sin_local = {
-		.sin_family = AF_INET
-	};
-	struct sockaddr_in sin_remote = {
-		.sin_family = AF_INET
-	};
+	struct ast_sockaddr addr_local = { {0,} };
+	struct ast_sockaddr addr_remote = { {0,} };
+
 	struct timeval session_tv = ast_tvnow();
 	struct ast_security_event_inval_acct_id inval_acct_id = {
 		.common.event_type = AST_SECURITY_EVENT_INVAL_ACCT_ID,
@@ -124,32 +122,32 @@
 		.common.session_id = "Session456",
 		.common.session_tv = &session_tv,
 		.common.local_addr = {
-			.sin  = &sin_local,
-			.transport  = AST_SECURITY_EVENT_TRANSPORT_TCP,
-		},
-		.common.remote_addr = {
-			.sin = &sin_remote,
-			.transport  = AST_SECURITY_EVENT_TRANSPORT_TCP,
-		},
-	};
-
-	inet_aton("10.1.2.3", &sin_local.sin_addr);
-	sin_local.sin_port = htons(4321);
-
-	inet_aton("10.1.2.4", &sin_remote.sin_addr);
-	sin_remote.sin_port = htons(1234);
+			.addr  = &addr_local,
+			.transport  = AST_SECURITY_EVENT_TRANSPORT_TCP,
+		},
+		.common.remote_addr = {
+			.addr = &addr_remote,
+			.transport  = AST_SECURITY_EVENT_TRANSPORT_TCP,
+		},
+	};
+
+	char localaddr[53];
+	char remoteaddr[53];
+
+	ast_copy_string(localaddr, "10.1.2.3:4321", sizeof(localaddr));
+	ast_copy_string(remoteaddr, "10.1.2.4:123", sizeof(remoteaddr));
+
+	ast_sockaddr_parse(&addr_local, localaddr, 0);
+	ast_sockaddr_parse(&addr_remote, remoteaddr, 0);
 
 	ast_security_event_report(AST_SEC_EVT(&inval_acct_id));
 }
 
 static void evt_gen_session_limit(void)
 {
-	struct sockaddr_in sin_local = {
-		.sin_family = AF_INET
-	};
-	struct sockaddr_in sin_remote = {
-		.sin_family = AF_INET
-	};
+	struct ast_sockaddr addr_local = { {0,} };
+	struct ast_sockaddr addr_remote = { {0,} };
+
 	struct timeval session_tv = ast_tvnow();
 	struct ast_security_event_session_limit session_limit = {
 		.common.event_type = AST_SECURITY_EVENT_SESSION_LIMIT,
@@ -160,32 +158,32 @@
 		.common.session_id = "8675309",
 		.common.session_tv = &session_tv,
 		.common.local_addr = {
-			.sin  = &sin_local,
+			.addr  = &addr_local,
 			.transport  = AST_SECURITY_EVENT_TRANSPORT_TLS,
 		},
 		.common.remote_addr = {
-			.sin = &sin_remote,
+			.addr = &addr_remote,
 			.transport  = AST_SECURITY_EVENT_TRANSPORT_TLS,
 		},
 	};
 
-	inet_aton("10.5.4.3", &sin_local.sin_addr);
-	sin_local.sin_port = htons(4444);
-
-	inet_aton("10.5.4.2", &sin_remote.sin_addr);
-	sin_remote.sin_port = htons(3333);
+	char localaddr[53];
+	char remoteaddr[53];
+
+	ast_copy_string(localaddr, "10.5.4.3:4444", sizeof(localaddr));
+	ast_copy_string(remoteaddr, "10.5.4.2:3333", sizeof(remoteaddr));
+
+	ast_sockaddr_parse(&addr_local, localaddr, 0);
+	ast_sockaddr_parse(&addr_remote, remoteaddr, 0);
 
 	ast_security_event_report(AST_SEC_EVT(&session_limit));
 }
 
 static void evt_gen_mem_limit(void)
 {
-	struct sockaddr_in sin_local = {
-		.sin_family = AF_INET
-	};
-	struct sockaddr_in sin_remote = {
-		.sin_family = AF_INET
-	};
+	struct ast_sockaddr addr_local = { {0,} };
+	struct ast_sockaddr addr_remote = { {0,} };
+
 	struct timeval session_tv = ast_tvnow();
 	struct ast_security_event_mem_limit mem_limit = {
 		.common.event_type = AST_SECURITY_EVENT_MEM_LIMIT,
@@ -196,32 +194,32 @@
 		.common.session_id = "Session2604",
 		.common.session_tv = &session_tv,
 		.common.local_addr = {
-			.sin  = &sin_local,
-			.transport  = AST_SECURITY_EVENT_TRANSPORT_UDP,
-		},
-		.common.remote_addr = {
-			.sin = &sin_remote,
-			.transport  = AST_SECURITY_EVENT_TRANSPORT_UDP,
-		},
-	};
-
-	inet_aton("10.10.10.10", &sin_local.sin_addr);
-	sin_local.sin_port = htons(555);
-
-	inet_aton("10.10.10.12", &sin_remote.sin_addr);
-	sin_remote.sin_port = htons(5656);
+			.addr  = &addr_local,
+			.transport  = AST_SECURITY_EVENT_TRANSPORT_UDP,
+		},
+		.common.remote_addr = {
+			.addr = &addr_remote,
+			.transport  = AST_SECURITY_EVENT_TRANSPORT_UDP,
+		},
+	};
+
+	char localaddr[53];
+	char remoteaddr[53];
+
+	ast_copy_string(localaddr, "10.10.10.10:555", sizeof(localaddr));
+	ast_copy_string(remoteaddr, "10.10.10.12:5656", sizeof(remoteaddr));
+
+	ast_sockaddr_parse(&addr_local, localaddr, 0);
+	ast_sockaddr_parse(&addr_remote, remoteaddr, 0);
 
 	ast_security_event_report(AST_SEC_EVT(&mem_limit));
 }
 
 static void evt_gen_load_avg(void)
 {
-	struct sockaddr_in sin_local = {
-		.sin_family = AF_INET
-	};
-	struct sockaddr_in sin_remote = {
-		.sin_family = AF_INET
-	};
+	struct ast_sockaddr addr_local = { {0,} };
+	struct ast_sockaddr addr_remote = { {0,} };
+
 	struct timeval session_tv = ast_tvnow();
 	struct ast_security_event_load_avg load_avg = {
 		.common.event_type = AST_SECURITY_EVENT_LOAD_AVG,
@@ -232,32 +230,32 @@
 		.common.session_id = "XYZ123",
 		.common.session_tv = &session_tv,
 		.common.local_addr = {
-			.sin  = &sin_local,
-			.transport  = AST_SECURITY_EVENT_TRANSPORT_UDP,
-		},
-		.common.remote_addr = {
-			.sin = &sin_remote,
-			.transport  = AST_SECURITY_EVENT_TRANSPORT_UDP,
-		},
-	};
-
-	inet_aton("10.11.12.13", &sin_local.sin_addr);
-	sin_local.sin_port = htons(9876);
-
-	inet_aton("10.12.11.10", &sin_remote.sin_addr);
-	sin_remote.sin_port = htons(9825);
+			.addr  = &addr_local,
+			.transport  = AST_SECURITY_EVENT_TRANSPORT_UDP,
+		},
+		.common.remote_addr = {
+			.addr = &addr_remote,
+			.transport  = AST_SECURITY_EVENT_TRANSPORT_UDP,
+		},
+	};
+
+	char localaddr[53];
+	char remoteaddr[53];
+
+	ast_copy_string(localaddr, "10.11.12.13:9876", sizeof(localaddr));
+	ast_copy_string(remoteaddr, "10.12.11.10:9825", sizeof(remoteaddr));
+
+	ast_sockaddr_parse(&addr_local, localaddr, 0);
+	ast_sockaddr_parse(&addr_remote, remoteaddr, 0);
 
 	ast_security_event_report(AST_SEC_EVT(&load_avg));
 }
 
 static void evt_gen_req_no_support(void)
 {
-	struct sockaddr_in sin_local = {
-		.sin_family = AF_INET
-	};
-	struct sockaddr_in sin_remote = {
-		.sin_family = AF_INET
-	};
+	struct ast_sockaddr addr_local = { {0,} };
+	struct ast_sockaddr addr_remote = { {0,} };
+
 	struct timeval session_tv = ast_tvnow();
 	struct ast_security_event_req_no_support req_no_support = {
 		.common.event_type = AST_SECURITY_EVENT_REQ_NO_SUPPORT,
@@ -268,34 +266,34 @@
 		.common.session_id = "asdkl23478289lasdkf",
 		.common.session_tv = &session_tv,
 		.common.local_addr = {
-			.sin  = &sin_local,
-			.transport  = AST_SECURITY_EVENT_TRANSPORT_UDP,
-		},
-		.common.remote_addr = {
-			.sin = &sin_remote,
+			.addr  = &addr_local,
+			.transport  = AST_SECURITY_EVENT_TRANSPORT_UDP,
+		},
+		.common.remote_addr = {
+			.addr = &addr_remote,
 			.transport  = AST_SECURITY_EVENT_TRANSPORT_UDP,
 		},
 
 		.request_type = "MakeMeDinner",
 	};
 
-	inet_aton("10.110.120.130", &sin_local.sin_addr);
-	sin_local.sin_port = htons(9888);
-
-	inet_aton("10.120.110.100", &sin_remote.sin_addr);
-	sin_remote.sin_port = htons(9777);
+	char localaddr[53];
+	char remoteaddr[53];
+
+	ast_copy_string(localaddr, "10.110.120.130:9888", sizeof(localaddr));
+	ast_copy_string(remoteaddr, "10.120.110.100:9777", sizeof(remoteaddr));
+
+	ast_sockaddr_parse(&addr_local, localaddr, 0);
+	ast_sockaddr_parse(&addr_remote, remoteaddr, 0);
 
 	ast_security_event_report(AST_SEC_EVT(&req_no_support));
 }
 
 static void evt_gen_req_not_allowed(void)
 {
-	struct sockaddr_in sin_local = {
-		.sin_family = AF_INET
-	};
-	struct sockaddr_in sin_remote = {
-		.sin_family = AF_INET
-	};
+	struct ast_sockaddr addr_local = { {0,} };
+	struct ast_sockaddr addr_remote = { {0,} };
+
 	struct timeval session_tv = ast_tvnow();
 	struct ast_security_event_req_not_allowed req_not_allowed = {
 		.common.event_type = AST_SECURITY_EVENT_REQ_NOT_ALLOWED,
@@ -306,11 +304,11 @@
 		.common.session_id = "alksdjf023423h4lka0df",
 		.common.session_tv = &session_tv,
 		.common.local_addr = {
-			.sin  = &sin_local,
-			.transport  = AST_SECURITY_EVENT_TRANSPORT_UDP,
-		},
-		.common.remote_addr = {
-			.sin = &sin_remote,
+			.addr  = &addr_local,
+			.transport  = AST_SECURITY_EVENT_TRANSPORT_UDP,
+		},
+		.common.remote_addr = {
+			.addr = &addr_remote,
 			.transport  = AST_SECURITY_EVENT_TRANSPORT_UDP,
 		},
 
@@ -318,23 +316,23 @@
 		.request_params = "BACONNNN!",
 	};
 
-	inet_aton("10.110.120.130", &sin_local.sin_addr);
-	sin_local.sin_port = htons(9888);
-
-	inet_aton("10.120.110.100", &sin_remote.sin_addr);
-	sin_remote.sin_port = htons(9777);
+	char localaddr[53];
+	char remoteaddr[53];
+
+	ast_copy_string(localaddr, "10.110.120.130:9888", sizeof(localaddr));
+	ast_copy_string(remoteaddr, "10.120.110.100:9777", sizeof(remoteaddr));
+
+	ast_sockaddr_parse(&addr_local, localaddr, 0);
+	ast_sockaddr_parse(&addr_remote, remoteaddr, 0);
 
 	ast_security_event_report(AST_SEC_EVT(&req_not_allowed));
 }
 
 static void evt_gen_auth_method_not_allowed(void)
 {
-	struct sockaddr_in sin_local = {
-		.sin_family = AF_INET
-	};
-	struct sockaddr_in sin_remote = {
-		.sin_family = AF_INET
-	};
+	struct ast_sockaddr addr_local = { {0,} };
+	struct ast_sockaddr addr_remote = { {0,} };
+
 	struct timeval session_tv = ast_tvnow();
 	struct ast_security_event_auth_method_not_allowed auth_method_not_allowed = {
 		.common.event_type = AST_SECURITY_EVENT_AUTH_METHOD_NOT_ALLOWED,
@@ -345,34 +343,34 @@
 		.common.session_id = "010101010101",
 		.common.session_tv = &session_tv,
 		.common.local_addr = {
-			.sin  = &sin_local,
-			.transport  = AST_SECURITY_EVENT_TRANSPORT_TCP,
-		},
-		.common.remote_addr = {
-			.sin = &sin_remote,
+			.addr  = &addr_local,
+			.transport  = AST_SECURITY_EVENT_TRANSPORT_TCP,
+		},
+		.common.remote_addr = {
+			.addr = &addr_remote,
 			.transport  = AST_SECURITY_EVENT_TRANSPORT_TCP,
 		},
 
 		.auth_method = "PlainText"
 	};
 
-	inet_aton("10.110.120.135", &sin_local.sin_addr);
-	sin_local.sin_port = htons(8754);
-
-	inet_aton("10.120.110.105", &sin_remote.sin_addr);
-	sin_remote.sin_port = htons(8745);
+	char localaddr[53];
+	char remoteaddr[53];
+
+	ast_copy_string(localaddr, "10.110.120.135:8754", sizeof(localaddr));
+	ast_copy_string(remoteaddr, "10.120.110.105:8745", sizeof(remoteaddr));
+
+	ast_sockaddr_parse(&addr_local, localaddr, 0);
+	ast_sockaddr_parse(&addr_remote, remoteaddr, 0);
 
 	ast_security_event_report(AST_SEC_EVT(&auth_method_not_allowed));
 }
 
 static void evt_gen_req_bad_format(void)
 {
-	struct sockaddr_in sin_local = {
-		.sin_family = AF_INET
-	};
-	struct sockaddr_in sin_remote = {
-		.sin_family = AF_INET
-	};
+	struct ast_sockaddr addr_local = { {0,} };
+	struct ast_sockaddr addr_remote = { {0,} };
+
 	struct timeval session_tv = ast_tvnow();
 	struct ast_security_event_req_bad_format req_bad_format = {
 		.common.event_type = AST_SECURITY_EVENT_REQ_BAD_FORMAT,
@@ -383,11 +381,11 @@
 		.common.session_id = "838383fhfhf83hf8h3f8h",
 		.common.session_tv = &session_tv,
 		.common.local_addr = {
-			.sin  = &sin_local,
-			.transport  = AST_SECURITY_EVENT_TRANSPORT_TCP,
-		},
-		.common.remote_addr = {
-			.sin = &sin_remote,
+			.addr  = &addr_local,
+			.transport  = AST_SECURITY_EVENT_TRANSPORT_TCP,
+		},
+		.common.remote_addr = {
+			.addr = &addr_remote,
 			.transport  = AST_SECURITY_EVENT_TRANSPORT_TCP,
 		},
 
@@ -395,23 +393,23 @@
 		.request_params = "Onions,Swiss,MotorOil",
 	};
 
-	inet_aton("10.110.220.230", &sin_local.sin_addr);
-	sin_local.sin_port = htons(1212);
-
-	inet_aton("10.120.210.200", &sin_remote.sin_addr);
-	sin_remote.sin_port = htons(2121);
+	char localaddr[53];
+	char remoteaddr[53];
+
+	ast_copy_string(localaddr, "10.110.220.230:1212", sizeof(localaddr));
+	ast_copy_string(remoteaddr, "10.120.210.200:2121", sizeof(remoteaddr));
+
+	ast_sockaddr_parse(&addr_local, localaddr, 0);
+	ast_sockaddr_parse(&addr_remote, remoteaddr, 0);
 
 	ast_security_event_report(AST_SEC_EVT(&req_bad_format));
 }
 
 static void evt_gen_successful_auth(void)
 {
-	struct sockaddr_in sin_local = {
-		.sin_family = AF_INET
-	};
-	struct sockaddr_in sin_remote = {
-		.sin_family = AF_INET
-	};
+	struct ast_sockaddr addr_local = { {0,} };
+	struct ast_sockaddr addr_remote = { {0,} };
+
 	struct timeval session_tv = ast_tvnow();
 	struct ast_security_event_successful_auth successful_auth = {
 		.common.event_type = AST_SECURITY_EVENT_SUCCESSFUL_AUTH,
@@ -422,35 +420,33 @@
 		.common.session_id = "Session456",
 		.common.session_tv = &session_tv,
 		.common.local_addr = {
-			.sin  = &sin_local,
-			.transport  = AST_SECURITY_EVENT_TRANSPORT_TCP,
-		},
-		.common.remote_addr = {
-			.sin = &sin_remote,
-			.transport  = AST_SECURITY_EVENT_TRANSPORT_TCP,
-		},
-	};
-
-	inet_aton("10.1.2.3", &sin_local.sin_addr);
-	sin_local.sin_port = htons(4321);
-
-	inet_aton("10.1.2.4", &sin_remote.sin_addr);
-	sin_remote.sin_port = htons(1234);
+			.addr  = &addr_local,
+			.transport  = AST_SECURITY_EVENT_TRANSPORT_TCP,
+		},
+		.common.remote_addr = {
+			.addr = &addr_remote,
+			.transport  = AST_SECURITY_EVENT_TRANSPORT_TCP,
+		},
+	};
+
+	char localaddr[53];
+	char remoteaddr[53];
+
+	ast_copy_string(localaddr, "10.1.2.3:4321", sizeof(localaddr));
+	ast_copy_string(remoteaddr, "10.1.2.4:1234", sizeof(remoteaddr));
+
+	ast_sockaddr_parse(&addr_local, localaddr, 0);
+	ast_sockaddr_parse(&addr_remote, remoteaddr, 0);
 
 	ast_security_event_report(AST_SEC_EVT(&successful_auth));
 }
 
 static void evt_gen_unexpected_addr(void)
 {
-	struct sockaddr_in sin_local = {
-		.sin_family = AF_INET
-	};
-	struct sockaddr_in sin_remote = {
-		.sin_family = AF_INET
-	};
-	struct sockaddr_in sin_expected = {
-		.sin_family = AF_INET
-	};
+	struct ast_sockaddr addr_local = { {0,} };
+	struct ast_sockaddr addr_remote = { {0,} };
+	struct ast_sockaddr addr_expected = { {0,} };
+
 	struct timeval session_tv = ast_tvnow();
 	struct ast_security_event_unexpected_addr unexpected_addr = {
 		.common.event_type = AST_SECURITY_EVENT_UNEXPECTED_ADDR,
@@ -461,40 +457,40 @@
 		.common.session_id = "Session789",
 		.common.session_tv = &session_tv,
 		.common.local_addr = {
-			.sin  = &sin_local,
-			.transport  = AST_SECURITY_EVENT_TRANSPORT_UDP,
-		},
-		.common.remote_addr = {
-			.sin = &sin_remote,
+			.addr  = &addr_local,
+			.transport  = AST_SECURITY_EVENT_TRANSPORT_UDP,
+		},
+		.common.remote_addr = {
+			.addr = &addr_remote,
 			.transport  = AST_SECURITY_EVENT_TRANSPORT_UDP,
 		},
 
 		.expected_addr = {
-			.sin = &sin_expected,
-			.transport  = AST_SECURITY_EVENT_TRANSPORT_UDP,
-		},
-	};
-
-	inet_aton("10.1.2.3", &sin_local.sin_addr);
-	sin_local.sin_port = htons(4321);
-
-	inet_aton("10.1.2.4", &sin_remote.sin_addr);
-	sin_remote.sin_port = htons(1234);
-
-	inet_aton("10.1.2.5", &sin_expected.sin_addr);
-	sin_expected.sin_port = htons(2343);
+			.addr = &addr_expected,
+			.transport  = AST_SECURITY_EVENT_TRANSPORT_UDP,
+		},
+	};
+
+	char localaddr[53];
+	char remoteaddr[53];
+	char expectedaddr[53];
+
+	ast_copy_string(localaddr, "10.1.2.3:4321", sizeof(localaddr));
+	ast_copy_string(remoteaddr, "10.1.2.4:1234", sizeof(remoteaddr));
+	ast_copy_string(expectedaddr, "10.1.2.5:2343", sizeof(expectedaddr));
+
+	ast_sockaddr_parse(&addr_local, localaddr, 0);
+	ast_sockaddr_parse(&addr_remote, remoteaddr, 0);
+	ast_sockaddr_parse(&addr_expected, expectedaddr, 0);
 
 	ast_security_event_report(AST_SEC_EVT(&unexpected_addr));
 }
 
 static void evt_gen_chal_resp_failed(void)
 {
-	struct sockaddr_in sin_local = {
-		.sin_family = AF_INET
-	};
-	struct sockaddr_in sin_remote = {
-		.sin_family = AF_INET
-	};
+	struct ast_sockaddr addr_local = { {0,} };
+	struct ast_sockaddr addr_remote = { {0,} };
+
 	struct timeval session_tv = ast_tvnow();
 	struct ast_security_event_chal_resp_failed chal_resp_failed = {
 		.common.event_type = AST_SECURITY_EVENT_CHAL_RESP_FAILED,
@@ -505,11 +501,11 @@
 		.common.session_id = "Session1231231231",
 		.common.session_tv = &session_tv,
 		.common.local_addr = {
-			.sin  = &sin_local,
-			.transport  = AST_SECURITY_EVENT_TRANSPORT_TCP,
-		},
-		.common.remote_addr = {
-			.sin = &sin_remote,
+			.addr  = &addr_local,
+			.transport  = AST_SECURITY_EVENT_TRANSPORT_TCP,
+		},
+		.common.remote_addr = {
+			.addr = &addr_remote,
 			.transport  = AST_SECURITY_EVENT_TRANSPORT_TCP,
 		},
 
@@ -518,23 +514,23 @@
 		.expected_response = "oiafaljhadf9834luahk3k",
 	};
 
-	inet_aton("10.1.2.3", &sin_local.sin_addr);
-	sin_local.sin_port = htons(4321);
-
-	inet_aton("10.1.2.4", &sin_remote.sin_addr);
-	sin_remote.sin_port = htons(1234);
+	char localaddr[53];
+	char remoteaddr[53];
+
+	ast_copy_string(localaddr, "10.1.2.3:4321", sizeof(localaddr));
+	ast_copy_string(remoteaddr, "10.1.2.4:1234", sizeof(remoteaddr));
+
+	ast_sockaddr_parse(&addr_local, localaddr, 0);
+	ast_sockaddr_parse(&addr_remote, remoteaddr, 0);
 
 	ast_security_event_report(AST_SEC_EVT(&chal_resp_failed));
 }
 
 static void evt_gen_inval_password(void)
 {
-	struct sockaddr_in sin_local = {
-		.sin_family = AF_INET
-	};
-	struct sockaddr_in sin_remote = {
-		.sin_family = AF_INET
-	};
+	struct ast_sockaddr addr_local = { {0,} };
+	struct ast_sockaddr addr_remote = { {0,} };
+
 	struct timeval session_tv = ast_tvnow();
 	struct ast_security_event_inval_password inval_password = {
 		.common.event_type = AST_SECURITY_EVENT_INVAL_PASSWORD,
@@ -545,20 +541,23 @@
 		.common.session_id = "SessionIDGoesHere",
 		.common.session_tv = &session_tv,
 		.common.local_addr = {
-			.sin  = &sin_local,
-			.transport  = AST_SECURITY_EVENT_TRANSPORT_TCP,
-		},
-		.common.remote_addr = {
-			.sin = &sin_remote,
-			.transport  = AST_SECURITY_EVENT_TRANSPORT_TCP,
-		},
-	};
-
-	inet_aton("10.200.100.30", &sin_local.sin_addr);
-	sin_local.sin_port = htons(4321);
-
-	inet_aton("10.200.100.40", &sin_remote.sin_addr);
-	sin_remote.sin_port = htons(1234);
+			.addr  = &addr_local,
+			.transport  = AST_SECURITY_EVENT_TRANSPORT_TCP,
+		},
+		.common.remote_addr = {
+			.addr = &addr_remote,
+			.transport  = AST_SECURITY_EVENT_TRANSPORT_TCP,
+		},
+	};
+
+	char localaddr[53];
+	char remoteaddr[53];
+
+	ast_copy_string(localaddr, "10.200.100.30:4321", sizeof(localaddr));
+	ast_copy_string(remoteaddr, "10.200.100.40:1234", sizeof(remoteaddr));
+
+	ast_sockaddr_parse(&addr_local, localaddr, 0);
+	ast_sockaddr_parse(&addr_remote, remoteaddr, 0);
 
 	ast_security_event_report(AST_SEC_EVT(&inval_password));
 }




More information about the asterisk-commits mailing list