Exemple #1
0
/*-
-- cap = cap:set_filter(filter, nooptimize)

- filter is the filter string, see tcpdump or pcap-filter man page.
- nooptimize can be true if you don't want the filter optimized during compile
  (the default is to optimize).
*/
static int lpcap_set_filter(lua_State* L)
{
    pcap_t* cap = checkpcap(L);
    const char* filter = luaL_checkstring(L, 2);
    int optimize = !lua_toboolean(L, 3);
    bpf_u_int32 netmask = PCAP_NETMASK_UNKNOWN; /* TODO get device from registry, and call pcap_lookup_net()*/
    int ret = 0;
    struct bpf_program program = { 0 };

    ret = pcap_compile(cap, &program, filter, optimize, netmask);

    if(ret < 0) {
        return pusherr(L, cap);
    }

    ret = pcap_setfilter(cap, &program);

    pcap_freecode(&program);

    if(ret < 0) {
        return pusherr(L, cap);
    }

    lua_settop(L, 1);

    return 1;
}
Exemple #2
0
static int lpcap_next(lua_State* L)
{
    pcap_t* cap = checkpcap(L);
    struct pcap_pkthdr* pkt_header = NULL;
    const u_char* pkt_data = NULL;
    int e = pcap_next_ex(cap, &pkt_header, &pkt_data);

    /* Note: return values don't have names, they are documented numerically
       in the man page. */
    switch(e) {
        case 1: /* success */
            return pushpkt(L, pkt_header, pkt_data);
        case 0: /* read live, and timeout occurred */
            lua_pushnil(L);
            lua_pushstring(L, "timeout");
            return 2;
        case -2: /* read from a savefile, and no more packets */
            lua_pushnil(L);
            lua_pushstring(L, "closed");
            return 2;
        case -1: /* an error occurred */
            return pusherr(L, cap);
    }
    return luaL_error(L, "unreachable");
}
Exemple #3
0
/*
 * La procedure "fscanf_Position" lit en ascii un positionnement.
 * Entree :
 * pp		Positionnement a lire.
 */
void fscanf_Position (AritPosition *pp)
{
	pusherr ("rotate: ");
	fscanf_Vector (&pp->rotate);
	popuperr ("scale: ");
	fscanf_Vector (&pp->scale);
	popuperr ("translate: ");
	fscanf_Vector (&pp->translate);
	poperr ();
}
/*
 * La procedure "fscanf_Bound" lit en ascii une surface.
 * Entree :
 * bp		Surface a lire.
 */
void fscanf_Bound (Bound *bp)
{
	/* Lecture du type polygonale de la surface.	*/

	skip_keyword (T_TYPE, "bound: keyword \"type\" expected");
	if (lex () != T_INT)
	  lexerr ("start","bound_type: boolean expected (0=FALSE|~0=TRUE)", NULL);
	bp->is_polygonal = (myint ? 1 : 0);

	/* Lecture de la liste de points de la surface.	*/

	skip_keyword (T_POINT_LIST, "bound: keyword \"point_list\" expected");
	pusherr ("bound_point_list: ");
	fscanf_Point3f_list (&bp->point);
	poperr ();

	/* Lecture de la liste de faces de la surface.	*/

	skip_keyword (T_FACE_LIST, "bound: keyword \"face_list\" expected");
	pusherr ("bound_face_list: ");
	fscanf_Face_list (&bp->face);
	poperr ();
}
Exemple #5
0
static int lpcap_inject(lua_State* L)
{
    pcap_t* cap = checkpcap(L);
    size_t datasz = 0;
    const char* data = luaL_checklstring(L, 2, &datasz);

    int sent = pcap_inject(cap, data, datasz);

    if (sent < 0) {
        return pusherr(L, cap);
    }

    lua_pushinteger(L, sent);

    return 1;
}
Exemple #6
0
/*-
-- dumper = cap:dump_open(fname)

Open a dump file to write packets to.

An fname of "-" is a synonym for stdout.

Note that the dumper object is independent of the cap object, once
it's created (so the cap object can be closed if its not going to
be used).
*/
static int lpcap_dump_open(lua_State *L)
{
    pcap_t* cap = checkpcap(L);
    const char* fname = luaL_checkstring(L, 2);
    pcap_dumper_t** dumper = lua_newuserdata(L, sizeof(*dumper));

    *dumper = NULL;

    luaL_getmetatable(L, L_PCAP_DUMPER_REGID);
    lua_setmetatable(L, -2);

    *dumper = pcap_dump_open(cap, fname);

    if (!*dumper) {
        return pusherr(L, cap);
    }

    return 1;
}
Exemple #7
0
/*
 * La procedure "fscanf_View_parameters" lit en ascii les parametres
 * de visualisation.
 * Entree :
 * vp		Parametres de visualisation a lire.
 */
void fscanf_View_parameters (View_parameters *vp)
{
	/* Lecture du type de projection lors de la prise de vue.	*/

	skip_keyword (T_TYPE, "view: keyword \"type\" expected");
	switch (lex ()) {
	case T_PARALLEL :
		vp->type = PARALLEL;
		break;
	case T_PERSPECTIVE :
		vp->type = PERSPECTIVE;
		break;
	default :
	  lexerr ("start", "view_type: keyword \"parallel|perspective\" expected");
		break;
	}

	/* Lecture du centre de projection (oeil) de la prise de vue.	*/

	skip_keyword (T_COP, "view: keyword \"cop\" expected");
	pusherr ("view_cop: ");
	fscanf_Point3f (&vp->cop);
	poperr ();

	/* Lecture du point de reference (cible) a la prise de vue.	*/

	skip_keyword (T_VRP, "view: keyword \"vrp\" expected");
	pusherr ("view_vrp: ");
	fscanf_Point3f (&vp->vrp);
	poperr ();

	/* Lecture de la direction normale au plan de projection.	*/

	skip_keyword (T_VPN, "view: keyword \"vpn\" expected");
	pusherr ("view_vpn: ");
	fscanf_Vector (&vp->vpn);
	poperr ();

	/* Lecture de la direction indiquant le haut de la projection.	*/

	skip_keyword (T_VUP, "view: keyword \"vup\" expected");
	pusherr ("view_vup: ");
	fscanf_Vector (&vp->vup);
	poperr ();

	/* Lecture de la fenetre de projection de la prise de vue.	*/

	skip_keyword (T_WINDOW, "view: keyword \"window\" expected");
	pusherr ("view_window_umin: ");
	fscanf_float (&vp->vwd.umin);
	popuperr ("view_window_umax: ");
	fscanf_float (&vp->vwd.umax);
	popuperr ("view_window_vmin: ");
	fscanf_float (&vp->vwd.vmin);
	popuperr ("view_window_vmax: ");
	fscanf_float (&vp->vwd.vmax);
	poperr ();

	/* Lecture des profondeurs de decoupage avant et arriere.	*/

	skip_keyword (T_DEPTH, "view: keyword \"depth\" expected");
	pusherr ("view_depth_front: ");
	fscanf_float (&vp->depth.front);
	popuperr ("view_depth_back: ");
	fscanf_float (&vp->depth.back);
	poperr ();
}