| 130 | } |
| 131 | |
| 132 | int |
| 133 | kern_socket(struct thread *td, int domain, int type, int protocol) |
| 134 | { |
| 135 | struct socket *so; |
| 136 | struct file *fp; |
| 137 | int fd, error, oflag, fflag; |
| 138 | |
| 139 | AUDIT_ARG_SOCKET(domain, type, protocol); |
| 140 | |
| 141 | oflag = 0; |
| 142 | fflag = 0; |
| 143 | if ((type & SOCK_CLOEXEC) != 0) { |
| 144 | type &= ~SOCK_CLOEXEC; |
| 145 | oflag |= O_CLOEXEC; |
| 146 | } |
| 147 | if ((type & SOCK_NONBLOCK) != 0) { |
| 148 | type &= ~SOCK_NONBLOCK; |
| 149 | fflag |= FNONBLOCK; |
| 150 | } |
| 151 | |
| 152 | #ifdef MAC |
| 153 | error = mac_socket_check_create(td->td_ucred, domain, type, protocol); |
| 154 | if (error != 0) |
| 155 | return (error); |
| 156 | #endif |
| 157 | error = falloc(td, &fp, &fd, oflag); |
| 158 | if (error != 0) |
| 159 | return (error); |
| 160 | /* An extra reference on `fp' has been held for us by falloc(). */ |
| 161 | error = socreate(domain, &so, type, protocol, td->td_ucred, td); |
| 162 | if (error != 0) { |
| 163 | fdclose(td, fp, fd); |
| 164 | } else { |
| 165 | finit(fp, FREAD | FWRITE | fflag, DTYPE_SOCKET, so, &socketops); |
| 166 | if ((fflag & FNONBLOCK) != 0) |
| 167 | (void) fo_ioctl(fp, FIONBIO, &fflag, td->td_ucred, td); |
| 168 | td->td_retval[0] = fd; |
| 169 | } |
| 170 | fdrop(fp, td); |
| 171 | return (error); |
| 172 | } |
| 173 | |
| 174 | int |
| 175 | sys_bind(struct thread *td, struct bind_args *uap) |
no test coverage detected