1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950 |
- #include <stdio.h>
- #include <stdlib.h>
- #include <errno.h>
- #include <sys/socket.h>
- #include <assert.h>
- int main(int argc,char **argv) {
- int z;
- int s = -1;
- int so_type = -1;
- socklen_t optlen;
- int rv;
-
-
- s = socket(PF_INET,SOCK_STREAM,0);
- if ( s == -1 ) {
- printf("socket(2) error %d", errno);
- exit(-1);
- }
-
- optlen = sizeof so_type;
- z = getsockopt(s,SOL_SOCKET,SO_TYPE,
- &so_type,&optlen);
- if ( z ) {
- printf("getsockopt(s,SOL_SOCKET,"
- "SO_TYPE) %d", errno);
- exit(-1);
- }
-
- assert(optlen == sizeof so_type);
- if (so_type == SOCK_STREAM) {
- printf("getsockopt: Got socket type OK\n");
- } else {
- printf("getsockopt: Got socket type failed\n");
- rv = -1;
- }
-
- return rv;
- }
-
|