svr4_stream.c (86487) | svr4_stream.c (89306) |
---|---|
1/* 2 * Copyright (c) 1998 Mark Newton. All rights reserved. 3 * Copyright (c) 1994, 1996 Christos Zoulas. All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright --- 13 unchanged lines hidden (view full) --- 22 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 23 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 24 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 28 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 * | 1/* 2 * Copyright (c) 1998 Mark Newton. All rights reserved. 3 * Copyright (c) 1994, 1996 Christos Zoulas. All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright --- 13 unchanged lines hidden (view full) --- 22 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 23 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 24 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 28 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 * |
30 * $FreeBSD: head/sys/compat/svr4/svr4_stream.c 86487 2001-11-17 03:07:11Z dillon $ | 30 * $FreeBSD: head/sys/compat/svr4/svr4_stream.c 89306 2002-01-13 11:58:06Z alfred $ |
31 */ 32 33/* 34 * Pretend that we have streams... 35 * Yes, this is gross. 36 * 37 * ToDo: The state machine for getmsg needs re-thinking 38 */ --- 33 unchanged lines hidden (view full) --- 72#include <compat/svr4/svr4_timod.h> 73#include <compat/svr4/svr4_sockmod.h> 74#include <compat/svr4/svr4_ioctl.h> 75#include <compat/svr4/svr4_socket.h> 76 77/* Utils */ 78static int clean_pipe __P((struct thread *, const char *)); 79static void getparm __P((struct file *, struct svr4_si_sockparms *)); | 31 */ 32 33/* 34 * Pretend that we have streams... 35 * Yes, this is gross. 36 * 37 * ToDo: The state machine for getmsg needs re-thinking 38 */ --- 33 unchanged lines hidden (view full) --- 72#include <compat/svr4/svr4_timod.h> 73#include <compat/svr4/svr4_sockmod.h> 74#include <compat/svr4/svr4_ioctl.h> 75#include <compat/svr4/svr4_socket.h> 76 77/* Utils */ 78static int clean_pipe __P((struct thread *, const char *)); 79static void getparm __P((struct file *, struct svr4_si_sockparms *)); |
80static int svr4_do_putmsg __P((struct proc *, struct svr4_sys_putmsg_args *, 81 struct file *)); 82static int svr4_do_getmsg __P((struct proc *, struct svr4_sys_getmsg_args *, 83 struct file *)); |
|
80 81/* Address Conversions */ 82static void sockaddr_to_netaddr_in __P((struct svr4_strmcmd *, 83 const struct sockaddr_in *)); 84static void sockaddr_to_netaddr_un __P((struct svr4_strmcmd *, 85 const struct sockaddr_un *)); 86static void netaddr_to_sockaddr_in __P((struct sockaddr_in *, 87 const struct svr4_strmcmd *)); --- 142 unchanged lines hidden (view full) --- 230 } 231 FREE(ktriov, M_TEMP); 232 } 233#endif 234bad: 235 if (to) 236 FREE(to, M_SONAME); 237done1: | 84 85/* Address Conversions */ 86static void sockaddr_to_netaddr_in __P((struct svr4_strmcmd *, 87 const struct sockaddr_in *)); 88static void sockaddr_to_netaddr_un __P((struct svr4_strmcmd *, 89 const struct sockaddr_un *)); 90static void netaddr_to_sockaddr_in __P((struct sockaddr_in *, 91 const struct svr4_strmcmd *)); --- 142 unchanged lines hidden (view full) --- 234 } 235 FREE(ktriov, M_TEMP); 236 } 237#endif 238bad: 239 if (to) 240 FREE(to, M_SONAME); 241done1: |
242 fdrop(fp, td); |
|
238 fputsock(so); 239 return (error); 240} 241 242static int 243svr4_recvit(td, s, mp, namelenp) 244 register struct thread *td; 245 int s; --- 108 unchanged lines hidden (view full) --- 354 mp->msg_controllen = ctlbuf - (caddr_t)mp->msg_control; 355 } 356out: 357 if (fromsa) 358 FREE(fromsa, M_SONAME); 359 if (control) 360 m_freem(control); 361done1: | 243 fputsock(so); 244 return (error); 245} 246 247static int 248svr4_recvit(td, s, mp, namelenp) 249 register struct thread *td; 250 int s; --- 108 unchanged lines hidden (view full) --- 359 mp->msg_controllen = ctlbuf - (caddr_t)mp->msg_control; 360 } 361out: 362 if (fromsa) 363 FREE(fromsa, M_SONAME); 364 if (control) 365 m_freem(control); 366done1: |
367 fdrop(fp, td); |
|
362 fputsock(so); 363 return (error); 364} 365 366#ifdef DEBUG_SVR4 367static void bufprint __P((u_char *, size_t)); 368static int show_ioc __P((const char *, struct svr4_strioctl *)); 369static int show_strbuf __P((struct svr4_strbuf *)); --- 244 unchanged lines hidden (view full) --- 614} 615 616 617static void 618getparm(fp, pa) 619 struct file *fp; 620 struct svr4_si_sockparms *pa; 621{ | 368 fputsock(so); 369 return (error); 370} 371 372#ifdef DEBUG_SVR4 373static void bufprint __P((u_char *, size_t)); 374static int show_ioc __P((const char *, struct svr4_strioctl *)); 375static int show_strbuf __P((struct svr4_strbuf *)); --- 244 unchanged lines hidden (view full) --- 620} 621 622 623static void 624getparm(fp, pa) 625 struct file *fp; 626 struct svr4_si_sockparms *pa; 627{ |
622 struct svr4_strm *st = svr4_stream_get(fp); 623 struct socket *so = (struct socket *) fp->f_data; | 628 struct svr4_strm *st; 629 struct socket *so; |
624 | 630 |
631 st = svr4_stream_get(fp); |
|
625 if (st == NULL) 626 return; 627 | 632 if (st == NULL) 633 return; 634 |
635 so = (struct socket *) fp->f_data; 636 |
|
628 pa->family = st->s_family; 629 630 switch (so->so_type) { 631 case SOCK_DGRAM: 632 pa->type = SVR4_T_CLTS; 633 pa->protocol = IPPROTO_UDP; 634 DPRINTF(("getparm(dgram)\n")); 635 return; --- 1064 unchanged lines hidden (view full) --- 1700 1701 1702 1703int 1704svr4_sys_putmsg(td, uap) 1705 register struct thread *td; 1706 struct svr4_sys_putmsg_args *uap; 1707{ | 637 pa->family = st->s_family; 638 639 switch (so->so_type) { 640 case SOCK_DGRAM: 641 pa->type = SVR4_T_CLTS; 642 pa->protocol = IPPROTO_UDP; 643 DPRINTF(("getparm(dgram)\n")); 644 return; --- 1064 unchanged lines hidden (view full) --- 1709 1710 1711 1712int 1713svr4_sys_putmsg(td, uap) 1714 register struct thread *td; 1715 struct svr4_sys_putmsg_args *uap; 1716{ |
1708 struct filedesc *fdp = td->td_proc->p_fd; | 1717 struct file *fp; 1718 int error; 1719 1720 fp = ffind_hold(td, uap->fd); 1721 if (fp == NULL) { 1722#ifdef DEBUG_SVR4 1723 uprintf("putmsg: bad fp\n"); 1724#endif 1725 return EBADF; 1726 } 1727 error = svr4_do_putmsg(td, uap, fp); 1728 fdrop(fp, td); 1729 return (error); 1730} 1731 1732static int 1733svr4_do_putmsg(td, uap, fp) 1734 struct thread *td; 1735 struct svr4_sys_putmsg_args *uap; |
1709 struct file *fp; | 1736 struct file *fp; |
1737{ |
|
1710 struct svr4_strbuf dat, ctl; 1711 struct svr4_strmcmd sc; 1712 struct sockaddr_in sain; 1713 struct sockaddr_un saun; 1714 void *skp, *sup; 1715 int sasize, *retval; 1716 struct svr4_strm *st; 1717 int error; 1718 caddr_t sg; 1719 1720 retval = td->td_retval; | 1738 struct svr4_strbuf dat, ctl; 1739 struct svr4_strmcmd sc; 1740 struct sockaddr_in sain; 1741 struct sockaddr_un saun; 1742 void *skp, *sup; 1743 int sasize, *retval; 1744 struct svr4_strm *st; 1745 int error; 1746 caddr_t sg; 1747 1748 retval = td->td_retval; |
1721 fp = fdp->fd_ofiles[SCARG(uap, fd)]; | |
1722 | 1749 |
1723 if (((u_int)SCARG(uap, fd) >= fdp->fd_nfiles) || (fp == NULL)) { | |
1724#ifdef DEBUG_SVR4 | 1750#ifdef DEBUG_SVR4 |
1725 uprintf("putmsg: bad fp\n"); 1726#endif 1727 return EBADF; 1728 } 1729 1730#ifdef DEBUG_SVR4 | |
1731 show_msg(">putmsg", SCARG(uap, fd), SCARG(uap, ctl), 1732 SCARG(uap, dat), SCARG(uap, flags)); 1733#endif /* DEBUG_SVR4 */ 1734 | 1751 show_msg(">putmsg", SCARG(uap, fd), SCARG(uap, ctl), 1752 SCARG(uap, dat), SCARG(uap, flags)); 1753#endif /* DEBUG_SVR4 */ 1754 |
1735 if (((u_int)SCARG(uap, fd) >= fdp->fd_nfiles) || (fp == NULL)) { 1736#ifdef DEBUG_SVR4 1737 uprintf("putmsg: bad fp(2)\n"); 1738#endif 1739 return EBADF; 1740 } | 1755 FILE_LOCK_ASSERT(fp, MA_NOTOWNED); |
1741 1742 if (SCARG(uap, ctl) != NULL) { 1743 if ((error = copyin(SCARG(uap, ctl), &ctl, sizeof(ctl))) != 0) { 1744#ifdef DEBUG_SVR4 1745 uprintf("putmsg: copyin(): %d\n", error); 1746#endif 1747 return error; 1748 } --- 129 unchanged lines hidden (view full) --- 1878 1879 default: 1880 DPRINTF(("putmsg: Unimplemented command %lx\n", sc.cmd)); 1881 return ENOSYS; 1882 } 1883} 1884 1885int | 1756 1757 if (SCARG(uap, ctl) != NULL) { 1758 if ((error = copyin(SCARG(uap, ctl), &ctl, sizeof(ctl))) != 0) { 1759#ifdef DEBUG_SVR4 1760 uprintf("putmsg: copyin(): %d\n", error); 1761#endif 1762 return error; 1763 } --- 129 unchanged lines hidden (view full) --- 1893 1894 default: 1895 DPRINTF(("putmsg: Unimplemented command %lx\n", sc.cmd)); 1896 return ENOSYS; 1897 } 1898} 1899 1900int |
1901svr4_sys_getmsg(p, uap) 1902 struct proc *p; 1903 struct svr4_sys_getmsg_args *uap; 1904{ 1905 struct file *fp; 1906 int error; 1907 1908 fp = ffind_hold(td, uap->fd); 1909 if (fp == NULL) { 1910#ifdef DEBUG_SVR4 1911 uprintf("getmsg: bad fp\n"); 1912#endif 1913 return EBADF; 1914 } 1915 error = svr4_do_getmsg(p, uap, fp); 1916 fdrop(fp, td); 1917 return (error); 1918} 1919 1920int |
|
1886svr4_sys_getmsg(td, uap) 1887 register struct thread *td; 1888 struct svr4_sys_getmsg_args *uap; | 1921svr4_sys_getmsg(td, uap) 1922 register struct thread *td; 1923 struct svr4_sys_getmsg_args *uap; |
1924 struct file *fp; |
|
1889{ | 1925{ |
1890 struct filedesc *fdp = td->td_proc->p_fd; 1891 struct file *fp; | |
1892 struct getpeername_args ga; 1893 struct accept_args aa; 1894 struct svr4_strbuf dat, ctl; 1895 struct svr4_strmcmd sc; 1896 int error, *retval; 1897 struct msghdr msg; 1898 struct iovec aiov; 1899 struct sockaddr_in sain; 1900 struct sockaddr_un saun; 1901 void *skp, *sup; 1902 int sasize; 1903 struct svr4_strm *st; 1904 int *flen; 1905 int fl; 1906 caddr_t sg; 1907 1908 retval = td->td_retval; | 1926 struct getpeername_args ga; 1927 struct accept_args aa; 1928 struct svr4_strbuf dat, ctl; 1929 struct svr4_strmcmd sc; 1930 int error, *retval; 1931 struct msghdr msg; 1932 struct iovec aiov; 1933 struct sockaddr_in sain; 1934 struct sockaddr_un saun; 1935 void *skp, *sup; 1936 int sasize; 1937 struct svr4_strm *st; 1938 int *flen; 1939 int fl; 1940 caddr_t sg; 1941 1942 retval = td->td_retval; |
1909 fp = fdp->fd_ofiles[SCARG(uap, fd)]; | |
1910 | 1943 |
1911 if (((u_int)SCARG(uap, fd) >= fdp->fd_nfiles) || (fp == NULL)) 1912 return EBADF; | 1944 FILE_LOCK_ASSERT(fp, MA_NOTOWNED); |
1913 1914 memset(&sc, 0, sizeof(sc)); 1915 1916#ifdef DEBUG_SVR4 1917 show_msg(">getmsg", SCARG(uap, fd), SCARG(uap, ctl), 1918 SCARG(uap, dat), 0); 1919#endif /* DEBUG_SVR4 */ | 1945 1946 memset(&sc, 0, sizeof(sc)); 1947 1948#ifdef DEBUG_SVR4 1949 show_msg(">getmsg", SCARG(uap, fd), SCARG(uap, ctl), 1950 SCARG(uap, dat), 0); 1951#endif /* DEBUG_SVR4 */ |
1920 1921 if (((u_int)SCARG(uap, fd) >= fdp->fd_nfiles) || (fp == NULL)) 1922 return EBADF; | |
1923 1924 if (SCARG(uap, ctl) != NULL) { 1925 if ((error = copyin(SCARG(uap, ctl), &ctl, sizeof(ctl))) != 0) 1926 return error; 1927 } 1928 else { 1929 ctl.len = -1; 1930 ctl.maxlen = 0; --- 343 unchanged lines hidden --- | 1952 1953 if (SCARG(uap, ctl) != NULL) { 1954 if ((error = copyin(SCARG(uap, ctl), &ctl, sizeof(ctl))) != 0) 1955 return error; 1956 } 1957 else { 1958 ctl.len = -1; 1959 ctl.maxlen = 0; --- 343 unchanged lines hidden --- |