FreeBSD Bugzilla – Attachment 243661 Details for
Bug 272770
"divert-to" rule creates packet loops on all FreeBSD 11.0 to 14.0 CURRENT versions
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
Remember
[x]
|
Forgot Password
Login:
[x]
divert-to test code
file_272770.txt (text/plain), 1.94 KB, created by
Alfa
on 2023-07-28 07:21:25 UTC
(
hide
)
Description:
divert-to test code
Filename:
MIME Type:
Creator:
Alfa
Created:
2023-07-28 07:21:25 UTC
Size:
1.94 KB
patch
obsolete
>#define _GNU_SOURCE >#include <sys/types.h> >#include <sys/socket.h> >#include <arpa/inet.h> >#include <netinet/in.h> >#include <netinet/ip.h> >#include <net/if.h> >#include <stdlib.h> >#include <string.h> >#include <unistd.h> >#include <stdio.h> > >#define BUFSIZE 65535 > >int main() >{ > int ret, data_size; > struct sockaddr_in bindPort, sin; > socklen_t sinlen; > > unsigned char *packet = (unsigned char *)malloc(65536); //Its Big! > unsigned char *new_packet = (unsigned char *)malloc(65536); //Its Big! > > > /* open a divert socket */ > int bind_socket; // divert_socket_bind > bind_socket = socket(PF_INET, SOCK_RAW, IPPROTO_DIVERT); > > if (bind_socket == -1) { > perror("socket_bind_error"); > > exit(1); > } > > bindPort.sin_family=PF_INET; > bindPort.sin_port=htons(3355); > bindPort.sin_addr.s_addr=0; > > fprintf(stderr,"%d:Binding a socket\n",3355); > ret = bind(bind_socket, (struct sockaddr *)&bindPort, sizeof(struct sockaddr_in)); > > if(ret!=0){ > close(bind_socket); > fprintf(stderr, "%d: Error bind(): %s",3355,strerror(ret)); > exit(2); > } > > printf("Waiting for data...\n"); > > > sinlen = sizeof(struct sockaddr_in); > struct ip_header *hdr; > > > while(1){ > data_size=recvfrom(bind_socket, packet, BUFSIZE, 0, (struct sockaddr *) &sin, &sinlen); > if(data_size < 0){ > printf("Recvfrom Error, failed get packets \n"); > return 1; > } > > struct ip *ip_data = (struct ip *)packet; > > char source_ip[20], destination_ip[20]; > inet_ntop(AF_INET, &ip_data->ip_src, source_ip, sizeof(source_ip)); > inet_ntop(AF_INET, &ip_data->ip_dst, destination_ip, sizeof(destination_ip)); > > printf("source_ip : %s \n",source_ip); > printf("destination_ip : %s \n",destination_ip); > > data_size = sendto(bind_socket, packet, data_size ,0, (struct sockaddr *) &sin, sinlen); > } >}
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Raw
Actions:
View
Attachments on
bug 272770
: 243661