1
0
mirror of https://code.semirocket.science/wrapsix synced 2024-09-20 07:11:06 +03:00
wrapsix/wrapper/connections.c
xHire 4bc68edce5 Improved creating of a socket for the resolver
Written new mechanism of wrapper from scratch in C
* It listens to all ICMPv6 packets (for now) and translates them to ICMPv4 ones
* It can compute the checksum of the packet as well
2008-12-31 13:41:21 +01:00

24 lines
626 B
C

#include <unistd.h>
#include "wrapper.h"
void send_there(struct in_addr ip4_addr, unsigned char ttl, unsigned int type, unsigned char *payload, unsigned int paylen) {
int sock;
struct sockaddr_in sock_addr;
if ((sock = socket(AF_INET, SOCK_RAW, type)) == -1) {
fprintf(stderr, "Couldn't open RAW socket.\n");
exit(EXIT_FAILURE);
}
setsockopt(sock, IPPROTO_IP, IP_TTL, (const char *) &ttl, sizeof(ttl));
sock_addr.sin_family = AF_INET;
sock_addr.sin_port = 0;
sock_addr.sin_addr = ip4_addr;
sendto(sock, (char *) payload, paylen, 0, (struct sockaddr *) &sock_addr, sizeof(struct sockaddr));
close(sock);
}