Created
January 29, 2015 03:30
-
-
Save wenjianhn/5700915c16e3f7d29c1b to your computer and use it in GitHub Desktop.
Test if setsockopt(SO_PRIORITY) sets the IP type-of-service (TOS) field or not.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <assert.h> | |
#include <netinet/ip.h> | |
#include <stdio.h> | |
#include <sys/socket.h> | |
#include <sys/types.h> | |
void test_setsockopt() | |
{ | |
int priority = 6; | |
int iptos = IPTOS_CLASS_CS6; | |
int fd = socket(AF_INET, SOCK_STREAM, 0); | |
if(setsockopt(fd, SOL_SOCKET, SO_PRIORITY, &priority, | |
sizeof(priority)) < 0){ | |
printf("Oh no\n"); | |
} | |
int tos = -1; | |
int optlen = sizeof(tos); | |
if (getsockopt(fd, IPPROTO_IP, IP_TOS, &tos, &optlen) < 0){ | |
printf("Oh no\n"); | |
} | |
if (tos == 0){ | |
printf("The man page lies or the kernel is buggy\n"); | |
printf("setsockopt(SO_PRIORITY) didn't set the IP type-of-service (TOS) field.\n"); | |
} else { | |
printf("the man page doesn't lie\n"); | |
} | |
close(fd); | |
} | |
int main(void) | |
{ | |
// background: https://ocrete.ca/2009/07/24/when-a-man-page-lies/ | |
test_setsockopt(); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment