fork download
  1. #include <stdio.h>
  2. #include <sys/socket.h>
  3. #include <netinet/in.h>
  4. #include <string.h>
  5.  
  6. int main(void) {
  7.  
  8. int fd = socket(AF_INET, SOCK_STREAM, 0);
  9. int len = 0;
  10. struct sockaddr_in _self;
  11. memset(&_self, 0, sizeof (struct sockaddr_in));
  12. if (getsockname(fd, (struct sockaddr *) &_self, &len) != 0)
  13. {
  14. perror("getsockname");
  15. }
  16. else
  17. {
  18. printf("%s\n", inet_ntoa(_self.sin_addr));
  19. }
  20. // your code goes here
  21. return 0;
  22. }
  23.  
Success #stdin #stdout 0s 2248KB
stdin
Standard input is empty
stdout
0.0.0.0