subh. singh subh. singh - 1 year ago 127
C Question

Where is function err_sys() defined?

I am getting an error related to

in this code:

#include <stdio.h>
#include <sys/socket.h>
#include <netinet/in.h>
int main()
int sockfd;

if ((sockfd=socket(AF_INET,SOCK_STREAM,0))<0)
err_sys("can't create socket");

return 0;

I am getting the linker error:

/tmp/cciuUVhz.o: In function `main':
getsockopt.c:(.text+0x38): undefined reference to `err_sys'
collect2: ld returned 1 exit status

Where is the function

Answer Source

Place this on top of your code:

void err_sys(const char* x) 

perror is defined in stdio.h

err_sys is used in the book "UNIX Network Programming: The sockets networking API" by Richard Stevens. It's not something common, as far as I know.

edit:fixed code error

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download