#include "system/wait.h"
#include "lib/util/debug.h"
+#include "lib/util/blocking.h"
#include "protocol/protocol.h"
struct ip6_hdr ip6;
struct tcphdr tcp;
} ip6pkt;
+ int saved_errno;
switch (src->ip.sin_family) {
case AF_INET:
ip4pkt.tcp.check = tcp_checksum((uint16_t *)&ip4pkt.tcp, sizeof(ip4pkt.tcp), &ip4pkt.ip);
/* open a raw socket to send this segment from */
- s = socket(AF_INET, SOCK_RAW, htons(IPPROTO_RAW));
+ s = socket(AF_INET, SOCK_RAW, IPPROTO_RAW);
if (s == -1) {
DEBUG(DEBUG_CRIT,(__location__ " failed to open raw socket (%s)\n",
strerror(errno)));
return -1;
}
- set_nonblocking(s);
- set_close_on_exec(s);
-
- ret = sendto(s, &ip4pkt, sizeof(ip4pkt), 0, &dest->ip, sizeof(dest->ip));
+ ret = sendto(s, &ip4pkt, sizeof(ip4pkt), 0,
+ &dest->ip, sizeof(dest->ip));
+ saved_errno = errno;
close(s);
if (ret != sizeof(ip4pkt)) {
- DEBUG(DEBUG_CRIT,(__location__ " failed sendto (%s)\n", strerror(errno)));
+ DEBUG(DEBUG_ERR,
+ ("Failed sendto (%s)\n", strerror(saved_errno)));
return -1;
}
break;
ip6pkt.tcp.window = htons(1234);
ip6pkt.tcp.check = tcp_checksum6((uint16_t *)&ip6pkt.tcp, sizeof(ip6pkt.tcp), &ip6pkt.ip6);
- s = socket(PF_INET6, SOCK_RAW, IPPROTO_RAW);
+ s = socket(AF_INET6, SOCK_RAW, IPPROTO_RAW);
if (s == -1) {
DEBUG(DEBUG_CRIT, (__location__ " Failed to open sending socket\n"));
return -1;
tmpport = tmpdest->ip6.sin6_port;
tmpdest->ip6.sin6_port = 0;
- ret = sendto(s, &ip6pkt, sizeof(ip6pkt), 0, &dest->ip6, sizeof(dest->ip6));
+ ret = sendto(s, &ip6pkt, sizeof(ip6pkt), 0,
+ &dest->ip6, sizeof(dest->ip6));
+ saved_errno = errno;
tmpdest->ip6.sin6_port = tmpport;
close(s);
if (ret != sizeof(ip6pkt)) {
- DEBUG(DEBUG_CRIT,(__location__ " failed sendto (%s)\n", strerror(errno)));
+ DEBUG(DEBUG_ERR,
+ ("Failed sendto (%s)\n", strerror(saved_errno)));
return -1;
}
break;
/*
called when the raw socket becomes readable
*/
-int ctdb_sys_read_tcp_packet(int s, void *private_data,
- ctdb_sock_addr *src, ctdb_sock_addr *dst,
- uint32_t *ack_seq, uint32_t *seq)
+int ctdb_sys_read_tcp_packet(int s, void *private_data,
+ ctdb_sock_addr *src, ctdb_sock_addr *dst,
+ uint32_t *ack_seq, uint32_t *seq,
+ int *rst, uint16_t *window)
{
int ret;
#define RCVPKTSIZE 100
return -1;
}
+ ZERO_STRUCTP(src);
+ ZERO_STRUCTP(dst);
+
/* Ethernet */
eth = (struct ether_header *)pkt;
dst->ip.sin_port = tcp->dest;
*ack_seq = tcp->ack_seq;
*seq = tcp->seq;
+ if (window != NULL) {
+ *window = tcp->window;
+ }
+ if (rst != NULL) {
+ *rst = tcp->rst;
+ }
return 0;
} else if (ntohs(eth->ether_type) == ETHERTYPE_IP6) {
*ack_seq = tcp->ack_seq;
*seq = tcp->seq;
+ if (window != NULL) {
+ *window = tcp->window;
+ }
+ if (rst != NULL) {
+ *rst = tcp->rst;
+ }
return 0;
}