tools/testing/selftests/net/cmsg_sender.c

Source file repositories/reference/linux-study-clean/tools/testing/selftests/net/cmsg_sender.c

File Facts

System
Linux kernel
Corpus path
tools/testing/selftests/net/cmsg_sender.c
Extension
.c
Size
14289 bytes
Lines
584
Domain
Support Tooling And Documentation
Bucket
tools
Inferred role
Support Tooling And Documentation: implementation source
Status
source implementation candidate

Why This File Exists

Repository support layer: documentation, build tooling, samples, user-space helper tools, generated initramfs support, licenses, and validation utilities.

Dependency Surface

Detected Declarations

Annotated Snippet

struct option_cmsg_u32 {
	bool ena;
	unsigned int val;
};

struct options {
	bool silent_send;
	const char *host;
	const char *service;
	unsigned int size;
	unsigned int num_pkt;
	bool msg_more;
	struct {
		unsigned int mark;
		unsigned int dontfrag;
		unsigned int tclass;
		unsigned int hlimit;
		unsigned int priority;
	} sockopt;
	struct {
		unsigned int family;
		unsigned int type;
		unsigned int proto;
	} sock;
	struct option_cmsg_u32 mark;
	struct option_cmsg_u32 priority;
	struct {
		bool ena;
		unsigned int delay;
	} txtime;
	struct {
		bool ena;
	} ts;
	struct {
		struct option_cmsg_u32 dontfrag;
		struct option_cmsg_u32 tclass;
		struct option_cmsg_u32 hlimit;
		struct option_cmsg_u32 exthdr;
	} cmsg;
} opt = {
	.size = 13,
	.num_pkt = 1,
	.sock = {
		.family	= AF_UNSPEC,
		.type	= SOCK_DGRAM,
		.proto	= IPPROTO_UDP,
	},
};

static struct timespec time_start_real;
static struct timespec time_start_mono;

static void __attribute__((noreturn)) cs_usage(const char *bin)
{
	printf("Usage: %s [opts] <dst host> <dst port / service>\n", bin);
	printf("Options:\n"
	       "\t\t-s      Silent send() failures\n"
	       "\t\t-S      send() size\n"
	       "\t\t-4/-6   Force IPv4 / IPv6 only\n"
	       "\t\t-p prot Socket protocol\n"
	       "\t\t        (u = UDP (default); i = ICMP; r = RAW;\n"
	       "\t\t         U = UDP with MSG_MORE)\n"
	       "\n"
	       "\t\t-m val  Set SO_MARK with given value\n"
	       "\t\t-M val  Set SO_MARK via setsockopt\n"
	       "\t\t-P val  Set SO_PRIORITY via setsockopt\n"
	       "\t\t-Q val  Set SO_PRIORITY via cmsg\n"
	       "\t\t-d val  Set SO_TXTIME with given delay (usec)\n"
	       "\t\t-t      Enable time stamp reporting\n"
	       "\t\t-f val  Set don't fragment via cmsg\n"
	       "\t\t-F val  Set don't fragment via setsockopt\n"
	       "\t\t-c val  Set TOS/TCLASS via cmsg\n"
	       "\t\t-C val  Set TOS/TCLASS via setsockopt\n"
	       "\t\t-l val  Set TTL/HOPLIMIT via cmsg\n"
	       "\t\t-L val  Set TTL/HOPLIMIT via setsockopt\n"
	       "\t\t-H type Add an IPv6 header option\n"
	       "\t\t        (h = HOP; d = DST; r = RTDST)\n"
	       "\n");
	exit(ERN_HELP);
}

static void cs_parse_args(int argc, char *argv[])
{
	int o;

	while ((o = getopt(argc, argv, "46sS:p:P:m:M:n:d:tf:F:c:C:l:L:H:Q:")) != -1) {
		switch (o) {
		case 's':
			opt.silent_send = true;
			break;

Annotation

Implementation Notes