Skip to content

Commit

Permalink
sock options
Browse files Browse the repository at this point in the history
  • Loading branch information
tanvi-surana committed Apr 24, 2016
1 parent 7c3505a commit f398afa
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 54 deletions.
41 changes: 41 additions & 0 deletions sock-options/getsockopt.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#include <stdlib.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <stdio.h>

main()
{
int optlen, gs, socktype, s;

/* Create a datagram socket. */
s = socket(AF_INET, SOCK_DGRAM, 0);
if (s == -1) {
perror("Socket not created");
return EXIT_FAILURE;
}

/* Ask for the socket type. */
optlen = sizeof(socktype);
gs = getsockopt (s, SOL_SOCKET, SO_TYPE, &socktype, &optlen);
if (gs == -1) {
perror("getsockopt failed");
return EXIT_FAILURE;
}
/* Print socket type. */
switch (socktype)
{
case SOCK_STREAM:
puts("Stream socket.\n");
break;
case SOCK_DGRAM:
puts("Datagram socket.\n");
break;
case SOCK_RAW:
puts("Raw socket.\n");
break;
default:
puts("Unknown socket type.\n");
break;
}
return EXIT_SUCCESS;
}
54 changes: 0 additions & 54 deletions tcp-echo-improved/echo-client.c

This file was deleted.

File renamed without changes.

0 comments on commit f398afa

Please sign in to comment.