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