Make a rawrtc example actually build

We were missing a lot of things that the linker caught when building an
example.

Change-Id: Ic3ea2a1dd0bfa88569023b47b603ec25f337f54c
diff --git a/third_party/rawrtc/usrsctp/BUILD b/third_party/rawrtc/usrsctp/BUILD
index 7704bb9..654d29b 100644
--- a/third_party/rawrtc/usrsctp/BUILD
+++ b/third_party/rawrtc/usrsctp/BUILD
@@ -1,21 +1,63 @@
-# usrsctp is only actually being used for the CRC function, and getting
-# the entire library building was being obnoxious.
+load("@//tools/build_rules:select.bzl", "compiler_select")
+
 cc_library(
-    name = "usrsctp_crc32",
-    srcs = ["usrsctplib/netinet/sctp_crc32.c"],
+    name = "usrsctp",
+    srcs = [
+        "usrsctplib/netinet/sctp_asconf.c",
+        "usrsctplib/netinet/sctp_auth.c",
+        "usrsctplib/netinet/sctp_bsd_addr.c",
+        "usrsctplib/netinet/sctp_callout.c",
+        "usrsctplib/netinet/sctp_cc_functions.c",
+        "usrsctplib/netinet/sctp_crc32.c",
+        "usrsctplib/netinet/sctp_indata.c",
+        "usrsctplib/netinet/sctp_input.c",
+        "usrsctplib/netinet/sctp_output.c",
+        "usrsctplib/netinet/sctp_pcb.c",
+        "usrsctplib/netinet/sctp_peeloff.c",
+        "usrsctplib/netinet/sctp_sha1.c",
+        "usrsctplib/netinet/sctp_ss_functions.c",
+        "usrsctplib/netinet/sctp_sysctl.c",
+        "usrsctplib/netinet/sctp_timer.c",
+        "usrsctplib/netinet/sctp_userspace.c",
+        "usrsctplib/netinet/sctp_usrreq.c",
+        "usrsctplib/netinet/sctputil.c",
+        "usrsctplib/netinet6/sctp6_usrreq.c",
+        "usrsctplib/user_environment.c",
+        "usrsctplib/user_mbuf.c",
+        "usrsctplib/user_recv_thread.c",
+        "usrsctplib/user_socket.c",
+    ],
     hdrs = glob(["usrsctplib/**/*.h"]),
     copts = [
         "-Wno-cast-qual",
         "-Wno-cast-align",
         "-Wno-unused-parameter",
         "-Wno-incompatible-pointer-types-discards-qualifiers",
+        "-D__Userspace_os_Linux",
+        "-D__Userspace__",
+        "-D_GNU_SOURCE",
+        "-DSCTP_DEBUG",
+        "-DSCTP_SIMPLE_ALLOCATOR",
+        "-DINET",
+        "-DINET6",
+        "-DSCTP_PROCESS_LEVEL_LOCKS",
+        "-DHAVE_SYS_QUEUE_H",
+        "-DHAVE_STDATOMIC_H",
+        "-DHAVE_NETINET_IP_ICMP_H",
+        "-DHAVE_LINUX_RTNETLINK_H",
+        "-DHAVE_LINUX_IF_ADDR_H",
+        "-Wno-address-of-packed-member",
+    ] + compiler_select({
+        "clang": [],
+        "gcc": [
+            "-Wno-discarded-qualifiers",
+        ],
+    }),
+    includes = [
+        "usrsctplib/",
+        "usrsctplib/netinet",
+        "usrsctplib/netinet6",
     ],
-    defines = [
-        "__Userspace_os_Linux",
-        "__Userspace__",
-        "SCTP_SIMPLE_ALLOCATOR",
-    ],
-    includes = ["usrsctplib/"],
     target_compatible_with = ["@platforms//os:linux"],
     visibility = ["//visibility:public"],
 )
diff --git a/third_party/rawrtc/usrsctp/usrsctplib/netinet/sctp_constants.h b/third_party/rawrtc/usrsctp/usrsctplib/netinet/sctp_constants.h
index e275dd9..57240cd 100755
--- a/third_party/rawrtc/usrsctp/usrsctplib/netinet/sctp_constants.h
+++ b/third_party/rawrtc/usrsctp/usrsctplib/netinet/sctp_constants.h
@@ -778,7 +778,7 @@
 #define SCTP_DEFAULT_SPLIT_POINT_MIN 2904
 
 /* Maximum length of diagnostic information in error causes */
-#define SCTP_DIAG_INFO_LEN 64
+#define SCTP_DIAG_INFO_LEN 128
 
 /* ABORT CODES and other tell-tale location
  * codes are generated by adding the below
diff --git a/third_party/rawrtc/usrsctp/usrsctplib/netinet/sctp_pcb.c b/third_party/rawrtc/usrsctp/usrsctplib/netinet/sctp_pcb.c
index ec3ff6d..ca84395 100755
--- a/third_party/rawrtc/usrsctp/usrsctplib/netinet/sctp_pcb.c
+++ b/third_party/rawrtc/usrsctp/usrsctplib/netinet/sctp_pcb.c
@@ -6845,7 +6845,7 @@
 	TAILQ_INIT(&SCTP_BASE_INFO(callqueue));
 #endif
 #if defined(__Userspace__)
-	mbuf_init(NULL);
+	usrsctpmbuf_init(NULL);
 	atomic_init();
 #if defined(THREAD_SUPPORT) && (defined(INET) || defined(INET6))
 	recv_thread_init();
diff --git a/third_party/rawrtc/usrsctp/usrsctplib/netinet/sctputil.c b/third_party/rawrtc/usrsctp/usrsctplib/netinet/sctputil.c
index 87e7774..5ac93d5 100755
--- a/third_party/rawrtc/usrsctp/usrsctplib/netinet/sctputil.c
+++ b/third_party/rawrtc/usrsctp/usrsctplib/netinet/sctputil.c
@@ -5013,7 +5013,7 @@
  */
 
 struct mbuf *
-sctp_generate_cause(uint16_t code, char *info)
+sctp_generate_cause(uint16_t code, const char *info)
 {
 	struct mbuf *m;
 	struct sctp_gen_error_cause *cause;
diff --git a/third_party/rawrtc/usrsctp/usrsctplib/netinet/sctputil.h b/third_party/rawrtc/usrsctp/usrsctplib/netinet/sctputil.h
index 7746d54..1babe19 100755
--- a/third_party/rawrtc/usrsctp/usrsctplib/netinet/sctputil.h
+++ b/third_party/rawrtc/usrsctp/usrsctplib/netinet/sctputil.h
@@ -281,7 +281,7 @@
 #endif
 );
 
-struct mbuf *sctp_generate_cause(uint16_t, char *);
+struct mbuf *sctp_generate_cause(uint16_t, const char *);
 struct mbuf *sctp_generate_no_user_data_cause(uint32_t);
 
 void sctp_bindx_add_address(struct socket *so, struct sctp_inpcb *inp,
diff --git a/third_party/rawrtc/usrsctp/usrsctplib/user_mbuf.c b/third_party/rawrtc/usrsctp/usrsctplib/user_mbuf.c
index 9a82746..232d74e 100755
--- a/third_party/rawrtc/usrsctp/usrsctplib/user_mbuf.c
+++ b/third_party/rawrtc/usrsctp/usrsctplib/user_mbuf.c
@@ -121,7 +121,7 @@
 	mbuf_mb_args.type = type;
 #endif
 	/* Mbuf master zone, zone_mbuf, has already been
-	 * created in mbuf_init() */
+	 * created in usrsctpmbuf_init() */
 	mret = SCTP_ZONE_GET(zone_mbuf, struct mbuf);
 #if defined(SCTP_SIMPLE_ALLOCATOR)
 	mb_ctor_mbuf(mret, &mbuf_mb_args, 0);
@@ -328,11 +328,11 @@
 /************ End functions to substitute umem_cache_alloc and umem_cache_free **************/
 
 /* __Userspace__
- * TODO: mbuf_init must be called in the initialization routines
+ * TODO: usrsctpmbuf_init must be called in the initialization routines
  * of userspace stack.
  */
 void
-mbuf_init(void *dummy)
+usrsctpmbuf_init(void *dummy)
 {
 
 	/*
diff --git a/third_party/rawrtc/usrsctp/usrsctplib/user_mbuf.h b/third_party/rawrtc/usrsctp/usrsctplib/user_mbuf.h
index 7893ea9..64a0ac3 100755
--- a/third_party/rawrtc/usrsctp/usrsctplib/user_mbuf.h
+++ b/third_party/rawrtc/usrsctp/usrsctplib/user_mbuf.h
@@ -58,7 +58,7 @@
 
 
 /* mbuf initialization function */
-void mbuf_init(void *);
+void usrsctpmbuf_init(void *);
 
 #define	M_MOVE_PKTHDR(to, from)	m_move_pkthdr((to), (from))
 #define	MGET(m, how, type)	((m) = m_get((how), (type)))