netgraph(3) NGM_KSOCKET_BIND

From: Crist J. Clark (cristjc_at_comcast.net)
Date: 11/19/03

  • Next message: lipton: "ppp dial-up"
    Date: Tue, 18 Nov 2003 23:07:45 -0800
    To: net@freebsd.org
    
    

    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@alum.mit.edu
                                       |     cjclark@jhu.edu
    http://people.freebsd.org/~cjc/    |     cjc@freebsd.org
    _______________________________________________
    freebsd-net@freebsd.org mailing list
    http://lists.freebsd.org/mailman/listinfo/freebsd-net
    To unsubscribe, send any mail to "freebsd-net-unsubscribe@freebsd.org"
    

  • Next message: lipton: "ppp dial-up"

    Relevant Pages

    • Re: netgraph(3) NGM_KSOCKET_BIND
      ... >> userland. ... From how I read the documentation, ... >> The attached test program returns, ... care I forgot to set sin_len. ...
      (freebsd-net)
    • WSARecvMsg
      ... struggling to understand the documentation, and in spite of errors in the ... copy of my test program in my web site; ... That program is my test program and is also not the ...
      (microsoft.public.win32.programmer.networks)
    • Re: Problems converting ASCII to float
      ... > coding in straight C. ... My quick test program that parses such a line works ... Operating System Engineer http://www.sgi.com/ ...
      (comp.sys.sgi.misc)
    • Re: Pointer to vector element
      ... > Does a pointer to an element of a vector remain valid after calling ... You cannot 'prove' this sort of proposition with a test program. ... There is no substitute for reading the documentation. ...
      (comp.lang.cpp)
    • Re: first time using direct access files: recl ??
      ... if all else fails, write a short test program, examine output. ... (sometimes the documentation is obscure) ...
      (comp.lang.fortran)