1 /* 2 * Copyright (c) 2009-2011, The Regents of the University of California, 3 * through Lawrence Berkeley National Laboratory (subject to receipt of any 4 * required approvals from the U.S. Dept. of Energy). All rights reserved. 5 * 6 * This code is distributed under a BSD style license, see the LICENSE file 7 * for complete information. 8 */ 9 10 #ifndef __NET_H 11 #define __NET_H 12 13 int netdial(int domain, int proto, char *local, char *server, int port); 14 int netannounce(int domain, int proto, char *local, int port); 15 int Nread(int fd, char *buf, size_t count, int prot); 16 int Nwrite(int fd, const char *buf, size_t count, int prot) /* __attribute__((hot)) */; 17 int has_sendfile(void); 18 int Nsendfile(int fromfd, int tofd, const char *buf, size_t count) /* __attribute__((hot)) */; 19 int getsock_tcp_mss(int inSock); 20 int set_tcp_options(int sock, int no_delay, int mss); 21 int setnonblocking(int fd, int nonblocking); 22 int getsockdomain(int sock); 23 24 #define NET_SOFTERROR -1 25 #define NET_HARDERROR -2 26 27 unsigned long long htonll(unsigned long long); 28 unsigned long long ntohll(unsigned long long); 29 30 /* XXX: Need a better check for byte order */ 31 #if BYTE_ORDER == BIG_ENDIAN 32 #define HTONLL(n) (n) 33 #define NTOHLL(n) (n) 34 #else 35 #define HTONLL(n) ((((unsigned long long)(n) & 0xFF) << 56) | \ 36 (((unsigned long long)(n) & 0xFF00) << 40) | \ 37 (((unsigned long long)(n) & 0xFF0000) << 24) | \ 38 (((unsigned long long)(n) & 0xFF000000) << 8) | \ 39 (((unsigned long long)(n) & 0xFF00000000) >> 8) | \ 40 (((unsigned long long)(n) & 0xFF0000000000) >> 24) | \ 41 (((unsigned long long)(n) & 0xFF000000000000) >> 40) | \ 42 (((unsigned long long)(n) & 0xFF00000000000000) >> 56)) 43 44 #define NTOHLL(n) ((((unsigned long long)(n) & 0xFF) << 56) | \ 45 (((unsigned long long)(n) & 0xFF00) << 40) | \ 46 (((unsigned long long)(n) & 0xFF0000) << 24) | \ 47 (((unsigned long long)(n) & 0xFF000000) << 8) | \ 48 (((unsigned long long)(n) & 0xFF00000000) >> 8) | \ 49 (((unsigned long long)(n) & 0xFF0000000000) >> 24) | \ 50 (((unsigned long long)(n) & 0xFF000000000000) >> 40) | \ 51 (((unsigned long long)(n) & 0xFF00000000000000) >> 56)) 52 #endif 53 54 #define htonll(n) HTONLL(n) 55 #define ntohll(n) NTOHLL(n) 56 57 #endif 58