netgraph(3) NGM_KSOCKET_BIND
Crist J. Clark
cristjc at comcast.net
Tue Nov 18 23:07:30 PST 2003
OK, an easy one. I am trying to do some netgraph(3) coding in
userland. From how I read the documentation, this should work. Before
I go learn all of the netraph(4) kernel code to understand the error
message, could someone tell me how this is supposed to look? I'm sure
it's something obvious that I have missed.
The attached test program returns,
# ./ngtest
ngtest: failed to bind ksocket: Invalid argument
The program,
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <netinet/in_systm.h>
#include <netinet/ip.h>
#include <netgraph.h>
#include <netgraph/ng_ksocket.h>
#include <netgraph/ng_message.h>
#include <netgraph/ng_tee.h>
#include <err.h>
#include <errno.h>
#include <stdio.h>
#include <string.h>
#define DEFAULT_PORT 10000
#define OUR_HOOK_CTL "ctl_hook"
int main()
{
int cs, ds;
struct sockaddr_in laddr;
struct ngm_mkpeer ngmkp;
if (NgMkSockNode(NULL, &cs, &ds) == -1)
err(errno, "failed to create netgraph socket");
strcpy(ngmkp.type, NG_KSOCKET_NODE_TYPE);
strcpy(ngmkp.ourhook, OUR_HOOK_CTL);
strcpy(ngmkp.peerhook, "inet/dgram/udp");
if (NgSendMsg(cs, ".", NGM_GENERIC_COOKIE, NGM_MKPEER,
&ngmkp, sizeof ngmkp) == -1)
err(errno, "failed to create ksocket node");
bzero(&laddr, sizeof laddr);
laddr.sin_family = AF_INET;
laddr.sin_addr.s_addr = INADDR_ANY;
laddr.sin_port = htons(DEFAULT_PORT);
if (NgSendMsg(cs, OUR_HOOK_CTL, NGM_KSOCKET_COOKIE, NGM_KSOCKET_BIND,
&laddr, sizeof laddr) == -1)
err(errno, "failed to bind ksocket");
return 0;
}
--
Crist J. Clark | cjclark at alum.mit.edu
| cjclark at jhu.edu
http://people.freebsd.org/~cjc/ | cjc at freebsd.org
More information about the freebsd-net
mailing list