2 ctdb system specific code to manage raw sockets on linux
4 Copyright (C) Ronnie Sahlberg 2007
5 Copyright (C) Andrew Tridgell 2007
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, see <http://www.gnu.org/licenses/>.
22 #include "system/network.h"
24 #include "lib/util/debug.h"
26 #include "protocol/protocol.h"
28 #include "common/logging.h"
29 #include "common/system.h"
32 uint16 checksum for n bytes
34 uint32_t uint16_checksum(uint16_t *data
, size_t n
)
38 sum
+= (uint32_t)ntohs(*data
);
43 sum
+= (uint32_t)ntohs(*(uint8_t *)data
);
49 see if we currently have an interface with the given IP
51 we try to bind to it, and if that fails then we don't have that IP
54 bool ctdb_sys_have_ip(ctdb_sock_addr
*_addr
)
58 ctdb_sock_addr __addr
= *_addr
;
59 ctdb_sock_addr
*addr
= &__addr
;
60 socklen_t addrlen
= 0;
62 switch (addr
->sa
.sa_family
) {
64 addr
->ip
.sin_port
= 0;
65 addrlen
= sizeof(struct sockaddr_in
);
68 addr
->ip6
.sin6_port
= 0;
69 addrlen
= sizeof(struct sockaddr_in6
);
73 s
= socket(addr
->sa
.sa_family
, SOCK_STREAM
, IPPROTO_TCP
);
78 ret
= bind(s
, (struct sockaddr
*)addr
, addrlen
);