File: mod_echo.c

package info (click to toggle)
fragroute 1.2-7
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 692 kB
  • ctags: 520
  • sloc: ansic: 4,331; sh: 2,842; makefile: 74
file content (57 lines) | stat: -rw-r--r-- 784 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
/*
 * mod_echo.c
 *
 * Copyright (c) 2001 Dug Song <dugsong@monkey.org>
 *
 * $Id: mod_echo.c,v 1.4 2002/04/07 22:55:20 dugsong Exp $
 */

#include "config.h"

#include <sys/types.h>

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include "argv.h"
#include "mod.h"

void *
echo_open(int argc, char *argv[])
{
	char *p;
	
	if (argc < 2)
		return (NULL);

	if ((p = argv_copy(argv + 1)) == NULL)
		return (NULL);

	return (p);
}

int
echo_apply(void *d, struct pktq *pktq)
{
	char *p = (char *)d;

	printf("%s\n", p);
	return (0);
}

void *
echo_close(void *d)
{
	if (d != NULL)
		free(d);
	return (NULL);
}

struct mod mod_echo = {
	"echo",				/* name */
	"echo <string> ...",		/* usage */
	echo_open,			/* open */
	echo_apply,			/* apply */
	echo_close			/* close */
};