2 * CDE - Common Desktop Environment
4 * Copyright (c) 1993-2012, The Open Group. All rights reserved.
6 * These libraries and programs are free software; you can
7 * redistribute them and/or modify them under the terms of the GNU
8 * Lesser General Public License as published by the Free Software
9 * Foundation; either version 2 of the License, or (at your option)
12 * These libraries and programs are distributed in the hope that
13 * they will be useful, but WITHOUT ANY WARRANTY; without even the
14 * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU Lesser General Public License for more
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with these librararies and programs; if not, write
20 * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
21 * Floor, Boston, MA 02110-1301 USA
23 /* $XConsortium: tclIOSock.c /main/2 1996/08/08 14:44:39 cde-hp $ */
27 * Common routines used by all socket based channel types.
29 * Copyright (c) 1995 Sun Microsystems, Inc.
31 * See the file "license.terms" for information on usage and redistribution
32 * of this file, and for a DISCLAIMER OF ALL WARRANTIES.
34 * SCCS: @(#) tclIOSock.c 1.16 96/03/12 07:04:33
41 *----------------------------------------------------------------------
45 * Maps from a string, which could be a service name, to a port.
46 * Used by socket creation code to get port numbers and resolve
47 * registered service names to port numbers.
50 * A standard Tcl result. On success, the port number is
51 * returned in portPtr. On failure, an error message is left in
57 *----------------------------------------------------------------------
61 TclSockGetPort(interp, string, proto, portPtr)
63 char *string; /* Integer or service name */
64 char *proto; /* "tcp" or "udp", typically */
65 int *portPtr; /* Return port number */
67 struct servent *sp = getservbyname(string, proto);
69 *portPtr = ntohs((unsigned short) sp->s_port);
72 if (Tcl_GetInt(interp, string, portPtr) != TCL_OK) {
75 if (*portPtr > 0xFFFF) {
76 Tcl_AppendResult(interp, "couldn't open socket: port number too high",
84 *----------------------------------------------------------------------
86 * TclSockMinimumBuffers --
88 * Ensure minimum buffer sizes (non zero).
91 * A standard Tcl result.
94 * Sets SO_SNDBUF and SO_RCVBUF sizes.
96 *----------------------------------------------------------------------
100 TclSockMinimumBuffers(sock, size)
101 int sock; /* Socket file descriptor */
102 int size; /* Minimum buffer size */
105 int len = sizeof(int);
107 getsockopt(sock, SOL_SOCKET, SO_SNDBUF, (char *) ¤t, &len);
108 if (current < size) {
110 setsockopt(sock, SOL_SOCKET, SO_SNDBUF, (char *) &size, len);
113 getsockopt(sock, SOL_SOCKET, SO_RCVBUF, (char *) ¤t, &len);
114 if (current < size) {
116 setsockopt(sock, SOL_SOCKET, SO_RCVBUF, (char *) &size, len);