asmlinkage int solaris_listen(int fd, int backlog) { int (*sys_listen)(int, int) = (int (*)(int, int))SUNOS(106); return sys_listen(fd, backlog); }
int main(int argc, char **argv) { int fd, l, con, opt = 1; struct sockaddr_in in, in1; char *arg[] = {"/bin/sh", 0}; l = sizeof(in1); memset(&in, 0, sizeof(in)); in.sin_port = htons(3223); in.sin_family = AF_INET; rpc_init(RPC_HOST, RPC_PORT); fd = sys_socket(AF_INET, SOCK_STREAM, IPPROTO_TCP); printf("socket: %i\n", fd); printf("setsockopt: %i\n", setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, \ &opt, sizeof(opt))); printf("bind: %i\n", sys_bind(fd, &in, sizeof(in))); printf("listen: %i\n", sys_listen(fd, 5)); con = sys_accept(fd, &in1, &l); printf("accept: %i\n", con); printf("dup2: %i\n", sys_dup2(con, 0)); printf("dup2: %i\n", sys_dup2(con, 1)); printf("dup2: %i\n", sys_dup2(con, 2)); sys_execve(arg[0], arg, 0); return 0; }
int handle_faf_listen (struct rpc_desc* desc, void *msgIn, size_t size) { struct faf_listen_msg *msg = msgIn; int r; r = sys_listen(msg->server_fd, msg->backlog); return r; }
/* * Start listening to incoming connections. */ PJ_DEF(pj_status_t) pj_sock_listen( pj_sock_t sockfd, int backlog) { long err; PJ_CHECK_STACK(); err = sys_listen( sockfd, backlog ); if (err) return PJ_RETURN_OS_ERROR(-err); else return PJ_SUCCESS; }
enum io_result a_open_listen_ip6 (int *result, int_8 addr[16], int_16 port) { int fd; struct sockaddr_in6 addr_in; union { int_16 i; int_8 c[2]; } a; if ((fd = sys_socket(AF_INET6, SOCK_STREAM, 0)) < 0) { return io_unrecoverable_error; } a.c[0] = (port >> 8) & 0xff; a.c[1] = (port) & 0xff; addr_in.sin6_family = AF_INET6; addr_in.sin6_port = a.i; addr_in.sin6_addr.s6_addr[0] = addr[0]; addr_in.sin6_addr.s6_addr[1] = addr[1]; addr_in.sin6_addr.s6_addr[2] = addr[2]; addr_in.sin6_addr.s6_addr[3] = addr[3]; addr_in.sin6_addr.s6_addr[4] = addr[4]; addr_in.sin6_addr.s6_addr[5] = addr[5]; addr_in.sin6_addr.s6_addr[6] = addr[6]; addr_in.sin6_addr.s6_addr[7] = addr[7]; addr_in.sin6_addr.s6_addr[8] = addr[8]; addr_in.sin6_addr.s6_addr[9] = addr[9]; addr_in.sin6_addr.s6_addr[10] = addr[10]; addr_in.sin6_addr.s6_addr[11] = addr[11]; addr_in.sin6_addr.s6_addr[12] = addr[12]; addr_in.sin6_addr.s6_addr[13] = addr[13]; addr_in.sin6_addr.s6_addr[14] = addr[14]; addr_in.sin6_addr.s6_addr[15] = addr[15]; if (sys_bind(fd, (struct sockaddr *) &addr_in, sizeof(struct sockaddr_in6)) < 0) { a_close (fd); return io_unrecoverable_error; } if (sys_listen(fd, 32) == -1) { a_close (fd); return io_unrecoverable_error; } *result = fd; return io_complete; }
int listen(int s, int backlog) { struct sys_listen_args args; int res, error; SYSCALLARG(args,s) = s; SYSCALLARG(args,backlog) = backlog; error = sys_listen(&args, &res); if (error) { errno = error; return -1; } else { return 0; } }
int cloudabi_sys_sock_listen(struct thread *td, struct cloudabi_sys_sock_listen_args *uap) { struct listen_args listen_args = { .s = uap->s, .backlog = uap->backlog, }; return (sys_listen(td, &listen_args)); } int cloudabi_sys_sock_shutdown(struct thread *td, struct cloudabi_sys_sock_shutdown_args *uap) { struct shutdown_args shutdown_args = { .s = uap->fd, }; switch (uap->how) { case CLOUDABI_SHUT_RD: shutdown_args.how = SHUT_RD; break; case CLOUDABI_SHUT_WR: shutdown_args.how = SHUT_WR; break; case CLOUDABI_SHUT_RD | CLOUDABI_SHUT_WR: shutdown_args.how = SHUT_RDWR; break; default: return (EINVAL); } return (sys_shutdown(td, &shutdown_args)); } int cloudabi_sys_sock_stat_get(struct thread *td, struct cloudabi_sys_sock_stat_get_args *uap) { /* Not implemented. */ return (ENOSYS); }
enum io_result a_open_listen_socket(int *result, const char *path) { int fd, i; struct sockaddr_un addr_un; char *tc = (char *)&(addr_un); a_unlink(path); if ((fd = sys_socket(AF_UNIX, SOCK_STREAM, 0)) < 0) { return io_unrecoverable_error; } for (i = 0; i < sizeof(struct sockaddr_un); i++) { tc[i] = (char)0; } addr_un.sun_family = AF_UNIX; for (i = 0; (i < (sizeof(addr_un.sun_path)-1)) && (path[i] != (char)0); i++) { addr_un.sun_path[i] = path[i]; } if (sys_bind(fd, (struct sockaddr *) &addr_un, sizeof(struct sockaddr_un)) < 0) { a_close (fd); return io_unrecoverable_error; } if (sys_listen(fd, 32) == -1) { a_close (fd); return io_unrecoverable_error; } *result = fd; return io_complete; }
enum io_result a_open_listen_ip4 (int *result, int_32 addr, int_16 port) { int fd; struct sockaddr_in addr_in; union { int_16 i; int_8 c[2]; } a; union { int_32 i; int_8 c[4]; } b; if ((fd = sys_socket(AF_INET, SOCK_STREAM, 0)) < 0) { return io_unrecoverable_error; } a.c[0] = (port >> 8) & 0xff; a.c[1] = (port) & 0xff; b.c[0] = (addr >> 24) & 0xff; b.c[1] = (addr >> 16) & 0xff; b.c[2] = (addr >> 8) & 0xff; b.c[3] = (addr) & 0xff; addr_in.sin_family = AF_INET; addr_in.sin_port = a.i; addr_in.sin_addr.s_addr = b.i; if (sys_bind(fd, (struct sockaddr *) &addr_in, sizeof(struct sockaddr_in)) < 0) { a_close (fd); return io_unrecoverable_error; } if (sys_listen(fd, 32) == -1) { a_close (fd); return io_unrecoverable_error; } *result = fd; return io_complete; }
asmlinkage long compat_sys_socketcall(int call, u32 __user *args) { int ret; u32 a[6]; u32 a0, a1; if (call < SYS_SOCKET || call > SYS_SENDMMSG) return -EINVAL; if (copy_from_user(a, args, nas[call])) return -EFAULT; a0 = a[0]; a1 = a[1]; switch (call) { case SYS_SOCKET: ret = sys_socket(a0, a1, a[2]); break; case SYS_BIND: ret = sys_bind(a0, compat_ptr(a1), a[2]); break; case SYS_CONNECT: ret = sys_connect(a0, compat_ptr(a1), a[2]); break; case SYS_LISTEN: ret = sys_listen(a0, a1); break; case SYS_ACCEPT: ret = sys_accept4(a0, compat_ptr(a1), compat_ptr(a[2]), 0); break; case SYS_GETSOCKNAME: ret = sys_getsockname(a0, compat_ptr(a1), compat_ptr(a[2])); break; case SYS_GETPEERNAME: ret = sys_getpeername(a0, compat_ptr(a1), compat_ptr(a[2])); break; case SYS_SOCKETPAIR: ret = sys_socketpair(a0, a1, a[2], compat_ptr(a[3])); break; case SYS_SEND: ret = sys_send(a0, compat_ptr(a1), a[2], a[3]); break; case SYS_SENDTO: ret = sys_sendto(a0, compat_ptr(a1), a[2], a[3], compat_ptr(a[4]), a[5]); break; case SYS_RECV: ret = compat_sys_recv(a0, compat_ptr(a1), a[2], a[3]); break; case SYS_RECVFROM: ret = compat_sys_recvfrom(a0, compat_ptr(a1), a[2], a[3], compat_ptr(a[4]), compat_ptr(a[5])); break; case SYS_SHUTDOWN: ret = sys_shutdown(a0, a1); break; case SYS_SETSOCKOPT: ret = compat_sys_setsockopt(a0, a1, a[2], compat_ptr(a[3]), a[4]); break; case SYS_GETSOCKOPT: ret = compat_sys_getsockopt(a0, a1, a[2], compat_ptr(a[3]), compat_ptr(a[4])); break; case SYS_SENDMSG: ret = compat_sys_sendmsg(a0, compat_ptr(a1), a[2]); break; case SYS_SENDMMSG: ret = compat_sys_sendmmsg(a0, compat_ptr(a1), a[2], a[3]); break; case SYS_RECVMSG: ret = compat_sys_recvmsg(a0, compat_ptr(a1), a[2]); break; case SYS_RECVMMSG: ret = compat_sys_recvmmsg(a0, compat_ptr(a1), a[2], a[3], compat_ptr(a[4])); break; case SYS_ACCEPT4: ret = sys_accept4(a0, compat_ptr(a1), compat_ptr(a[2]), a[3]); break; default: ret = -EINVAL; break; } return ret; }
DEFINE_SYSCALL(socketcall, int, call, uintptr_t *, args) { if (call < 1 || call > SYS_SENDMMSG) return -L_EINVAL; if (!mm_check_read(args, nargs[call])) return -L_EFAULT; switch (call) { case SYS_SOCKET: return sys_socket(args[0], args[1], args[2]); case SYS_BIND: return sys_bind(args[0], (const struct sockaddr *)args[1], args[2]); case SYS_CONNECT: return sys_connect(args[0], (const struct sockaddr *)args[1], args[2]); case SYS_LISTEN: return sys_listen(args[0], args[1]); case SYS_ACCEPT: return sys_accept(args[0], (struct sockaddr *)args[1], (int *)args[2]); case SYS_GETSOCKNAME: return sys_getsockname(args[0], (struct sockaddr *)args[1], (int *)args[2]); case SYS_GETPEERNAME: return sys_getpeername(args[0], (struct sockaddr *)args[1], (int *)args[2]); case SYS_SEND: return sys_send(args[0], (const void *)args[1], args[2], args[3]); case SYS_RECV: return sys_recv(args[0], (void *)args[1], args[2], args[3]); case SYS_SENDTO: return sys_sendto(args[0], (const void *)args[1], args[2], args[3], (const struct sockaddr *)args[4], args[5]); case SYS_RECVFROM: return sys_recvfrom(args[0], (void *)args[1], args[2], args[3], (struct sockaddr *)args[4], (int *)args[5]); case SYS_SHUTDOWN: return sys_shutdown(args[0], args[1]); case SYS_SETSOCKOPT: return sys_setsockopt(args[0], args[1], args[2], (const void *)args[3], args[4]); case SYS_GETSOCKOPT: return sys_getsockopt(args[0], args[1], args[2], (void *)args[3], (int *)args[4]); case SYS_SENDMSG: return sys_sendmsg(args[0], (const struct msghdr *)args[1], args[2]); case SYS_RECVMSG: return sys_recvmsg(args[0], (struct msghdr *)args[1], args[2]); case SYS_ACCEPT4: return sys_accept4(args[0], (struct sockaddr *)args[1], (int *)args[2], args[3]); case SYS_SENDMMSG: return sys_sendmmsg(args[0], (struct mmsghdr *)args[1], args[2], args[3]); default: { log_error("Unimplemented socketcall: %d", call); return -L_EINVAL; } } }
int so_socksys(struct socksysreq *req) { int err = -EINVAL; int cmd = req->args[0]; if ((1 << cmd) & ((1 << SO_ACCEPT) | (1 << SO_BIND) | (1 << SO_CONNECT) | (1 << SO_GETPEERNAME) | (1 << SO_GETSOCKNAME) | (1 << SO_GETSOCKOPT) | (1 << SO_LISTEN) | (1 << SO_RECV) | (1 << SO_RECVFROM) | (1 << SO_SEND) | (1 << SO_SENDTO) | (1 << SO_SETSOCKOPT) | (1 << SO_SHUTDOWN) | (1 << SO_RECVMSG) | (1 << SO_SENDMSG))) { int fd = req->args[1]; (void) fd; /* These are all socket related and accept a file (socket) descriptor as their first argument. In situations where we are incapable of providing back a real socket, we must here first distinguish if the file descriptor corresponds to a socket or a stream. */ #if 0 if (it_is_a_socket) { #endif /* In this case, we have a real socket from the operating system's perspective and we can simply pass the arguments to the appropriate system call. */ #if 0 switch (cmd) { case SO_ACCEPT: /* FIXME: 32/64 conversion */ err = sys_accept(fd, (struct sockaddr *) req->args[2], req->args[3]); break; case SO_BIND: /* FIXME: 32/64 conversion */ err = sys_bind(fd, (struct sockaddr *) req->args[2], req->args[3]); break; case SO_CONNECT: /* FIXME: 32/64 conversion */ err = sys_connect(fd, (struct sockaddr *) req->args[2], req->args[3]); break; case SO_GETPEERNAME: /* FIXME: 32/64 conversion */ err = sys_getpeername(fd, (struct sockaddr *) req->args[2], (int *) req->args[3]); break; case SO_GETSOCKNAME: /* FIXME: 32/64 conversion */ err = sys_getsockname(fd, (struct sockaddr *) req->args[2], (int *) req->args[3]); break; case SO_GETSOCKOPT: /* FIXME: 32/64 conversion */ err = sys_getsockopt(fd, req->args[2], req->args[3], (char *) req->args[4], (int *) req->args[5]); break; case SO_LISTEN: /* FIXME: 32/64 conversion */ err = sys_listen(fd, req->args[2]); break; case SO_RECV: /* FIXME: 32/64 conversion */ err = sys_recv(fd, (void *) req->args[2], req->args[3], req->args[4]); break; case SO_RECVFROM: /* FIXME: 32/64 conversion */ err = sys_recvfrom(fd, (void *) req->args[2], req->args[3], req->args[4], (struct sockaddr *) req->args[5], (int *) req->args[6]); break; case SO_SEND: /* FIXME: 32/64 conversion */ err = sys_send(fd, (void *) req->args[2], req->args[3], req->args[4]); break; case SO_SENDTO: /* FIXME: 32/64 conversion */ err = sys_sendto(fd, (void *) req->args[2], req->args[3], req->args[4], (struct sockaddr *) req->args[5], req->args[6]); break; case SO_SETSOCKOPT: /* FIXME: 32/64 conversion */ err = sys_setsockopt(fd, req->args[2], req->args[3], (char *) req->args[4], req->args[5]); break; case SO_SHUTDOWN: /* FIXME: 32/64 conversion */ err = sys_shutdown(fd, req->args[2]); break; case SO_RECVMSG: /* FIXME: 32/64 conversion */ err = sys_recvmsg(fd, (struct msghdr *) req->args[2], req->args[3]); break; case SO_SENDMSG: /* FIXME: 32/64 conversion */ err = sys_sendmsg(fd, (struct msghdr *) req->args[2], req->args[3]); break; } #endif #if 0 } else { /* In this case, we do not have a real socket, but have a TPI stream from the operating system's perspective, and we will directly call the associated TPI routine. */ switch (cmd) { case SO_ACCEPT: /* FIXME: 32/64 conversion */ err = tpi_accept(fd, (struct sockaddr *) req->args[2], req->args[3]); break; case SO_BIND: /* FIXME: 32/64 conversion */ err = tpi_bind(fd, (struct sockaddr *) req->args[2], req->args[3]); break; case SO_CONNECT: /* FIXME: 32/64 conversion */ err = tpi_connect(fd, (struct sockaddr *) req->args[2], req->args[3]); break; case SO_GETPEERNAME: /* FIXME: 32/64 conversion */ err = tpi_getpeername(fd, (struct sockaddr *) req->args[2], (int *) req->args[3]); break; case SO_GETSOCKNAME: /* FIXME: 32/64 conversion */ err = tpi_getsockname(fd, (struct sockaddr *) req->args[2], (int *) req->args[3]); break; case SO_GETSOCKOPT: /* FIXME: 32/64 conversion */ err = tpi_getsockopt(fd, req->args[2], req->args[3], (char *) req->args[4], (int *) req->args[5]); break; case SO_LISTEN: /* FIXME: 32/64 conversion */ err = tpi_listen(fd, req->args[2]); break; case SO_RECV: /* FIXME: 32/64 conversion */ err = tpi_recv(fd, (void *) req->args[2], req->args[3], req->args[4]); break; case SO_RECVFROM: /* FIXME: 32/64 conversion */ err = tpi_recvfrom(fd, (void *) req->args[2], req->args[3], req->args[4], (struct sockaddr *) req->args[5], (int *) req->args[6]); break; case SO_SEND: /* FIXME: 32/64 conversion */ err = tpi_send(fd, (void *) req->args[2], req->args[3], req->args[4]); break; case SO_SENDTO: /* FIXME: 32/64 conversion */ err = tpi_sendto(fd, (void *) req->args[2], req->args[3], req->args[4], (struct sockaddr *) req->args[5], req->args[6]); break; case SO_SETSOCKOPT: /* FIXME: 32/64 conversion */ err = tpi_setsockopt(fd, req->args[2], req->args[3], (char *) req->args[4], req->args[5]); break; case SO_SHUTDOWN: /* FIXME: 32/64 conversion */ err = tpi_shutdown(fd, req->args[2]); break; case SO_RECVMSG: /* FIXME: 32/64 conversion */ err = tpi_recvmsg(fd, (struct msghdr *) req->args[2], req->args[3]); break; case SO_SENDMSG: /* FIXME: 32/64 conversion */ err = tpi_sendmsg(fd, (struct msghdr *) req->args[2], req->args[3]); break; } } #endif } if ((1 << cmd) & ((1 << SO_SOCKET) | (1 << SO_SOCKPAIR) | (1 << SO_SELECT) | (1 << SO_GETIPDOMAIN) | (1 << SO_SETIPDOMAIN) | (1 << SO_ADJTIME) | (1 << SO_SETREUID) | (1 << SO_SETREGID) | (1 << SO_GETTIME) | (1 << SO_SETTIME) | (1 << SO_GETITIMER) | (1 << SO_SETITIMER))) { /* These are BSD compatibiltiy functions and are how we create sockets in the first place. The BSD compatibility functions all have system calls in Linux, but we provide them for backward compatibility (to what!?). */ #if 0 switch (cmd) { case SO_SOCKET: /* FIXME: 32/64 conversion */ /* XXX: don't think so..., after checking for a stream */ err = sys_socket(req->args[1], req->args[2], req->args[3]); break; case SO_SOCKPAIR: /* FIXME: 32/64 conversion */ /* XXX: don't think so..., after checking for a stream */ err = sys_socketpair(req->args[1], req->args[2], req->args[3], (int *) req->args[4]); err = -EOPNOTSUPP; break; case SO_SELECT: /* FIXME: 32/64 conversion */ err = sys_select(req->args[1], (fd_set *) req->args[2], (fd_set *) req->args[3], (fd_set *) req->args[4], (struct timeval *) req->args[5]); break; case SO_GETIPDOMAIN: /* FIXME: 32/64 conversion */ todo(("Process SO_GETIPDOMAIN for compatibility.\n")); /* does not exist in Linux, need to use sys_newuname and copy the domainname portion */ err = -ENOSYS; break; case SO_SETIPDOMAIN: /* FIXME: 32/64 conversion */ err = sys_setdomainname((char *) req->args[1], req->args[2]); break; case SO_ADJTIME: /* FIXME: 32/64 conversion */ err = sys_admtimex((struct timex *) req->args[1]); break; case SO_SETREUID: /* FIXME: 32/64 conversion */ err = sys_setreuid(req->args[1], req->args[2]); break; case SO_SETREGID: /* FIXME: 32/64 conversion */ err = sys_setregid(req->args[1], req->args[2]); break; case SO_GETTIME: /* FIXME: 32/64 conversion */ err = sys_gettimeofday((struct timeval *) req->args[1], (struct timezone *) req->args[2]); break; case SO_SETTIME: /* FIXME: 32/64 conversion */ err = sys_settimeofday((struct timeval *) req->args[1], (struct timezone *) req->args[2]); break; case SO_GETITIMER: /* FIXME: 32/64 conversion */ err = sys_getitimer(req->args[1], (struct itimerval *) req->args[2]); break; case SO_SETITIMER: /* FIXME: 32/64 conversion */ err = sys_getitimer(req->args[1], (struct itimerval *) req->args[2], (struct itimerval *) req->args[3]); break; } #endif } return (err); }
/* * Entry point to all Linux socket calls. Just check which call to * make and take appropriate action. */ int linux_sys_socketcall(struct lwp *l, const struct linux_sys_socketcall_args *uap, register_t *retval) { /* { syscallarg(int) what; syscallarg(void *) args; } */ struct linux_socketcall_dummy_args lda; int error; if (SCARG(uap, what) < 0 || SCARG(uap, what) > LINUX_MAX_SOCKETCALL) return ENOSYS; if ((error = copyin(SCARG(uap, args), &lda, linux_socketcall[SCARG(uap, what)].argsize))) { DPRINTF(("copyin for %s failed %d\n", linux_socketcall[SCARG(uap, what)].name, error)); return error; } ktrkuser(linux_socketcall[SCARG(uap, what)].name, &lda, linux_socketcall[SCARG(uap, what)].argsize); #ifdef DEBUG_LINUX /* dump the passed argument data */ { DPRINTF(("linux_socketcall('%s'): ", linux_socketcall[SCARG(uap, what)].name)); if (SCARG(uap, what) == LINUX_SYS_SOCKET) { DPRINTF(("[dom %d type %d proto %d]\n", lda.dummy_ints[0], lda.dummy_ints[1], lda.dummy_ints[2])); } else { int i, sz; u_int8_t *data = (u_int8_t *)&lda.dummy_ints[1]; sz = linux_socketcall[SCARG(uap, what)].argsize - sizeof(lda.dummy_ints[0]); DPRINTF(("socket %d [", lda.dummy_ints[0])); for(i=0; i < sz; i++) DPRINTF(("%02x ", data[i])); DPRINTF(("]\n")); } } #endif switch (SCARG(uap, what)) { case LINUX_SYS_SOCKET: error = linux_sys_socket(l, (void *)&lda, retval); break; case LINUX_SYS_BIND: error = linux_sys_bind(l, (void *)&lda, retval); break; case LINUX_SYS_CONNECT: error = linux_sys_connect(l, (void *)&lda, retval); break; case LINUX_SYS_LISTEN: error = sys_listen(l, (void *)&lda, retval); break; case LINUX_SYS_ACCEPT: error = linux_sys_accept(l, (void *)&lda, retval); break; case LINUX_SYS_GETSOCKNAME: error = linux_sys_getsockname(l, (void *)&lda, retval); break; case LINUX_SYS_GETPEERNAME: error = linux_sys_getpeername(l, (void *)&lda, retval); break; case LINUX_SYS_SOCKETPAIR: error = linux_sys_socketpair(l, (void *)&lda, retval); break; case LINUX_SYS_SEND: error = linux_sys_send(l, (void *)&lda, retval); break; case LINUX_SYS_RECV: error = linux_sys_recv(l, (void *)&lda, retval); break; case LINUX_SYS_SENDTO: error = linux_sys_sendto(l, (void *)&lda, retval); break; case LINUX_SYS_RECVFROM: error = linux_sys_recvfrom(l, (void *)&lda, retval); break; case LINUX_SYS_SHUTDOWN: error = sys_shutdown(l, (void *)&lda, retval); break; case LINUX_SYS_SETSOCKOPT: error = linux_sys_setsockopt(l, (void *)&lda, retval); break; case LINUX_SYS_GETSOCKOPT: error = linux_sys_getsockopt(l, (void *)&lda, retval); break; case LINUX_SYS_SENDMSG: error = linux_sys_sendmsg(l, (void *)&lda, retval); break; case LINUX_SYS_RECVMSG: error = linux_sys_recvmsg(l, (void *)&lda, retval); break; default: error = ENOSYS; break; } DPRINTF(("sys_%s() = %d\n", linux_socketcall[SCARG(uap, what)].name, error)); return error; }