You Are Here:

Community: Wiki

This page was last modified on 14 July 2008, at 23:40.

Open C Sockets: getsockopt, setsockopt method

From Forum Nokia Wiki

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);
setsockopt(sock_fd,SOL_SOCKET,SO_KEEPALIVE,&optval,optlen);
getsockopt(sock_fd,SOL_SOCKET,SO_KEEPALIVE,(void*)&rdoptval,&optlen);
close(sock_fd);
}

Wiki Links

Open C Sockets Overview

Related Wiki Articles

No related wiki articles found

Rate This

 
Bookmark this page: DeliciousDiggFacebookGoogleYahooStumbleUponRedditDiigoTechnocratiTwitter  Share this page Share this page Print this Page Print this page Invite a friend Invite a friend
京ICP备05048969号    Email Newsletters Press Terms & Conditions Privacy Policy Sitemap Contact Us © 2009 Nokia