+
+done:
+ if (error) {
+ soisdisconnected(so);
+ lck_mtx_lock(ctl_mtx);
+ TAILQ_REMOVE(&kctl->kcb_head, kcb, next);
+ kcb->kctl = NULL;
+ kcb->sac.sc_unit = 0;
+ kctlstat.kcs_pcbcount--;
+ kctlstat.kcs_gencnt++;
+ kctlstat.kcs_conn_fail++;
+ lck_mtx_unlock(ctl_mtx);
+ }
+ return (error);
+}
+
+static int
+ctl_bind(struct socket *so, struct sockaddr *nam, struct proc *p)
+{
+ int error = 0;
+ struct ctl_cb *kcb = (struct ctl_cb *)so->so_pcb;
+
+ if (kcb == NULL) {
+ panic("ctl_bind so_pcb null\n");
+ }
+
+ error = ctl_setup_kctl(so, nam, p);
+ if (error) {
+ return (error);
+ }
+
+ if (kcb->kctl == NULL) {
+ panic("ctl_bind kctl null\n");
+ }
+
+ if (kcb->kctl->bind == NULL) {
+ return (EINVAL);
+ }