Print this page
9704 move socket functions to libc
Split |
Close |
Expand all |
Collapse all |
--- old/usr/src/lib/libsocket/socket/socketpair.c
+++ new/usr/src/lib/libc/port/socket/socketpair.c
1 1 /*
2 2 * CDDL HEADER START
3 3 *
4 4 * The contents of this file are subject to the terms of the
5 5 * Common Development and Distribution License, Version 1.0 only
6 6 * (the "License"). You may not use this file except in compliance
7 7 * with the License.
8 8 *
9 9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10 10 * or http://www.opensolaris.org/os/licensing.
11 11 * See the License for the specific language governing permissions
12 12 * and limitations under the License.
13 13 *
14 14 * When distributing Covered Code, include this CDDL HEADER in each
15 15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16 16 * If applicable, add the following below this CDDL HEADER, with the
17 17 * fields enclosed by brackets "[]" replaced with your own identifying
18 18 * information: Portions Copyright [yyyy] [name of copyright owner]
19 19 *
20 20 * CDDL HEADER END
21 21 */
22 22 /*
23 23 * Copyright 1997 Sun Microsystems, Inc. All rights reserved.
24 24 * Use is subject to license terms.
25 25 */
26 26
27 27 /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
28 28 /* All Rights Reserved */
29 29
↓ open down ↓ |
29 lines elided |
↑ open up ↑ |
30 30 /*
31 31 * University Copyright- Copyright (c) 1982, 1986, 1988
32 32 * The Regents of the University of California
33 33 * All Rights Reserved
34 34 *
35 35 * University Acknowledgment- Portions of this document are derived from
36 36 * software developed by the University of California, Berkeley, and its
37 37 * contributors.
38 38 */
39 39
40 -#pragma ident "%Z%%M% %I% %E% SMI"
41 -
42 40 #include <sys/types.h>
43 41 #include <sys/socket.h>
44 42 #include <sys/stropts.h>
45 43 #include <sys/stream.h>
46 44 #include <sys/socketvar.h>
47 45 #include <errno.h>
48 46 #include <unistd.h>
49 47 #include <stdlib.h>
50 48
51 -extern int _socket_create(int, int, int, int);
52 -extern int _so_socketpair(int*);
49 +extern int _so_socket(int, int, int, dev_t, int);
50 +extern int _so_socketpair(int *);
53 51
54 52 int _socketpair_create(int, int, int, int*, int);
55 53
56 54 #pragma weak socketpair = _socketpair
57 55
58 56 int
59 57 _socketpair(int family, int type, int protocol, int sv[2])
60 58 {
61 59 return (_socketpair_create(family, type, protocol, sv, SOV_DEFAULT));
62 60 }
63 61
64 62 /*
65 63 * Used by the BCP library.
66 64 */
67 65 int
68 66 _socketpair_bsd(int family, int type, int protocol, int sv[2])
69 67 {
70 68 return (_socketpair_create(family, type, protocol, sv, SOV_SOCKBSD));
71 69 }
72 70
73 71 int
74 72 _socketpair_svr4(int family, int type, int protocol, int sv[2])
75 73 {
76 74 return (_socketpair_create(family, type, protocol, sv,
77 75 SOV_SOCKSTREAM));
78 76 }
79 77
80 78 int
81 79 __xnet_socketpair(int family, int type, int protocol, int sv[2])
82 80 {
83 81 return (_socketpair_create(family, type, protocol, sv,
84 82 SOV_XPG4_2));
85 83 }
86 84
↓ open down ↓ |
24 lines elided |
↑ open up ↑ |
87 85 int
88 86 _socketpair_create(int family, int type, int protocol, int sv[2], int version)
89 87 {
90 88 int res;
91 89 int fd1, fd2;
92 90
93 91 /*
94 92 * Create the two sockets and pass them to _so_socketpair, which
95 93 * will connect them together.
96 94 */
97 - fd1 = _socket_create(family, type, protocol, version);
95 + fd1 = _so_socket(family, type, protocol, NULL, version);
98 96 if (fd1 < 0)
99 97 return (-1);
100 - fd2 = _socket_create(family, type, protocol, version);
98 + fd2 = _so_socket(family, type, protocol, NULL, version);
101 99 if (fd2 < 0) {
102 100 int error = errno;
103 101
104 102 (void) close(fd1);
105 103 errno = error;
106 104 return (-1);
107 105 }
108 106 sv[0] = fd1;
109 107 sv[1] = fd2;
110 108 res = _so_socketpair(sv);
111 109 if (res < 0) {
112 110 int error = errno;
113 111
114 112 (void) close(fd1);
115 113 (void) close(fd2);
116 114 errno = error;
117 115 return (-1);
118 116 }
119 117 /*
120 118 * Check if kernel returned different fds in which case we close
121 119 * the original ones. This is the case for SOCK_STREAM where
122 120 * one of the original sockets is used as a listener and
123 121 * _so_socketpair passes out the newly accepted socket.
124 122 */
125 123 if (sv[0] != fd1)
126 124 (void) close(fd1);
127 125 if (sv[1] != fd2)
128 126 (void) close(fd2);
129 127 return (res);
130 128 }
↓ open down ↓ |
20 lines elided |
↑ open up ↑ |
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX