9069 libfru: comparison between pointer and zero character constant
[unleashed.git] / usr / src / lib / libwanboot / common / socket_inet.c
blobf1ddd29e5362ccbcfa8f83b8750051b357212606
1 /*
2 * CDDL HEADER START
4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License, Version 1.0 only
6 * (the "License"). You may not use this file except in compliance
7 * with the License.
9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10 * or http://www.opensolaris.org/os/licensing.
11 * See the License for the specific language governing permissions
12 * and limitations under the License.
14 * When distributing Covered Code, include this CDDL HEADER in each
15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16 * If applicable, add the following below this CDDL HEADER, with the
17 * fields enclosed by brackets "[]" replaced with your own identifying
18 * information: Portions Copyright [yyyy] [name of copyright owner]
20 * CDDL HEADER END
23 * Copyright 2002-2003 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
27 #pragma ident "%Z%%M% %I% %E% SMI"
29 #include <sys/types.h>
30 #include <sys/socket.h>
31 #include <netinet/in.h>
32 #include <unistd.h>
33 #include <poll.h>
34 #include <errno.h>
36 #include <socket_inet.h>
39 * Name: socket_read
40 * Description: Use recv in non-secure sockets.
41 * Scope: private
42 * Arguments: fildes - Socket file descriptor.
43 * buf - Buffer to read data into.
44 * nbyte - Number of bytes to read.
45 * read_timeout - Timeout value in seconds.
46 * Returns: n - Number of bytes read. -1 on error.
48 int
49 socket_read(int fildes, void *buf, size_t nbyte, int read_timeout)
51 struct pollfd pfd;
53 pfd.fd = fildes;
54 pfd.events = POLLIN;
56 switch (poll(&pfd, 1, read_timeout * 1000)) {
57 case 0:
58 errno = EINTR;
59 return (-1);
60 case -1:
61 return (-1);
62 default:
63 break;
66 return (recv(fildes, buf, nbyte, 0));
70 * Name: socket_write
71 * Description: Use sendto for non-secure connections.
72 * Scope: private
73 * Arguments: fildes - Socket file descriptor.
74 * buf - Buffer containing data to be written.
75 * nbyte - Number of bytes to write.
76 * addr - Connection address
77 * Returns: n - Number of bytes written. -1 on error.
79 int
80 socket_write(int fildes, const void *buf, size_t nbyte,
81 struct sockaddr_in *addr)
83 return (sendto(fildes, buf, nbyte, 0, (struct sockaddr *)addr,
84 sizeof (*addr)));
87 int
88 socket_close(int fildes)
90 return (close(fildes));