Re: Redirecting Sockets using NKE
Re: Redirecting Sockets using NKE
- Subject: Re: Redirecting Sockets using NKE
- From: Matt Jaffa <email@hidden>
- Date: Mon, 7 Jun 2004 08:49:58 -0600
To be a little more informative.
Yes I could use the ipfw and make a divert rule to go to my userland
app,
but I am being more specific in what I want sent to my listening
userland app.
So what is the proper way, when I am in the send function of my Socket
level nke, to divert the packet to
my userland apps listening port. Currently I am closing that socket and
opening a new one and connecting it to my userland app. Like I
mentioned in the previous post.
int vi_send2(struct socket *so, struct sockaddr_in **addr, struct uio
**uio,
struct mbuf **top, struct mbuf **control, int *flags,
register struct kextcb *kp) {
int funnel_state;
funnel_state = thread_funnel_set(network_flock, TRUE);
//Code to figure out if get, already done
if(GETREQUEST) {
// Need to Divert packet now to my userland app, below is what I try
to do:
struct sockaddr_in server; /* the information structure for the
server (to be filled out) */
bzero(&server, sizeof(struct sockaddr_in));
struct in_addr s_addr;
s_addr.s_addr = 2130706433;
server.sin_len = sizeof(server);
memcpy(&server.sin_addr, &s_addr, sizeof(struct in_addr));
server.sin_family = AF_INET; // Set the server's family
server.sin_port = htons((unsigned short) 48080); /* Set the port
to connect to... */
int threeerror = sodisconnect(so);
printf("threeerror: %d\n", threeerror);
int shuterror = soshutdown(so,2);
printf("shuterror: %d\n", shuterror);
//int mosterror = soclose(so);
//printf("mosterror: %d\n", mosterror);
int testerror = socreate(AF_INET, &so,SOCK_STREAM,0);
printf("testerror: %d\n", testerror);
int theerrors = soconnect(so, (struct sockaddr*)&server);
printf("theerrors: %d\n", theerrors);
}
}
On Jun 7, 2004, at 1:21 AM, Matt Jaffa wrote:
>
Hi,
>
>
I have successfully created a NKE and I am particularily interested in
>
the send function that I am using.
>
>
In the send function I detect if the outgoing message is a GET request
>
if so I do this:
>
>
if( is a GET request) {
>
>
struct sockaddr_in server; /* the information structure for the server
>
(to be filled out) */
>
bzero(&server, sizeof(struct sockaddr_in));
>
struct in_addr s_addr;
>
s_addr.s_addr = 2130706433;
>
server.sin_len = sizeof(server);
>
memcpy(&server.sin_addr, &s_addr, sizeof(struct in_addr));
>
server.sin_family = AF_INET; // Set the server's family
>
server.sin_port = htons((unsigned short) 48080); /* Set the port to
>
connect to... */
>
int threeerror = sodisconnect(so);
>
printf("threeerror: %d\n", threeerror);
>
int shuterror = soshutdown(so,2);
>
printf("shuterror: %d\n", shuterror);
>
//int mosterror = soclose(so);
>
//printf("mosterror: %d\n", mosterror);
>
int testerror = socreate(AF_INET, &so,SOCK_STREAM,0);
>
printf("testerror: %d\n", testerror);
>
int theerrors = soconnect(so, (struct sockaddr*)&server);
>
printf("theerrors: %d\n", theerrors);
>
>
>
}
>
>
>
And then I have a daemon that is listening on 127.0.0.1 with port
>
48080. In the daemon it successfully gets past the accept, but spins
>
on recv(....,...,....,....) forever. So I am assuming that in the
>
Kernel after I have redirected the socket to my daemon, and then when
>
the send function returns it sends that GET request instead to my
>
daemon, where I can look at the information.
>
>
But in my daemon the accept works, but it doesn't get past
>
recv(,,,,,,,,,);
>
>
What to do?
>
>
thanks,
>
Matt
>
_______________________________________________
>
darwin-kernel mailing list | email@hidden
>
Help/Unsubscribe/Archives:
>
http://www.lists.apple.com/mailman/listinfo/darwin-kernel
>
Do not post admin requests to the list. They will be ignored.
_______________________________________________
darwin-kernel mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/darwin-kernel
Do not post admin requests to the list. They will be ignored.