Whamcloud - gitweb
LU-5577 libcfs: fix warnings in libcfs/curproc.h
[fs/lustre-release.git] / libcfs / include / libcfs / user-tcpip.h
1 /*
2  * GPL HEADER START
3  *
4  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License version 2 only,
8  * as published by the Free Software Foundation.
9  *
10  * This program is distributed in the hope that it will be useful, but
11  * WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  * General Public License version 2 for more details (a copy is included
14  * in the LICENSE file that accompanied this code).
15  *
16  * You should have received a copy of the GNU General Public License
17  * version 2 along with this program; If not, see
18  * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf
19  *
20  * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
21  * CA 95054 USA or visit www.sun.com if you need additional information or
22  * have any questions.
23  *
24  * GPL HEADER END
25  */
26 /*
27  * Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved.
28  * Use is subject to license terms.
29  */
30 /*
31  * This file is part of Lustre, http://www.lustre.org/
32  * Lustre is a trademark of Sun Microsystems, Inc.
33  */
34
35 #ifndef __LIBCFS_USER_TCPIP_H__
36 #define __LIBCFS_USER_TCPIP_H__
37
38 #ifndef __LIBCFS_LIBCFS_H__
39 #error Do not #include this file directly. #include <libcfs/libcfs.h> instead
40 #endif
41
42 #ifndef __KERNEL__
43
44 #include <sys/uio.h>
45 #include <endian.h>
46
47 /*
48  * Functions to get network interfaces info
49  */
50
51 int libcfs_sock_ioctl(int cmd, unsigned long arg);
52 int libcfs_ipif_query (char *name, int *up, __u32 *ip);
53 void libcfs_ipif_free_enumeration (char **names, int n);
54 int libcfs_ipif_enumerate (char ***namesp);
55
56 /*
57  * Network function used by user-land lnet acceptor
58  */
59
60 typedef struct cfs_socket {
61         int s_fd;
62 } cfs_socket_t;
63
64 #define LIBCFS_SOCK2FD(sock) ((sock)->s_fd)
65
66 int libcfs_sock_listen(cfs_socket_t **sockp, __u32 ip, int port, int backlog);
67 int libcfs_sock_accept(cfs_socket_t **newsockp, cfs_socket_t *sock);
68 int libcfs_sock_read(cfs_socket_t *sock, void *buffer, int nob, int timeout);
69 int libcfs_sock_write(cfs_socket_t *sock, void *buffer, int nob, int timeout);
70 void libcfs_sock_abort_accept(cfs_socket_t *sock);
71 void libcfs_sock_release(cfs_socket_t *sock);
72 int libcfs_sock_getaddr(cfs_socket_t *sock, int remote, __u32 *ip, int *port);
73
74 /*
75  * Network functions of common use
76  */
77
78 int libcfs_socketpair(cfs_socket_t **sockp);
79 int libcfs_fcntl_nonblock(cfs_socket_t *sock);
80 int libcfs_sock_set_nagle(cfs_socket_t *sock, int nagle);
81 int libcfs_sock_set_bufsiz(cfs_socket_t *sock, int bufsiz);
82 int libcfs_sock_connect(cfs_socket_t *sock, __u32 ip, __u16 port);
83 int libcfs_sock_writev(cfs_socket_t *sock,
84                        const struct iovec *vector, int count);
85 int libcfs_sock_readv(cfs_socket_t *sock,
86                       const struct iovec *vector, int count);
87 int libcfs_sock_create(cfs_socket_t **sockp, int *fatal,
88                        __u32 local_ip, int local_port);
89
90
91 /*
92  * Macros for easy printing IP-adresses
93  */
94
95 #define NIPQUAD(addr) \
96         ((unsigned char *)&addr)[0], \
97         ((unsigned char *)&addr)[1], \
98         ((unsigned char *)&addr)[2], \
99         ((unsigned char *)&addr)[3]
100
101 #if __BYTE_ORDER == __LITTLE_ENDIAN
102 #define HIPQUAD(addr)                \
103         ((unsigned char *)&addr)[3], \
104         ((unsigned char *)&addr)[2], \
105         ((unsigned char *)&addr)[1], \
106         ((unsigned char *)&addr)[0]
107 #elif __BYTE_ORDER == __BIG_ENDIAN
108 #define HIPQUAD NIPQUAD
109 #else
110 #error "Undefined byteorder??"
111 #endif /* __LITTLE_ENDIAN */
112
113 #endif /* !__KERNEL__ */
114
115 #endif