Following code is shown:
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <errno.h>
#include <string.h>
#include <sys/types.h>
#include <sys/socket.h>
int
main(int argc,char **argv) {
int z; /* Status return code */
int s[2]; /* Pair of sockets */
/*
* Create a pair of local sockets :
*/
z = socketpair(AF_UNIX,SOCK_STREAM,0,s);
if ( z == -1 ) {
fprintf(stderr,"%s: socketpair(AF_UNIX,SOCK_STREAM,0)\n", strerror(errno));
return 1; /* Failed */
}
/*
* Report the socket file descriptors returned:
*/
printf("s[0] = %d;\n",s[0]);
printf("s[1] = %d;\n",s[1]);
system("netstat | grep tcp"
;
return 0;
}
-----------------------------------------------
I then tried compiling it,
tex15 101 % make 01lst01
gcc -c -D_GNU_SOURCE -Wall 01LST01.c
01LST01.c:2: warning: #warning SOL forced
gcc 01LST01.o -o 01lst01
01LST01.o: In function `main':
01LST01.o(.text+0x1c): undefined reference to `socketpair'
collect2: ld returned 1 exit status
make: *** [01lst01] Error 1
why is that ?
I checked /usr/include dir and the header files are there.
Any help is FULLY Appreciated
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <errno.h>
#include <string.h>
#include <sys/types.h>
#include <sys/socket.h>
int
main(int argc,char **argv) {
int z; /* Status return code */
int s[2]; /* Pair of sockets */
/*
* Create a pair of local sockets :
*/
z = socketpair(AF_UNIX,SOCK_STREAM,0,s);
if ( z == -1 ) {
fprintf(stderr,"%s: socketpair(AF_UNIX,SOCK_STREAM,0)\n", strerror(errno));
return 1; /* Failed */
}
/*
* Report the socket file descriptors returned:
*/
printf("s[0] = %d;\n",s[0]);
printf("s[1] = %d;\n",s[1]);
system("netstat | grep tcp"
return 0;
}
-----------------------------------------------
I then tried compiling it,
tex15 101 % make 01lst01
gcc -c -D_GNU_SOURCE -Wall 01LST01.c
01LST01.c:2: warning: #warning SOL forced
gcc 01LST01.o -o 01lst01
01LST01.o: In function `main':
01LST01.o(.text+0x1c): undefined reference to `socketpair'
collect2: ld returned 1 exit status
make: *** [01lst01] Error 1
why is that ?
I checked /usr/include dir and the header files are there.
Any help is FULLY Appreciated