--- iputils/ping.c Sun Dec 2 19:28:32 2001 +++ iputils-prio/ping.c Thu Apr 18 17:06:54 2002 @@ -79,6 +79,7 @@ struct sockaddr_in whereto; /* who to ping */ int optlen = 0; int settos = 0; /* Set TOS, Precendence or other QOS options */ +int priority = 0; /* skb->priority */ int icmp_sock; /* socket file descriptor */ u_char outpack[0x10000]; int maxpacket = sizeof(outpack); @@ -92,6 +93,7 @@ static u_short in_cksum(const u_short *addr, int len, u_short salt); static void pr_icmph(__u8 type, __u8 code, __u32 info, struct icmphdr *icp); static int parsetos(char *str); +static int parsepriority(const char *str); static struct { struct cmsghdr cm; @@ -124,7 +126,7 @@ source.sin_family = AF_INET; preload = 1; - while ((ch = getopt(argc, argv, COMMON_OPTSTR "bRT:")) != EOF) { + while ((ch = getopt(argc, argv, COMMON_OPTSTR "bRT:P:")) != EOF) { switch(ch) { case 'b': broadcast_pings = 1; @@ -138,6 +140,15 @@ exit(2); } break; + case 'P': + priority = parsepriority(optarg); + if (priority && + (setsockopt(icmp_sock, SOL_SOCKET, SO_PRIORITY, + (char *)&priority, sizeof(int)) < 0)) { + perror("ping: error setting priority"); + exit(2); + } + break; case 'R': if (options & F_TIMESTAMP) { fprintf(stderr, "Only one of -T or -R may be used\n"); @@ -1158,6 +1169,18 @@ return(tos); } +#include + +int parsepriority(const char *str) +{ + char *sep; + + if ((sep = strstr(str, ":")) == NULL) + return atoi(str); + *sep = '\0'; + return TC_H_MAKE(atoi(str) << 16, atoi(sep + 1)); +} + #include void install_filter(void) @@ -1196,6 +1219,6 @@ "Usage: ping [-LRUbdfnqrvVaA] [-c count] [-i interval] [-w deadline]\n" " [-p pattern] [-s packetsize] [-t ttl] [-I interface or address]\n" " [-M mtu discovery hint] [-S sndbuf]\n" -" [ -T timestamp option ] [ -Q tos ] [hop1 ...] destination\n"); +" [ -T timestamp option ] [ -Q tos ] [ -P classid ] [hop1 ...] destination\n"); exit(2); }