Open C Sockets: getsockopt, setsockopt method

From Nokia Developer Wiki
Jump to: navigation, search
Article Metadata
Created: polaka_sr (17 Jun 2008)
Last edited: hamishwillee (27 Jul 2012)

The getsockopt, setsockopt methods gets and sets options on sockets.

int getsockopt (int s, int level, int optname, void * restrict optval, 
socklen_t * restrict optlen);
int setsockopt (int s, int level, int optname, const void *optval, socklen_t optlen);

The getsockopt and setsockopt system calls manipulate the options associated with a socket. Options may exist at multiple protocol levels; they are always present at the uppermost "socket" level.

Following is the usage of getsockopt and setsockopt system calls:

#include <sys/socket.h>
#include <netinet/in.h>
#include <unistd.h>
void SocketOptions()
int sock_fd;
int optval = 1;
unsigned int optlen = sizeof(optval);
int rdoptval;
sock_fd = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);

Wiki Links

Open C Sockets Overview

This page was last modified on 27 July 2012, at 04:18.
48 page views in the last 30 days.

Was this page helpful?

Your feedback about this content is important. Let us know what you think.


Thank you!

We appreciate your feedback.